Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vb.net and sending remote commands

Posted on 2014-11-08
5
Medium Priority
?
391 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 35

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 35

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 35

Accepted Solution

by:
it_saige earned 1500 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

927 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