I get this error: Image
When i try to run this code:
strComputer = "server01"
strCommand = "powershell.exe -NoLogo -Command Start-Service -InputObject $(Get-Service -Computer " & strComputer & " -Name " & strService & ")"
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objExec = WshShell.Run(strCommand,0,True)
I want to run strCommand in an hidden window. This works the code ran through and do what it should do but this error occure and this is really bad.
.Run() - as opposed to .Exec() - returns an error code (not an object). So you must not use
Set objExec = WshShell.Run(strCommand,0,True)
but
nErrorCode = WshShell.Run(strCommand,0,True)
您需要在命令之前和命令末尾添加双引号:
strCommand = "powershell.exe -NoExit -NoLogo -Command ""Start-Service -PassThru -InputObject (Get-Service -Computer " & strComputer & " -Name " & strService & ")"""
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.