Thread: mixed success with ShellExecuteEx

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    36

    mixed success with ShellExecuteEx

    I am using ShellExecuteEx to run an external program which works fine on my end. Various people who have tried it are getting very strange errors though. I read a topic on MSDN forums that discussed ShellExecuteEx depending on settings a user may have, but I didn't grasp much from it. What variables are there that may be causing the problem? The problem is that Windows pops up an error saying the target program can't be found, as if the program was not in the directory. It passes a check initially with GetFileAttributes for existance in the first place though, so it's very confusing to me.......

    Code:
    	SHELLEXECUTEINFO ShExecInfo = {0};
    
    	ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
    	ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
    	ShExecInfo.hwnd = NULL;
    	ShExecInfo.lpVerb = "open";
    	ShExecInfo.lpFile = "prg.exe";  //exe path
    	ShExecInfo.lpParameters = cmdline;  //crafted command line
    	ShExecInfo.lpDirectory = NULL;
    	ShExecInfo.nShow = SW_HIDE;
    	ShExecInfo.hInstApp = NULL;
    	ShellExecuteEx(&ShExecInfo);
    	
    	//wait until it completes
    	WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
    So I call it, wait til it finishes and then proceed. It works fine for me, but other people don't have success with it reporting an error that Windows can't find prg.exe, despite being in the same directory...

  2. #2
    Registered User Ktulu's Avatar
    Join Date
    Oct 2006
    Posts
    107
    I would recommend not to use the ShellExecuteEx funciton but instead you should try CreateProcess, before you call CreateProcess make sure the application you which to execute exists.
    This parameter is reserved

  3. #3
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Is the app run at start or from a shortcut (or clicking on the .exe file)?

    If run from the start up it will not be 'considered' by windows to be running from the same folder as the .exe file. In this case you will need a full path (not just the path from the .exe as you are using).
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  4. #4
    Registered User
    Join Date
    Jun 2006
    Posts
    36
    Supplying the full path did the trick!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 10:13 AM
  2. need help
    By the bosss in forum C++ Programming
    Replies: 1
    Last Post: 11-12-2007, 10:56 PM
  3. What's wrong with my success statement??
    By cool_dude07 in forum C Programming
    Replies: 7
    Last Post: 07-21-2007, 11:22 PM
  4. linked list stack question
    By Drew in forum C++ Programming
    Replies: 2
    Last Post: 09-11-2003, 05:05 AM
  5. Why do I get these errors in the If statements?
    By Drew in forum C++ Programming
    Replies: 4
    Last Post: 09-10-2003, 08:52 PM