Running an external exe from win32 application

13,671

Solution 1

ShellExecute wants the program name and its parameters to be given separately. Try this:

ShellExecute(hWnd, NULL, "D:\\scan\\scan.exe", "-l", NULL, SW_HIDE);

Solution 2

You should really use CreateProcess which does not use the shell to call a program. This also allows you to capture the program output and retrieve any error codes it might give.

If you need to hide the window of a GUI app, you can set CREATE_NO_WINDOW in the dwFlags in the CreateProcess call (cfr. this answer)

Share:
13,671
WiXXeY
Author by

WiXXeY

I am experienced in .Net Technologies, C/C++, C#, WFP, WCF, MVC, MVVM, ASP.net. I have also worked in Java Web Technologies(JSP, JSF) and Python. And also having a hands on experience in designing in developing Database applications.

Updated on June 04, 2022

Comments

  • WiXXeY
    WiXXeY almost 2 years

    I am working on a WIN32 application in Visual Studio 2010. I have to execute an external exe from my code but don't have to show its window. along with executing the exe I am passing certain argument to exe. my code is given

    char path[] = "D:\\scan\\scan.exe -l";
    system(path);
    //ShellExecute(hWnd, "open",path, NULL, NULL, SWP_HIDEWINDOW); 
    

    if I use system(path) it is executed properly but the window of the exe is also shown, but if I use ShellExecute(hWnd, "open",path, NULL, NULL, SWP_HIDEWINDOW); then the exe of the given path is not executed. how should I overcome this problem, kindly guide me