The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: brixton on December 23, 2005, 04:26:49 PM

Title: WinExec problem
Post by: brixton on December 23, 2005, 04:26:49 PM
OK, I am writing a program which has to create a batch file (just using a filename, no path, so the file is written in the current directory), but when I _lclose it after writing, and then invoke WinExec, ADDR filename, I always get ''filename.bat' is not recognized as an internal or external command, operable program or batch file.'.  This is a load of crap as the .bat IS created successfully and IS in the directory of the calling process..  So I can't see why it doesn't find it successfully.

Any help?  Is this a common problem?  I tried moving all the files to the root directory and it didn't affect it.

Thanks in advance!
Title: Re: WinExec problem
Post by: P1 on December 23, 2005, 06:49:16 PM
Read your documentation !!!

Include your full path.

And after you read the documentation on WinExec ( Hint: It uses CreateProcess ), then you will know that it should have been passed with a "cmd.exe" for NT and "command.com" for the Dos OSes.

For better programming:
Remarks

Win32-based applications should use the CreateProcess function rather than this function. The WinExec function exists in Win32 to provide compatibility with earlier versions of Windows. For more information about how the WinExec function is implemented, see the Remarks section of the LoadModule function.


Regards,  P1  :8)
Title: Re: WinExec problem
Post by: PBrennick on December 23, 2005, 06:52:33 PM
The batch file needs to be the tail portion of CreateProcess and cmd.exe or command.com is the executable.  The default directory for READ and for WRITE are not guaranteed to be the same so use the FULL path.

Paul
Title: Re: WinExec problem
Post by: PBrennick on December 23, 2005, 06:53:36 PM
OOPS, sorry Michael, seems you posted while I was typing.  Your words state it perfectly.

Paul
Title: Re: WinExec problem
Post by: brixton on December 24, 2005, 12:15:25 AM
Thankyou for the replies both  :U
Title: Re: WinExec problem
Post by: brixton on December 25, 2005, 02:02:09 AM
Now, when debugging, I get ERROR_NOACCESS  :red
Title: Re: WinExec problem
Post by: tenkey on December 25, 2005, 10:39:43 PM
Add the /c option to command.exe or cmd.exe to get a program to run. Use command.exe only on Win9x systems (includes ME). On all others use cmd.exe.

command.exe /c app.exe arglist
cmd.exe /c app.exe arglist

The /c will also handle batch files and the commands that aren't handled by executables (like DIR, DEL, REN, etc.)
Title: Re: WinExec problem
Post by: zooba on December 26, 2005, 11:10:17 AM
'COMMAND.COM' does exist on post-9x systems, but it is much slower. Depending on what your batch file needs to do, you may be able to get away with using command.com exclusively.
Title: Re: WinExec problem
Post by: P1 on December 28, 2005, 06:09:28 AM
Quote from: brixton on December 25, 2005, 02:02:09 AM
Now, when debugging, I get ERROR_NOACCESS  :red
Post some code, I know you are using something wrong!

Regards,  P1  :8)
Title: Re: WinExec problem
Post by: brixton on January 08, 2006, 11:53:58 AM
Hey P1,

Yeah, to be honest I couldn't find the mistakes..
So I copy/pasted the algos I needed and just re-wrote everything else.  I didn't even use cmd.exe or command.com or anything, just WinExec'd the batchfile and it works now.  I think maybe I had errors previously messing everything up.. But I still don't know where they are lol  :bg