How Can I use this code ?

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

Guest

Hi EveryBody:

Is there any one know how can I use the following code to make windows application project that can start and stop the windows32 service manually?and tell me what the languege this code is wretin by is it Vb.Net or C#
any help will be appreciated

CODE:

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
 
Back
Top