Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss
Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Please help with CreateProcess and Executing VBS Script

1,204 views
Skip to first unread message

James

unread,
Feb 7, 2009, 2:35:37 PM2/7/09
to
Hi there,
 
I'm having problems executing a VBS Script through CreateProcess.  Below is the sample code that I am using.  Please note that the application is built with UNICODE enabled.  The main problem is that, the script is never executed and "WaitForSingleObject" nevers completes execution.  I'm not getting any error messages, but rather my application just hangs.  Can someone please help me with correcting this - as all I want is to execute the vbs script.  Many thanks for your help
 
STARTUPINFO si;
ZeroMemory(&si, sizeof(si));
si.cb = sizeof STARTUPINFO;
PROCESS_INFORMATION pi;
si.dwFlags = STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
 
 
 
CreateProcess(_T("C:\\Windows\\system32\\cmd.exe"), _T("c:/myfile.vbs"), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
WaitForSingleObject(pi.hProcess, INFINITE);
DWORD exit_code;
GetExitCodeProcess(pi.hProcess, &exit_code);
    CloseHandle( pi.hProcess );
    CloseHandle( pi.hThread );
 
 
Thanks,
James

Scott Seligman

unread,
Feb 7, 2009, 2:42:47 PM2/7/09
to
"James" <synta...@yahoo.co.uk> wrote:
>CreateProcess(_T("C:\\Windows\\system32\\cmd.exe"),
>_T("c:/myfile.vbs"), NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);

You should use either cscript.exe or wscript.exe to run a script file.
Also, instead of the string you're passing, you'll need to pass a real
path (i.e., "c:\\myfile.vbs")

--
--------- Scott Seligman <scott at <firstname> and michelle dot net> ---------
Music hath charms to soothe the savage breast, to soften rocks, or
bend a knotted oak.
-- The Mourning Bride by William Congreve

James

unread,
Feb 7, 2009, 5:27:00 PM2/7/09
to
Hi Scott,

I've tried what you suggested and it still doesn't work. I changed it to
the below line:
CreateProcess(_T("cscript //NOLOGO c:/myfile.vbs"), NULL, NULL, NULL, FALSE,

0, NULL, NULL, &si, &pi);


"Scott Seligman" <seli...@example.com> wrote in message
news:gmko7n$5o9$1...@panix3.panix.com...

James

unread,
Feb 7, 2009, 6:06:14 PM2/7/09
to
I solved it:-)
Basically, internally CreateProcess modifies the second parameter passed to it.  The solution was to simply store the second parameter into a Variable and then pass the variable to
CreateProcess like so:
TCHAR appCmdLine[] = TEXT("cscript.exe //NOLOGO c:/myfile.vbs");
CreateProcess(NULL, appCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi);
 
Thanks,
Jim

diegos...@gmail.com

unread,
Feb 21, 2017, 5:35:53 PM2/21/17
to
Thanks James, I was facing the same issue. Your post helped me a lot.
Cheers :)
0 new messages