Solved

vb.net and sending remote commands

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

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 32

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 32

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

705 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

19 Experts available now in Live!

Get 1:1 Help Now