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,078 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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 …
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 …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
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…

762 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

17 Experts available now in Live!

Get 1:1 Help Now