如何在Windows XP Embedded上创建服务(未安装Sc.exe)?
答案 0 :(得分:0)
你可以尝试使用VBScript,我从here找到了这个代码,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