1

如何在 Windows XP Embedded 上创建服务(未安装 Sc.exe)?

4

1 回答 1

0

你可以尝试使用 VBScript,我从这里找到了这段代码,OP 说它工作得很好,所以也许值得一试。

' Connect to WMI. 
set objServices = GetObjecT("winmgmts:root\cimv2") 

' Obtain the definition of the Win32_Service class. 
Set objService = objServices.Get("Win32_Service") 

' Obtain an InParameters object specific to the Win32_Service.Create method. 
Set objInParam = objService.Methods_("Create").inParameters.SpawnInstance_() 

' Add the input parameters. 
objInParam.Properties_.item("Name") = "GPServer" '< - Service Name 
objInParam.Properties_.item("DisplayName") = "GPServer" '< - Display Name, what you see in the Services control panel 
objInParam.Properties_.item("PathName") = "c:\Server\srvany.exe" '< - Path and Command Line of the executable 
objInParam.Properties_.item("ServiceType") = 16 
objInParam.Properties_.item("ErrorControl") = 0 
objInParam.Properties_.item("StartMode") = "Manual" 
objInParam.Properties_.item("DesktopInteract") = True
'objInParam.Properties_.item("StartName") = ".\Administrator" '< - If null, will run as Local System 
'objInParam.Properties_.item("StartPassword") = "YourPassword" '< - Only populate if the SatrtName param is populated 

'More parameters and return statuses are listed in MSDN: "Create Method of the Win32_Service Class" 


' Execute the method and obtain the return status. 
' The OutParameters object in objOutParams is created by the provider. 
Set objOutParams = objService.ExecMethod_("Create", objInParam) 
wscript.echo objOutParams.ReturnValue
于 2013-01-22T13:43:16.257 回答