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

x
?
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
Medium Priority
?
1,089 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 1000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
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…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Loops Section Overview
Suggested Courses

876 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