如何在远程机器上执行 vbs 文件 [英] How to execute vbs file on a remote machine
本文介绍了如何在远程机器上执行 vbs 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不使用 PsExec 的情况下执行位于同一域中的远程机器上的 VBScript?
How to execute a VBScript located on a remote machine where machines are on same domain without using PsExec?
我尝试了以下代码,但没有成功.
I tried the following code, but no luck.
Sub RunCommand(strComputer, Command)
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2:Win32_Process")
Err = objWMIService.Create("cmd /c " & Command, Null, Null, intProcessID)
If Err > 0 Then
MsgBox "Error occured on Remote Server", vbCritical, "Error"
End If
End Sub
Sub Test()
Runcommand("HE2264","C:\Temp\Test.vbs")
End Sub
推荐答案
您需要使用 cscript.exe
或 wscript.exe
运行 VBScript,而不是使用 CMD.
You need to run VBScripts with either cscript.exe
or wscript.exe
, not with CMD.
Err = objWMIService.Create("wscript.exe " & Command, Null, Null, intProcessID)
另外,您需要去掉括号 来自 Test
中的 RunCommand
调用:
Also, you need to remove the parentheses from the RunCommand
call in Test
:
Runcommand "HE2264", "C:\Temp\Test.vbs"
这篇关于如何在远程机器上执行 vbs 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文