0

現在、手動でリモート デスクトップを開き、.bat ファイルをダブルクリックして実行しています。このサイトまたは他の場所で、これを自動化できる次のコードを見つけました。このコードは、リモート コンピューターでメモ帳または calc を開こうとすると機能しますが、.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"
4

0 に答える 0