golfnut1969 Posted October 14, 2004 Posted October 14, 2004 Anyone have any idea how I can determine the status of a service? (In particular, SMTP) I would like to know if the service is started, stopped, disabled, etc... Thanks, Quote
Administrators PlausiblyDamp Posted October 14, 2004 Administrators Posted October 14, 2004 Dim sc As New System.ServiceProcess.ServiceController sc.ServiceName = "name of service here" If sc.Status = ServiceProcess.ServiceControllerStatus.Running Then 'is running End If Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
golfnut1969 Posted October 15, 2004 Author Posted October 15, 2004 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 Quote
Administrators PlausiblyDamp Posted October 15, 2004 Administrators Posted October 15, 2004 You will also need to add a reference to System.ServiceProcess.dll Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Mykre Posted October 19, 2004 Posted October 19, 2004 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 Quote Glenn "Mykre" Wilson, DirectX MVP Inner Realm Managed DirectX and Game Programming Resources
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.