【发布时间】:2012-12-20 18:21:27
【问题描述】:
我想知道服务启动模式是否设置为“自动”,如果设置为“手动”
我有这个代码:
If objService("StartMode").ToString = "Automatic" Then
objService.ChangeStartMode("Manual")
End If
但是当我编译我的项目时,Visual Studio 会报告该错误:
COMException 未处理:未找到成员。 (来自 HRESULT 的异常:0x80020003 (DISP_E_MEMBERNOTFOUND))
在If objService("StartMode").ToString = "Automatic" Then
请帮我解决这个问题?这对我来说非常重要。谢谢。
我在管理员帐户上使用 Visual Studio 2008、VB.NET、Windows XP Sp3。
【问题讨论】:
-
将 strComputer 调暗为字符串 = "." Dim objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Dim colServiceList = objWMIService.ExecQuery _ ("Select * from Win32_Service where Name = '" & iobit & "'")'其中iobit是定义我的服务名称的字符串(例如:wauserv)'MsgBox(iobit.ToString) For Each objService In colServiceList Application.DoEvents() If objService("StartMode").ToString = "Automatic" Then ' If grade = 1然后 objService.ChangeStartMode("Manual") End If
-
您使用 WMI 而不是 ServiceController 类的任何原因?
标签: vb.net windows-services comexception