Solved

How do you Manipulate Services (Start/Stop) in Win2K on a Remote Machine- Using VB .NET and WMI??

Posted on 2003-11-26
2
1,081 Views
Last Modified: 2012-08-14
Ok, here is my problem...

I have been going back and forth trying to use WMI, and inherent VB .NET code to manipulate processes/services and so far have not been able to get it to work...

I can get it to work on my local machine, but when I try it on a remote machine, I get an error ' this feature is not supported' ... now I do understand why as its a powerful tool, but we utilize 100's of servers, and over 400,000 client machines, and having this function would be very helpful...

Its easy in script form (WMI/VB), but in the console it seems to have some safeguards in place, or I am just missing one key feature... anyway here is the code.... any help is appreciated.  (Note, I only use WMI and VB.net , no C++/C# please)....


Code:

Imports System.Diagnostics
Imports System.Drawing
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Management


 Private Sub Service_Stop_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Service_Stop_Button.Click

 Const CRLF As String = Chr(13) & Chr(10)

        Dim query As ManagementObjectSearcher
        Dim queryCollection As ManagementObjectCollection
        Dim co As ConnectionOptions
        Dim oq As System.Management.ObjectQuery
        Dim ms As System.Management.ManagementScope
        'Dim mo As ManagementObject
        Dim mo As ManagementObject
        Dim strComputerName, strQuery As String

        strComputerName = LogView_ComboBox.Text

        strQuery = "SELECT * FROM Win32_Service Where Name = 'RADEXECD'"

        ' Connect to the remote computer
        co = New ConnectionOptions()

        ' Point to machine
        ms = New System.Management.ManagementScope("\\" + strComputerName + "\root\cimv2", co)

        ' Query remote computer across the connection
        oq = New System.Management.ObjectQuery(strQuery)
        query = New ManagementObjectSearcher(ms, oq)

        queryCollection = query.Get()

        For Each mo In queryCollection
            ' create child node for operating system
           
            Dim errReturnCode
            errReturnCode = mo.StopService()

        Next


    End Sub

::::End Code :::


Note:  In this code I am trying to query the RADEXECD service... I want to be able to stop/start, etc... but from what I see I am getting an error at the mo.StopService() (Stating that this isnt a function of the System.Management class in Win32_Service).... but its the same thing thats used in WMI.. so not sure what I am missing... anyone have any ideas?  Is there something else I need to do to enable remote service manipulation??  or another route I can go... (Note: I do have admin rights to all the remote machines).

Thanks
0
Comment
Question by:phesser
2 Comments
 
LVL 8

Accepted Solution

by:
Dranizz earned 250 total points
ID: 9825199
use the service controller class and use the properties and methods of that class

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemserviceprocessservicecontrollerclasstopic.asp

this class can controls the services of any remote machine in a domain. Weel, if you have the rigths.
0
 

Author Comment

by:phesser
ID: 9826513
Thanks Dranizz...

That sparked what I needed.... I thought this class was only for C++/C#..but I just wasnt adding the reference to the .dll I needed.. ..

Appreciate it.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

820 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