WMI: Create Method of the Win32_Service Class

Posted by Marco on Stack Overflow See other posts from Stack Overflow or by Marco
Published on 2010-04-01T23:48:00Z Indexed on 2010/04/01 23:53 UTC
Read the original article Hit count: 395

Filed under:
|

Hello, 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

© Stack Overflow or respective owner

Related posts about wmi

Related posts about .NET