Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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,086 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
[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
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

718 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