我目前手动打开远程桌面并通过双击运行.bat文件。我在这个网站或其他地方找到了以下代码,可以让我自动执行此操作。当我尝试在远程计算机上打开记事本或计算时,此代码有效,但它不会运行我的.bat文件。我得到“因错误8而无法启动进程”。我检查过,错误8表示“未知故障”。 PSEXEC对我来说不是一个选择。任何帮助,将不胜感激。感谢。
Const ForWriting = 2
Const ForAppending = 8
Const NormalWindow = 5
Set fs = CreateObject("Scripting.FileSystemObject")
Dim CurrentDate
CurrentDate = Date
DateTime = CurrentDate & "," & CurrentTime
On Error Resume Next
'-----------------------------------------------------------
remote_machine_name = "RemoteComputerName"
Set objLocator = CreateObject("WbemScripting.SWbemLocator")
Set objService = objLocator.ConnectServer(remote_machine_name, "Root\DEFAULT")
If Err.Number <> 0 Then
WScript.Echo "Error " & Err.Number & ": " & Err.Description
Err.Clear
Else
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & remote_machine_name & "\root\cimv2:Win32_Process")
Set objConfig = objStartup.SpawnInstance_
objConfig.ShowWindow = NormalWindow
Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
'-------This line works fine
errReturn = objProcess.Create("notepad.exe", NULL, objConfig, intProcessID)
'-------This line doesn't work
'errReturn = objProcess.Create("XX.bat", "c:\users\Name\desktop\", objConfig, intProcessID)
'-------Neither does this line
'errReturn = objProcess.Create("XX.bat", "c:\users\Name\desktop\", NULL, intProcessID)
If errReturn = 0 Then
Wscript.Echo "Process started with a process ID of " & intProcessID & "."
Else
Wscript.Echo "Process could not be started due to error " & errReturn & "."
End If
End If
WScript.Echo "Completed"