derek7467
asked on
vb.net and sending remote commands
I am using the below code to run an SCCM update which works fine and i can see it in the logs, when i change the command to run to "taskmgr.exe" or "regedit.exe", it works locally but when attempting to send to a remote workstation, it creates the process but never loads the GUI window.
Dim RC As String = TextBox1.Text
Dim str As String
'Dim str2 As String
Try
Dim theScope As New ManagementScope("\\" & RC & "\root\cimv2")
Dim objectQuery As New ObjectQuery("SELECT * FROM Win32_OperatingSystem")
Dim managementObjectSearcher As New ManagementObjectSearcher(theScope, objectQuery)
Dim managementPath As New ManagementPath("Win32_Process")
Dim managementClass As New ManagementClass(theScope, managementPath, Nothing)
Dim managementClass1 As New ManagementClass("Win32_ProcessStartup")
managementClass1("CreateFlags") = 16777216
Dim methodParameters As ManagementBaseObject = managementClass.GetMethodParameters("Create")
Dim text As String = "Trigger SCCM Check"
If text = "Update Group Policy" Then
str = "gpupdate /force"
ElseIf text <> "Trigger SCCM Check" Then
MessageBox.Show("Please select an option from the list.")
Return
Else
str = "regedit.exe"
'str = "WMIC /namespace:\\root\ccm path sms_client CALL TriggerSchedule ""{00000000-0000-0000-0000-000000000021}"" /NOINTERACTIVE"
'str = "WMIC /namespace:\\root\ccm path sms_client CALL TriggerSchedule ""{00000000-0000-0000-0000-000000000026}"" /NOINTERACTIVE"
End If
methodParameters("CommandLine") = str
methodParameters("ProcessStartupInformation") = managementClass1
Dim managementBaseObject As ManagementBaseObject = managementClass.InvokeMethod("Create", methodParameters, Nothing)
Dim str1 As String = managementBaseObject("ReturnValue").ToString()
String.Concat("ReturnValue: ", str1)
Catch exception As Exception
MessageBox.Show("The command failed to execute.")
End Try
ASKER
any other recommendations to start a remote process besides pstools?
This should help you:
http://blogs.technet.com/b/heyscriptingguy/archive/2005/09/06/how-can-i-remotely-start-an-interactive-process.aspx
-saige-
http://blogs.technet.com/b/heyscriptingguy/archive/2005/09/06/how-can-i-remotely-start-an-interactive-process.aspx
-saige-
ASKER
tried to follow your advice, the below code runs, but doesnt return any errors and does not load notepad on the remote computer, am i doing it wrong?
Dim workstation As String = "10.1.x.x"
Dim WMIServiceObject As Object
'Dim objNewJob As Object
WMIServiceObject = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & workstation & "\root\cimv2").ExecQuery _
("select * from Win32_ScheduledJob where Primary=true")
For Each ObjSys In WMIServiceObject
ObjSys.create("Notepad.exe", "********10500.000000-420", True, 64, , True)
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Source
-saige-