Solved

vb.net and sending remote commands

Posted on 2014-11-08
5
300 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 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