How Can I use this code ?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top