我有一个Windows服务,该服务调用bat文件。该bat文件将调用PowerShell脚本,在该PowerShell脚本中将调用VBScript。
Windows Service > bat file > powershell file > vbscript
当我手动运行bat文件时,成功执行了VBscript,但是如果我从Windows服务中执行了相同的bat文件,则将调用所有脚本,但是VBScript会跳过运行。
手动执行bat文件可以成功执行VBScript,但不能通过Windows服务
我试图以不同的方式在PowerShell中调用VBScript:
-
& c:\windows\system32\cscript.exe NameOfFile.vbs
-
start-process
-
invoke-expression
-
C:\Windows\System32\cscript.exe NameOfFiles.vbs //B //Nologo $IP_SU $RemoteSessions_Output $user
我的VBScript是:
dim ip
dim sessions_dir
dim temp
dim username
dim password
set temp = Wscript.Arguments
ip = temp(0)
sessions_dir = temp(1)
username = temp(2)
password = temp(3)
Sub WaitEnter()
WshShell.Appactivate("telnet " & ip )
WScript.Sleep 2000
WshShell.Appactivate("telnet " & ip)
WshShell.SendKeys "{Enter}"
WshShell.Appactivate("telnet " & ip)
WScript.Sleep 2000
End Sub
set WshShell = WScript.CreateObject("WScript.Shell")
Wscript.Sleep 1000
WshShell.Appactivate("telnet " & ip )
WshShell.Run "telnet " & ip & " -f " & sessions_dir & "\" & ip & "_SU_Status_Output.txt",2
WshShell.Appactivate("telnet " & ip)
WScript.Sleep 1000
WshShell.Appactivate("telnet " & ip)
WshShell.SendKeys username
WaitEnter
WshShell.Appactivate("telnet " & ip)
WshShell.SendKeys password
WaitEnter
WshShell.Appactivate("telnet " & ip)
WshShell.SendKeys "SU_INrOmk=` pl | awk '{{}print {$}3{}}' | head -3 | cut -d '=' -f2`; SU_type=` pl | grep $SU_INrOmk | tail -1 | awk '{{}print {$}12{}}'`"
WaitEnter
WshShell.Appactivate("telnet " & ip)
WshShell.SendKeys "echo $SU_type"
WaitEnter
WshShell.Appactivate("telnet " & ip)
WshShell.SendKeys "exit"
WshShell.Appactivate("telnet " & ip)
WshShell.SendKeys "{Enter}"
和调用它的PowerShell脚本如下:
if(Test-Path C:\Windows\System32\cscript.exe){
echo "Cscript found"
$command = "& C:\Windows\System32\cscript.exe NameOfFile.vbs $IP_SU $RemoteSessions_Output $user $DecPwd | out-null"
Invoke-Expression -Command $Command
start-Sleep 10
if($?){
start-sleep 10
$SU_Output_File = $IP_SU + "_SU_Status_Output.txt"
$SU_Remote_FilePath = $RemoteSessions_Output + "\" + $SU_Output_File
}
}
我希望Windows服务调用bat文件时会调用VBScript。