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 Type: REG_DWORD Data: 3 (Default: 2)(Data values are 0 = Boot, 1 = System, 2 = Automatic, 3 = Manual, 4 = Disabled) |
註冊表操作的內容摘自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
以上代碼從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程式