NO

Author Topic: CreateProcess not found ?  (Read 1805 times)

Offline bitcoin

  • Member
  • *
  • Posts: 179
CreateProcess not found ?
« on: November 11, 2022, 08:32:52 PM »
Hello
I have simple code

Code: [Select]
int entry(void)
{
WinExec("cmd.exe /k systeminfo.exe",SW_SHOW);
ExitProcess(0);
}

It works, when I start it from explorer.exe / total commander / cmd.exe / etc.

But when I start it from PellesC IDE (button "Execute" under the menu) I have error "command systeminfo not found" - because cmd.exe don't found this program. Also , same errors are with ping.exe , tracert and other. Why?

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2091
Re: CreateProcess not found ?
« Reply #1 on: November 12, 2022, 09:18:00 AM »
Check Tools -> Options -> Projects -> Folders Executables
If C:\windows\system32 isn't there, add it.
« Last Edit: November 12, 2022, 11:36:42 AM by TimoVJL »
May the source be with you

Offline John Z

  • Member
  • *
  • Posts: 796
Re: CreateProcess not found ?
« Reply #2 on: November 12, 2022, 12:58:36 PM »
But when I start it from PellesC IDE (button "Execute" under the menu) I have error "command systeminfo not found" - because cmd.exe don't found this program. Also , same errors are with ping.exe , tracert and other. Why?

When the cmd window opens and displays the error method, type path <return> you will see the problem.

You could use this format as well as TimoVJL more versatile (better) solution:
 WinExec("cmd.exe /k c:\\windows\\syswow64\\systeminfo.exe",SW_SHOW);
or
 WinExec("cmd.exe /k c:\\windows\\system32\\systeminfo.exe",SW_SHOW);


John Z

BTW - if you run the resulting exe outside of Pelles UI you will see that your original code does work, and if you again type path <return> you will see why....
« Last Edit: November 12, 2022, 01:32:49 PM by John Z »

Offline bitcoin

  • Member
  • *
  • Posts: 179
Re: CreateProcess not found ?
« Reply #3 on: December 10, 2022, 03:12:37 PM »
TimoVJL, John Z
both method works, thanks!

Offline Vortex

  • Member
  • *
  • Posts: 802
    • http://www.vortex.masmcode.com
Re: CreateProcess not found ?
« Reply #4 on: February 05, 2023, 01:04:16 PM »
Hello bitcoin,

This one works too :

Code: [Select]
#include <stdio.h>
#include <windows.h>

int main(void)
{
ShellExecute(0,"open","cmd.exe","/k systeminfo.exe",0,SW_SHOW);
return 0;
}
Code it... That's all...

Offline bitcoin

  • Member
  • *
  • Posts: 179
Re: CreateProcess not found ?
« Reply #5 on: February 14, 2023, 12:32:07 AM »
hello Vortex
And why is that? Is it the key '/k' to or the function ShellExecute?

Offline John Z

  • Member
  • *
  • Posts: 796
Re: CreateProcess not found ?
« Reply #6 on: February 14, 2023, 02:35:53 PM »
And why is that? Is it the key '/k' to or the function ShellExecute?

Hi Bitcoin,

It is not due to the '/k' that just keeps the command window from closing, which then allows you to view the results.

It is the ShellExecute because it uses the registry.  Here is an excerpt from Microsoft at:
https://learn.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutea

Code: [Select]
Because ShellExecute can delegate execution to Shell extensions (data sources, context menu handlers, verb implementations)
 that are activated using Component Object Model (COM), COM should be initialized before ShellExecute is called. Some Shell
extensions require the COM single-threaded apartment (STA) type. In that case, COM should be initialized as shown here:

CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE)

There are certainly instances where ShellExecute does not use one of these types of Shell extension and those
instances would not require COM to be initialized at all. Nonetheless, it is good practice to always initialize COM
before using this function.

This method allows you to execute any commands in a folder's shortcut menu or stored in the registry.

In this case the needed 'path' which was missing previously is obtained elsewhere. Also note that in many use cases
for ShellExecute you will need coInitializeEx.....

John Z

Offline Vortex

  • Member
  • *
  • Posts: 802
    • http://www.vortex.masmcode.com
Re: CreateProcess not found ?
« Reply #7 on: February 14, 2023, 08:42:50 PM »
Hi bitcoin,

John's explanation is correct. ShellExecute can be useful for practical programming.
Code it... That's all...