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

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

            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

Related Posts by Categories

Stumble This Fav This With Technorati Add To Digg This Add To Reddit Add To Facebook Add To Yahoo


Luis Fonseca said...

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

CoolCoder said...

He uses an unexistant namespace.

Post a Comment