WMI 创建系统服务的实现代码(Automatic)
程序员文章站
2022-07-06 12:58:48
复制代码 代码如下:const own_process = &h10const err_control = &h2const interactive = false
se...
复制代码 代码如下:
const own_process = &h10
const err_control = &h2
const interactive = false
servicename = "testservice"
displayname = "this is a test service."
installpath = "c:\windows\system32\test.exe"
set objwmi = getobject("winmgmts:" & "{impersonationlevel=impersonate, (security)}!\\.\root\cimv2")
set objsvr = objwmi.get("win32_service")
return = objsvr.create(servicename, displayname, installpath, own_process, err_control, "automatic", interactive, "localsystem", "")
if (return = 0) then
wscript.echo "service create success."
wscript.echo "servicename: " & servicename
wscript.echo "displayname: " & displayname
wscript.echo "installpath: " & installpath
wscript.echo ""
else
wscript.echo "service create failure(" & return & ")."
wscript.quit(return)
end if
wscript.quit