Using NT 4.0 SP5
From a Windows Service program I want to launch a batch file in a separate
process. I used CreateProcess in the following manner
CreateProcess(lpszCommand,
lpszCommandLine,
NULL,
NULL, FALSE,
CREATE_NO_WINDOW|CREATE_NEW_PROCESS_GROUP,
NULL,/* Environment of calling process */
NULL,
&si,
&pi);
This succeeds as long as lpszCommandLine is an empty string. But when
non-empty it fails with GetLastError returning 2. This does not happen when
lpszCommand is an .exe file.
From the newsgroups I found a workaround to route the batch file thro
CMD.EXE
i.e. Making the batch file and its command-line arguments(CLA) as
the CLA to CMD.exe. This worked but this has the overhead of an additional
CMD.EXE process which is undesirable this being a long-running program.
Does anybody have any ideas, apart from the above workaround, to launch a
batch-file having CLA using CreateProcess ?
Thanks,
V
------------------------------------------------------------
Get your FREE web-based e-mail and newsgroup access at:
http://MailAndNews.com
Create a new mailbox, or access your existing IMAP4 or
POP3 mailbox from anywhere with just a web browser.
------------------------------------------------------------
Luc
"Vishwanath Nukal" <lak...@MailAndNews.com> wrote in message
news:3AD7...@MailAndNews.com...
Is this also happening if you specify NULL instead of lpszCommand and
in lpszCommandLine give filename and CLA (for instance: "myfile.bat
arg1 arg2")?
Is it shell functionality to recognise BAT and CMD files and to run
interpreter? Or this is more low level feature implemented by
OS(loader?) itself?
I *thought* I knew the answer... until I looked up the "cmdfile" and
"batfile" entries under HKEY_CLASSES_ROOT!
The Shell\open\command entries specify "%1" "%*", which is also present for
"comfile", "exefile", "piffile"
I expected to find %SYSTEMROOT%\CMD.EXE %* there...
I guess .bat .cmd .com .exe and .pif *are* handled in a "special" way.
Anyway, the result will always be that launching a .bat or cmd needs a
CMD.EXE or COMMAND.COM to handle it...
Or did I still miss something?
Luc
Anyway, I continued the trial-and-error work and found that the following method
works.
CreateProcess(NULL,
"batchfile.bat cla1 cla2 cla3",
NULL,
NULL, FALSE,
CREATE_NO_WINDOW|CREATE_NEW_PROCESS_GROUP,
NULL,/* Environment of calling process */
NULL,
&si,
&pi);
Making the command as NULL and putting the batch-file alongwith its CLA into the
CommandLine does the trick. This does not even require the extra do-nothing
CMD.EXE process to be hovering around.
Thanks to all who responded
V
Luc Kumps wrote:
--
Vishwana...@oracle.com
Ph: (650) 633 6349
"Vishwanath Nukal" <Vishwana...@Oracle.com> wrote in message
news:3AD353EA...@MailAndNews.com...
Luc
"Vishwanath Nukal" <Vishwana...@Oracle.com> wrote in message
news:3AD353EA...@MailAndNews.com...
>