Solved

vb.net and sending remote commands

Posted on 2014-11-08
5
343 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 34

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 34

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 34

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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

632 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