Start process on remote Pc via Wmi problem RRS feed

  • Question

  • I have a problem when i try to start batch not locate on system32 folder

    If i copy oro.cmd on C:\temp and try to start and call function with RemoteStart(remoteServer, {"c:\temp\oro.cmd"})  doesn't works

    My question is cmd must be on windows folder??

    this is my code:

       RemoteStart(remoteServer, {"oro.cmd"})

     Function RemoteStart(ByVal Server As String, ByVal sProcess As Object)
                Dim connOptions As ConnectionOptions = New ConnectionOptions()
                connOptions.Username = "sms"
                connOptions.Password = "Mc"
                connOptions.EnablePrivileges = True
                Dim theScope As ManagementScope = New ManagementScope("\\" & Server & "\root\cimv2", connOptions)
                Dim theClass As New ManagementClass(theScope, New ManagementPath("Win32_Process"), New ObjectGetOptions())
                theClass.InvokeMethod("Create", sProcess)
            Catch ex As Exception
            End Try

            Return Nothing

        End Function

    Could you help me?

    Monday, November 20, 2017 10:24 AM

All replies

  • Hi termi_80,

    Can you tell me what the oro.cmd is? Did you write it yourself? Can successfully put in system32 folder?

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Tuesday, November 21, 2017 6:40 AM
  •  This seems to work for me.  However,  you need to have both computers set up correctly to be able t do this.

    Imports System.Management
    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            '#####  This can not run a process that requires user interaction. The remote user will not see it or be able to interact with it. #####
            Dim remoteMachine As String = "RemoteComputerName"
            Dim sFile As String = "C:\Users\*UserName*\Documents\MyCommandFile.cmd" 'the full or relative path to the executable file
            Dim connOptions As New ConnectionOptions()
            connOptions.Impersonation = ImpersonationLevel.Impersonate
            connOptions.EnablePrivileges = True
            connOptions.Username = "*UserName*"
            connOptions.Password = "*Password*"
            Dim manScope As New ManagementScope(String.Format("\\{0}\ROOT\CIMV2", remoteMachine), connOptions)
            Dim processClass As New ManagementClass(manScope, New ManagementPath("Win32_Process"), New ObjectGetOptions())
            'For more details on the 4 parameters of the Create method -->
            Dim inParams As ManagementBaseObject = processClass.GetMethodParameters("Create")
            inParams("CommandLine") = sFile
            'For more details on the return values of the Create method -->
            Dim outParams As ManagementBaseObject = processClass.InvokeMethod("Create", inParams, Nothing)
            Dim ReturnValue As CreateReturnValues = CType(outParams("returnValue"), CreateReturnValues)
            Dim ProcessId As Integer = CInt(outParams("processId"))
            Debug.WriteLine("Creation of the process returned: " & ReturnValue.ToString)
            Debug.WriteLine("Process ID: " & ProcessId.ToString)
        End Sub
        Public Enum CreateReturnValues As UInteger
            SuccessfulCompletion = 0
            AccessDenied = 2
            InsufficientPrivilege = 3
            UnknownFailure = 8
            PathNotFound = 9
            InvalidParameter = 21
            'Other (22–4294967295) See Error Constants -->
        End Enum
    End Class

     I would recommend running an elevated Command Prompt (right click -> Run as administrator) and running the command below.  Do that on both or all of your computers.  It will help you automatically set up the firewall settings and start the required services.  You just need to answer (y or n) to the questions it asks you. Basically you will be typing y to let it do its thing.  I struggled with getting both computers to allow WMI to run a remote executable until i ran this on both computers.

    Type and Enter this into the elevated command prompt on the computers...

    winrm quickconfig


     You can also read through the msdn documents starting at the link below.  If you follow through the links on the left and in the paragraphs,  you will find important information such as setting up all the settings manually on the computers if you don't want to run the command i showed above.

    Creating Processes Remotely using WMI

    If you say it can`t be done then i`ll try it

    Tuesday, November 21, 2017 12:04 PM