【问题标题】:How to execute vbs file on a remote machine如何在远程机器上执行 vbs 文件
【发布时间】:2016-06-26 16:58:40
【问题描述】:

如何在不使用 PsExec 的情况下执行位于机器位于同一域中的远程机器上的 VBScript?

我尝试了以下代码,但没有成功。

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

【问题讨论】:

    标签: vbscript remote-execution


    【解决方案1】:

    您需要使用 cscript.exewscript.exe 运行 VBScript,而不是使用 CMD。

    Err = objWMIService.Create("wscript.exe " & Command, Null, Null, intProcessID)
    

    另外,您需要从RunCommand 调用remove the parentheses Test

    Runcommand "HE2264", "C:\Temp\Test.vbs"
    

    【讨论】:

    • 同样,如果我想执行一个 bat 文件,我可以像上面提到的那样使用 wscript.exe 吗?
    • 或者留下括号和前缀Call (链接文章中的第3.2点)
    • @santosh 当然不是。批处理文件需要与 VBScript 文件(cscript.exewscript.exe)不同的解释器(cmd.exe)。
    猜你喜欢
    • 1970-01-01
    • 2014-09-30
    • 1970-01-01
    • 2023-03-21
    • 2011-01-21
    • 2014-11-05
    • 1970-01-01
    • 2020-06-12
    • 1970-01-01
    相关资源
    最近更新 更多