我需要製作一個簡單的vbs腳本來自動運行某個進程。我在微軟的網站上找到了以下腳本。它運行正常,以原始示例顯示的方式運行notepad.exe,但我試圖修改它以運行myprog.exe。這個程序的完整路徑是:C:\myprogdir\myprog.exe
在VBS中啓動進程:path not found
Const SW_NORMAL = 1
strComputer = "."
strCommand = "myprog.exe"
strPath = "C:\myprogdir\"
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, strPath, 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
我不斷收到返回值:9,這表明「找不到路徑」。但路徑是正確的。有沒有我沒有得到的東西?
一見鍾情,我認爲配置不對。 –
@DavidCandy:更簡單的一行:'CreateObject(「WScript.Shell」)。運行「C:\ myprogdir \ myprog.exe」 – Helen