WMI:Win32_Service 类的创建方法
我正在尝试使用 Win32_Service 类的 Create 方法,但是当我调用 InvokeMethod 时,我收到此异常:
System.Management.ManagementException: Invalid method
at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
at System.Management.ManagementObject.InvokeMethod(String methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)
at <StartupCode$FSI_0075>.$FSI_0075.main@()
这是代码(在 F# 中,但对于 C# 程序员来说也不稳定:)):
let scope = new ManagementScope(@"root\cimv2", null)
use imageService = Utility.getServiceObject scope "Win32_Service"
use inParams = imageService.GetMethodParameters("Create")
inParams.["Name"] <- name
inParams.["DisplayName"] <- displayName
inParams.["PathName"] <- pathName
inParams.["ServiceType"] <- 0x10 // Own Process
inParams.["ErrorControl"] <- 0 // User is not notified
inParams.["StartMode"] <- "Automatic"
inParams.["DesktopInteract"] <- false
inParams.["StartName"] <- "LocalSystem"
inParams.["StartPassword"] <- ""
inParams.["ServiceDependencies"] <- null
use outParams = imageService.InvokeMethod("Create", inParams, null)
当以下情况抛出异常:最后一行被执行(我删除了下一行)。
我认为我正确调用了该方法,所以我不知道为什么会引发异常。 谁能帮助我吗?
提前致谢, 马可
I'm trying to use the Create method of the Win32_Service class, but when I call the InvokeMethod, I receive this exception:
System.Management.ManagementException: Invalid method
at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode)
at System.Management.ManagementObject.InvokeMethod(String methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)
at <StartupCode$FSI_0075>.$FSI_0075.main@()
This is the code (in F# but it is understable for C# programmers too :)):
let scope = new ManagementScope(@"root\cimv2", null)
use imageService = Utility.getServiceObject scope "Win32_Service"
use inParams = imageService.GetMethodParameters("Create")
inParams.["Name"] <- name
inParams.["DisplayName"] <- displayName
inParams.["PathName"] <- pathName
inParams.["ServiceType"] <- 0x10 // Own Process
inParams.["ErrorControl"] <- 0 // User is not notified
inParams.["StartMode"] <- "Automatic"
inParams.["DesktopInteract"] <- false
inParams.["StartName"] <- "LocalSystem"
inParams.["StartPassword"] <- ""
inParams.["ServiceDependencies"] <- null
use outParams = imageService.InvokeMethod("Create", inParams, null)
The exception is thrown when the last line is executed (I removed the next lines).
I think I'm calling correctly the method, so I don't know why the exception is thrown.
Can anyone help me?
Thanks in advance,
Marco
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我解决了:)
我只需要创建 imageService 对象,如下所示:
无论如何,谢谢:)
马可
I resolved :)
I just need to create the imageService object as this:
Thanks anyway :)
Marco