Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run remote batch?

Status
Not open for further replies.

lelo66

Programmer
Sep 14, 2004
10
0
0
CH
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've found the solution:

Dim mCommand As String = "cmd /C""C:XY.cmd <Parameter>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top