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

对Windows Service(服务)的启动类型进行操作的几种方式strComputer = "."
对Windows Service(服务)的启动类型进行操作的几种方式Set objWMIService = GetObject("winmgmts:" _
对Windows Service(服务)的启动类型进行操作的几种方式& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
对Windows Service(服务)的启动类型进行操作的几种方式Set colRunningServices = objWMIService.ExecQuery _
对Windows Service(服务)的启动类型进行操作的几种方式("Select * from Win32_Service where Name='CiSvc'")
对Windows Service(服务)的启动类型进行操作的几种方式For Each objService in colRunningServices 
对Windows Service(服务)的启动类型进行操作的几种方式Wscript.Echo objService.DisplayName  & VbTab & objService.State
对Windows Service(服务)的启动类型进行操作的几种方式errReturnCode = objService.Change( , , , , "Automatic")  
对Windows Service(服务)的启动类型进行操作的几种方式objService.StartService()
对Windows Service(服务)的启动类型进行操作的几种方式Wscript.Echo objService.DisplayName  & VbTab & objService.State
对Windows Service(服务)的启动类型进行操作的几种方式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程序

相关文章:

  • 2022-12-23
  • 2021-10-23
  • 2021-09-28
  • 2021-10-26
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
猜你喜欢
  • 2021-04-01
  • 2022-02-04
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
  • 2022-12-23
  • 2022-01-12
相关资源
相似解决方案