0
votes

I've got a script which needs to run on various different versions of windows server, including 2003. Yeah, I already KNOW it's "unsupported".

My script has to launch an executable, in a hidden window (though the code to do this is not shown below, because I was asked to cut it down to the bare minimum). I'm currently using win32_Process.Create as follows:

Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
errReturn = objProcess.Create("C:\myprog.exe", null, null, intProcessID)

This works ok on 2008 and 2012, but it is to be failing on 2003 with error code 3 "Insufficient privilege" returned in errReturn. It also works when run through cmd.exe, as an ordinary user, but the parent program is a service, check_mk_agent.exe, and so is not an "ordinary user". This script is run as one of check_mk_agent.exe's plugins.

I'm now going to work out how to use runas to try to simulate running it as the same user as the service runs as.

1
"but seems to be failing on 2003" - Please edit the question and elaborate some more, what happens or doesn't happen, what errors you receive etc. - user692942
Is this the absolute minimum (readable) code you can write to do this on 2008/2012? If not, please write a minimal reproducible example to illustrate the exact issue, and make sure that there are no hidden issues. - Nic

1 Answers

0
votes

The two most common ways to launch a .exe from vbscript is WScript.Shell Run and Exec method. The main difference between the two is that you can capture the StdIn/StdOut/StdErr with the Exec method because applications are run in a child command shell.

Exec example:

Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("calc")

Run example:

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "%windir%\notepad " & WScript.ScriptFullName