Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create Process always returns "Path Not Found"

Status
Not open for further replies.

JOB2828

Programmer
Jan 21, 2005
17
US
I have a script that uses WMI to launch an executable. However, the only thing that I can get it to launch is items within the %systemroot%. I have tried to set the working directory to something else, but it produces the same result. How can I get it to launch an application outside of the %systemroot%?

Code:
Set oProcess = GetObject("winmgmts:Win32_Process")
Set oInParams = oProcess.Methods_("Create").InParameters.SpawnInstance_
oInParams.CommandLine = "gt.exe"
oInParams.CurrentDirectory = "c:\temp"
set RetObj = oProcess.ExecMethod_("Create", oInParams,null)
 
And what about something like this ?
oInParams.CommandLine = "c:\temp\gt.exe"

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Well, thanks for the reply. I feel like a bit of a knob, but I've been staring at code to long today. My problem was a typo...

Thanks again..
 
What I thought was me typoing was not. I had forgotten that I moved the exe into the %systemroot%. I better take a break from this one for a bit.... [ponder] The problem remains as described in the start of this thread.
 
***UPDATE***

It's aggrevating me now. I tested with the following code right out of the MSDN Library and it does the same thing.

Code:
Const SW_NORMAL = 1
strComputer = "."
strCommand = "gt.exe" 
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

' Configure the Notepad process to show a window
Set objStartup = objWMIService.Get("Win32_ProcessStartup")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = SW_NORMAL

' Create Notepad process
Set objProcess = objWMIService.Get("Win32_Process")
intReturn = objProcess.Create(strCommand, "E:\temp", objConfig, intProcessID)
If intReturn <> 0 Then
    Wscript.Echo "Process could not be created." & vbNewLine & "Command line: " & strCommand & vbNewLine & "Return value: " & intReturn
Else
    Wscript.Echo "Process created." & vbNewLine & "Command line: " & strCommand & vbNewLine & "Process ID: " & intProcessID
End If
 
>oInParams.CommandLine = "gt.exe"
You have to specify the path to it.
[tt]oInParams.CommandLine = "[blue]c:\yourpath\[/blue]gt.exe"[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top