对Windows Service(服务)的启动类型进行操作的几种方式

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

None.gifstrComputer = "."
None.gifSet objWMIService = GetObject("winmgmts:" _
None.gif& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
None.gifSet colRunningServices = objWMIService.ExecQuery _
None.gif("Select * from Win32_Service where Name='CiSvc'")
None.gifFor Each objService in colRunningServices 
None.gifWscript.Echo objService.DisplayName  & VbTab & objService.State
None.giferrReturnCode = objService.Change( , , , , "Automatic")  
None.gifobjService.StartService()
None.gifWscript.Echo objService.DisplayName  & VbTab & objService.State
None.gifNext

以上代码从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程序

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值