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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SlingPlayer alternatives 1 36
How to tell the version of visual studio used for a certain project. 3 24
Angular JS Route 3 54
Error on link 14 39
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

861 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

20 Experts available now in Live!

Get 1:1 Help Now