Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
Dim sc As New System.ServiceProcess.ServiceController
sc.ServiceName = "name of service here"
If sc.Status = ServiceProcess.ServiceControllerStatus.Running Then
    'is running
End If

 

I've tried adding the code you've supplied but I do not have the System.ServiceProcess namespace available. Any ideas?

Thanks

Posted

Try WMI it will make it easier to get to remote machines, pluse you can get a lot more information on the Machines.

 

Remember to add a referance to the System.management.dll to your project...

 

Imports System.Management

Module Module1
   Sub Main()
       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 strComputerName, strQuery As String
       Console.WriteLine("WMI List Services and there State")
       strQuery = "SELECT * FROM Win32_Service"
       ' Ask for a computer name
       Do
           Console.Write("Please enter server name (type 'localhost' for local machine): ")
           strComputerName = Console.ReadLine()
       Loop Until strComputerName <> ""
       ' Connect to the remote computer
       co = New ConnectionOptions
       If (strComputerName.Trim().Length = 0) Then
           Console.WriteLine("Must enter machine IP address or name.")
       Else
           ' 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)
           Try
               queryCollection = query.Get()
           Catch e1 As Exception
               Console.WriteLine("Error: " + e1.ToString())
           End Try
           For Each mo In queryCollection
               ' create child node for operating system
               Console.WriteLine(mo("Name").ToString() + " [" + mo("StartMode").ToString() + "]")
           Next
           Console.ReadLine()
       End If
   End Sub
End Module

Glenn "Mykre" Wilson, DirectX MVP

Inner Realm

Managed DirectX and Game Programming Resources

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...