欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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