Solved

vb.net and sending remote commands

Posted on 2014-11-08
5
290 Views
Last Modified: 2014-11-17
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

Open in new window

0
Comment
Question by:derek7467
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:it_saige
ID: 40430643
This is by design.
For security reasons the Win32_Process.Create method cannot be used to start an interactive process remotely.

Source

-saige-
0
 

Author Comment

by:derek7467
ID: 40430680
any other recommendations to start a remote process besides pstools?
0
 
LVL 33

Expert Comment

by:it_saige
ID: 40430865
0
 

Author Comment

by:derek7467
ID: 40431122
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

Open in new window

0
 
LVL 33

Accepted Solution

by:
it_saige earned 500 total points
ID: 40431517
Are you running this as a script on the remote computer.  That is what the above article states.

Create a script on the remote computer and use a scheduled job to run that script.

-saige-
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now