Avatar of Kelly Martens
Kelly Martens

asked on 

.NET Web Service call to run script on remote machine using WMI

I need to run a vbs script on a remote machine from WMI in a vb.net web service. The path of the vbs file on the remote machine is called
C:\ShippingSystem\Wave\wave.vbs

What I have so far.... (Remote Machine, Path on the remote machine, username, password)

Sub RunIt()
CreateProcess("REMOTEMACHINE", "C:\ShippingSystem\Wave\Wave.vbs", "DOMAIN\USERNAME", "password")
End Sub

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 System.Management.ManagementScope("\\" & strComputer & "\root\cimv2")
            Else
                msc = New System.Management.ManagementScope("\\" & strComputer & "\root\cimv2", co)
                'msc = New System.Management.ManagementScope("\\" & strComputer & "\root\cimv2", co)
            End If

            msc.Connect()

            Debug.WriteLine(msc.Path)
            processBatch.Scope = msc

Open in new window


'WHERE DO I GO FROM HERE

End Sub
Remote AccessVisual Basic.NETVB ScriptC#

Avatar of undefined
Last Comment
Kelly Martens

8/22/2022 - Mon