asked on
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