How can I start and stop the service?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi EveryBody

In VB.Net how can I make windows application project that can start and stop the service manually

Any help will be appreciated

Husa
 
Hi,

Add a reference to system.management

Dim moReturn As Management.ManagementObjectCollection
Dim moSearch As Management.ManagementObjectSearcher
Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_Service where Name = 'RemoteRegistry'")

moReturn = moSearch.Get
For Each mo In moReturn
Dim args() As Object
Dim strReturn As String = mo.InvokeMethod("StopService",
args).ToString
Trace.WriteLine(String.Format("Stop Service return {0}",
strReturn))
strReturn = mo.InvokeMethod("StartService", args).ToString
Trace.WriteLine(String.Format("Start Service return {0}",
strReturn))
Dim strOut As String
strOut = String.Format("{0} - State {1}", mo("Name").ToString,
mo("State").ToString)
Trace.WriteLine(strOut)
Next


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_service.asp

http://msdn.microsoft.com/library/d...tartservice_method_in_class_win32_service.asp

http://msdn.microsoft.com/library/d...stopservice_method_in_class_win32_service.asp

Ken
 
* "=?Utf-8?B?SHVzYW0=?= said:
In VB.Net how can I make windows application project that can start and stop the service manually ?

See class 'System.ServiceProcess.ServiceController'.
 
Back
Top