Start Process on Remote Machine in VB.Net

In this article we will use WMI Provider for Start a "Process on Remote Machine". You can use CreateProcess procedure, this procedure has verious parameters:
  • Computer Name
  • Process Name
  • UserName
  • Password
Private Sub CreateProcess(ByVal strComputer As String, ByVal strProcess As String,ByVal UserName As String,ByVal Password As String)

        Dim processBatch As ManagementClass = New ManagementClass("Win32_Process")
        Dim inParams As ManagementBaseObject = processBatch.GetMethodParameters("Create")
        Dim msc As ManagementScope

        inParams("CurrentDirectory") = Nothing
        inParams("CommandLine") = strProcess
        Dim co As ConnectionOptions = New ConnectionOptions()
        co.Username = UserName
        co.Password = Password

        Try
            If (strComputer = System.Environment.MachineName) Then
                msc = New Management.ManagementScope("\\" & strComputer & "\root\cimv2")
            Else
                msc = New Management.ManagementScope("\\" & strComputer & "\root\cimv2", co)
            End If

            msc.Connect()
            processBatch.Scope = msc
            Dim meyhodoptions As InvokeMethodOptions = New InvokeMethodOptions(Nothing, System.TimeSpan.MaxValue)
            Dim outParamas As ManagementBaseObject = Nothing
            outParamas = processBatch.InvokeMethod("Create", inParams, Nothing)

        Catch ex As Exception

        End Try
End Sub

Some Useful Links
http://msdn.microsoft.com/en-us/library/system.management.invokemethodoptions.aspx
http://msdn.microsoft.com/en-us/library/Aa389388

Related Posts by Categories



Stumble This Fav This With Technorati Add To Del.icio.us Digg This Add To Reddit Add To Facebook Add To Yahoo

2 comments:

Luis Fonseca said...

What namespace did you import? System.Management did not work.

CoolCoder said...

He uses an unexistant namespace.

Post a Comment