'''''''''''''''''''''''''''''''''''''''''''
'功能:删除添加指定的系统服务
'版权所有:Hahazhu QQ:383088680
'''''''''''''''''''''''''''''''''''''''''''
tp=inputBox("Notice:1为删除服务操作,其他为添加一个具体的服务操作:") '当为1时,是删除服务;当为其他时,是添加服务
if IsNumeric(trim(tp))=true then
if trim(tp)=1 then
servername=inputbox("请输入你要删除的服务名称:")
if trim(servername)<>"" then
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
sql0="Select * from Win32_Service Where Name = "&"'"&serverName&"'"
Set colListServices = objWMIService.ExecQuery _
(sql0)
for Each Obj in colListServices'此处的作用是用来判定输入的服务是否在系统服务中
if Obj.Name=servername then
sql="Select * from Win32_Service Where Name = "&"'"&serverName&"'"
Set colListOfServices = objWMIService.ExecQuery _
(sql)
For Each objService in colListOfServices
objService.StopService()
objService.Delete
Wscript.Echo ServerName&"服务已经删除了!"
Wscript.Quit
Next
else
Wscript.Echo "您指定的服务"&" "&ServeName&" "&"不存在,请仔细查看下!"
Wscript.Quit
end if
next
else
Wscript.Echo "您已经取消了此操作!"
Wscript.Quit
end if
else
Const OWN_PROCESS = 16
Const NOT_INTERACTIVE = False
Const NORMAL_ERROR_CONTROL = 2
'大家可以将下面扩展下,借助FSO功能可以检查EXE文件是否存在,等判断操作.
'只要修改以下常量就可以了.
Const Database="TestService"
Const DbService="TestService"
Const Servicepath="c:\windows\system32\cmd.exe"
Const Model="Manual"
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objService = objWMIService.Get("Win32_BaseService")
errReturn = objService.Create(DbService ,Database , _
Servicepath, OWN_PROCESS, NORMAL_ERROR_CONTROL,_
Model, NOT_INTERACTIVE, "NT AUTHORITY\LocalService", "" )
if errReturn=0 then
Wscript.Echo "服务已经装上了.哈哈~~~~"
Wscript.Quit
end if
end if
else
Wscript.Echo "您输入的内容必须是数字!"
Wscript.Quit
end if