Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ShellExecute( ) returns ERROR_FILE_NOT_FOUND

827 views
Skip to first unread message

pete

unread,
Feb 19, 2008, 9:15:17 AM2/19/08
to
Hi folks --

Using VS2005. I'm calling ShellExecute( ) from a DLL (but from a
function other than DllMain) and cannot persuade the function to find
the .exe I want to open. I call it like this:

retval = -1;
retval = (int) ShellExecute(NULL,"open",
"C:\\WINDOWS\\system32\\cmd.exe",
"","", SW_SHOWNORMAL );
if (retval <= 32)
printf("ShellExecute = %d, LastError = %d\n",
retval, GetLastError());

and no matter with what arguments I call ShellExecute( ), it always
returns 2. Here's the printf( ) output from the code above:

ShellExecute = 2, GetLastError = 2

I see from the debugger "Modules" window that shell32.dll is being
loaded. From FileSnoop I see this version info:

File name: C:\WINDOWS\system32\shell32.dll
Display name: shell32.dll
File type: Application Extension
File size: 8,384,000 Bytes (8,188 KB)
File size on disk: 8,384,512 Bytes (8,188 KB)
File attributes: A
Date created: 8/4/2004 7:00:00 AM
Date modified: 8/4/2004 7:00:00 AM
Last accessed: 2/19/2008 8:33:40 AM

and I also see that shell32.dll exports:

...
ShellExecuteA
ShellExecuteEx
ShellExecuteExA
ShellExecuteExW
ShellExecuteW
...

SO: why am I always getting file-not-found from Shell Execute( )?

Thanks!

-- Pete

David Lowndes

unread,
Feb 19, 2008, 10:43:21 AM2/19/08
to
>Using VS2005. I'm calling ShellExecute( ) from a DLL (but from a
>function other than DllMain) and cannot persuade the function to find
>the .exe I want to open. I call it like this:
>
> retval = -1;
> retval = (int) ShellExecute(NULL,"open",
> "C:\\WINDOWS\\system32\\cmd.exe",
> "","", SW_SHOWNORMAL );

Does the command prompt open? I presume it doesn't.

Try using my ShellExec test application on your computer to run
cmd.exe and see if that works - it does for me.

http://www.jddesign.f2s.com/freeware_programs.htm#ShellExec

Dave

pete

unread,
Feb 19, 2008, 11:47:51 AM2/19/08
to
On Feb 19, 10:43 am, David Lowndes <Dav...@example.invalid> wrote:
> >Using VS2005. I'm calling ShellExecute( ) from a DLL (but from a
> >function other than DllMain) and cannot persuade the function to find
> >the .exe I want to open. I call it like this:
>
> > retval = -1;
> > retval = (int) ShellExecute(NULL,"open",
> > "C:\\WINDOWS\\system32\\cmd.exe",
> > "","", SW_SHOWNORMAL );
>
> Does the command prompt open? I presume it doesn't.

That's correct. The command prompt does not open.

> Try using my ShellExec test application on your computer to run
> cmd.exe and see if that works - it does for me.
>
> http://www.jddesign.f2s.com/freeware_programs.htm#ShellExec
>
> Dave

It works byootiful! For cmd.exe and any other program I want to run.

What am I doing differently from ShellExec.exe?

Thanks, Dave

-- Pete

That's a very handy set of tools you have. I've bookmarked it.

David Lowndes

unread,
Feb 19, 2008, 7:58:18 PM2/19/08
to
>> > retval = (int) ShellExecute(NULL,"open",
>> > "C:\\WINDOWS\\system32\\cmd.exe",
>> > "","", SW_SHOWNORMAL );
>>
>> Try using my ShellExec test application on your computer to run
>> cmd.exe and see if that works - it does for me.
>>
>> http://www.jddesign.f2s.com/freeware_programs.htm#ShellExec
>>
>
>It works byootiful! For cmd.exe and any other program I want to run.
>
>What am I doing differently from ShellExec.exe?

I can't spot anything obvious, try passing NULL rather than "".

Dave

0 new messages