1、使用WMI管理控制台,对服务进行最直观的控制
这当然不是我们需要的。
2、操纵注册表中的相关配置信息
1. | Start Registry Editor (Regedt32.exe). |
2. | From the Registry menu, click Select Computer. Type in the name of the computer that is not responding, and then click OK. |
3. | Locate the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services \EventLog
|
4. | Edit the following entries:
Value Name: Start (Data values are 0 = Boot, 1 = System, 2 = Automatic, 3 = Manual, 4 = Disabled)
Data Type: REG_DWORD Data: 3 (Default: 2) |
注册表操作的内容摘自http://support.microsoft.com/?kbid=158995
知道了修改注册表中的哪个键值,使用.NET编程操作就非常方便了。
3、WMI编程:使用VBScript
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='CiSvc'")
For Each objService in colRunningServices
Wscript.Echo objService.DisplayName & VbTab & objService.State
errReturnCode = objService.Change( , , , , "Automatic")
objService.StartService()
Wscript.Echo objService.DisplayName & VbTab & objService.State
Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colRunningServices = objWMIService.ExecQuery _
("Select * from Win32_Service where Name='CiSvc'")
For Each objService in colRunningServices
Wscript.Echo objService.DisplayName & VbTab & objService.State
errReturnCode = objService.Change( , , , , "Automatic")
objService.StartService()
Wscript.Echo objService.DisplayName & VbTab & objService.State
Next
以上代码从Microsoft TechNet脚本中心得到。
4、WMI编程:使用.NET
其实前面的VBScript编程就是对WMI进行的,使用.NET编程同样也可以对WM进行编程
相关资料在:Windows Management Instrumentation (WMI),
示例文章:
Monitoring Application Health with WMI and .NET
WMI Scripting Primer: Part 1
WMI Scripting Primer: Part 2
5、编程:P/Invoke和.NET程序