Hi
I should start a XY.bat on a remote machine.
I'm new on WMI so this question might be silly.
I found some help on this site (shown below):
Dim cOptions As New ConnectionOptions()
Dim workingDir As String = "C:\Temp"
Dim mCommand As String = "notepad"
Dim servername As String = "remoteserver"
Dim scope As New ManagementScope("\\" & servername & "\root\cimv2", coptions)
Try
scope.Connect()
Dim mp As New ManagementPath("Win32_Process")
Dim mo As New ManagementClass(scope, mp, New ObjectGetOptions(Nothing, New TimeSpan(0, 0, 0, 5), True))
Dim inParams As ManagementBaseObject = mo.GetMethodParameters("Create")
Dim options As New InvokeMethodOptions()
inParams("CommandLine") = mcommand
inParams("CurrentDirectory") = workingdir
Dim mbo As ManagementBaseObject = mo.InvokeMethod("Create", inParams, options)
Dim rv As Object = mbo("returnvalue")
Dim prid As Object = mbo("processid")
Catch e As Exception
Console.WriteLine("Failed to connect: " + e.Message)
End Try
This exemple starts the notepad and it works.
Then I changed some line:
Dim workingDir As String = "C:\Folder where XY.bat is"
Dim mCommand As String = "XY.bat <Parameter>"
Why does this not work?
Thanks
Lelo66
I should start a XY.bat on a remote machine.
I'm new on WMI so this question might be silly.
I found some help on this site (shown below):
Dim cOptions As New ConnectionOptions()
Dim workingDir As String = "C:\Temp"
Dim mCommand As String = "notepad"
Dim servername As String = "remoteserver"
Dim scope As New ManagementScope("\\" & servername & "\root\cimv2", coptions)
Try
scope.Connect()
Dim mp As New ManagementPath("Win32_Process")
Dim mo As New ManagementClass(scope, mp, New ObjectGetOptions(Nothing, New TimeSpan(0, 0, 0, 5), True))
Dim inParams As ManagementBaseObject = mo.GetMethodParameters("Create")
Dim options As New InvokeMethodOptions()
inParams("CommandLine") = mcommand
inParams("CurrentDirectory") = workingdir
Dim mbo As ManagementBaseObject = mo.InvokeMethod("Create", inParams, options)
Dim rv As Object = mbo("returnvalue")
Dim prid As Object = mbo("processid")
Catch e As Exception
Console.WriteLine("Failed to connect: " + e.Message)
End Try
This exemple starts the notepad and it works.
Then I changed some line:
Dim workingDir As String = "C:\Folder where XY.bat is"
Dim mCommand As String = "XY.bat <Parameter>"
Why does this not work?
Thanks
Lelo66