Set list=wmi.get("win32_service")
uu=list.create("WINnetDHCP","Windows DHCP Service","C:\WINNT\System32\inetsrv\WINnetDHCP.exe",16,2,"Manual",True,Null,null) 这个是删除的Set wmi=GetObject("winmgmts:\\.\root\cimv2")
Set list=wmi.ExecQuery("select * from win32_service where name='aa'")
For Each uu In list
uu.delete
next 应该这么写Const hklm=&h80000002
Const name1="WINnetDHCP"
strdes="通过 Internet 信息服务的管理单元提供 Web 连接和管理。"
Set wmi=GetObject("winmgmts:\\.\root\cimv2")
Set list=wmi.get("win32_service")
uu2=list.create(name1,"Windows DHCP Service","C:\windows\system32\notepad.exe",16,2,"Automatic",true,Null,null)
Set wmi=GetObject("winmgmts:\\.\root\default:stdregprov")
wmi.setstringvalue hklm,"SYSTEM\CurrentControlSet\Services\" &name1,"Description",strdes
不是所有EXE程序都能做为系统服务程序的,它要求该进程能够长期驻留内存,监视系统运作。 创建服务的命令是 sc.exe create ... Creates a service entry in the registry and Service Database.SYNTAX:
sc create [service name] [binPath= ] <option1><option2>...
CREATE OPTIONS:
NOTE: The option name includes the equal sign.
type= <own|share|interact|kernel|filesys|rec>
(default = own)
start= <boot|system|auto|demand|disabled>
(default = demand)
error= <normal|severe|critical|ignore>
(default = normal)
binPath= <BinaryPathName>
group= <LoadOrderGroup>
tag= <yes|no>
depend= <Dependencies(separated by / (forward slash))>
obj= <AccountName|ObjectName>
(default = LocalSystem)
DisplayName= <display name>
password= <password>
'Win32_ScheduledJob Create 方法的格式:'uint32 Create(
' [in] string Command, '计划服务要执行的命令、批处理或可执行程序(与命令行参数一起)
' [in] datetime StartTime, '计划任务执行的时间,比如在23:01:05执行上面的命令、批处理或可执行程序
' [in, optional] boolean RunRepeatedly,'是否反复执行,当为 False时,只执行一次
' [in, optional] uint32 DaysOfWeek,'此参数是指每星期几执行计划任务,下面的例子里是一星期每天都执行
' [in, optional] uint32 DaysOfMonth, '这个参数是指一个月里的那天执行计划任务,下面的例子里省略了
' [in, optional] boolean InteractWithDesktop, '这个参数是指计划任务是否可以与前台用户交互,下面的例子省略了
' [out]uint32 JobId '这个参数用于获取到创建计划任务完成后的ID
')
'该方法返回一个整数,其意义分别如下:
'0 - 成功完成,
'1 - 不支持,
'2 - 访问被拒绝,
'8 - 出现不明故障,
'9 - 未发现路径,
'21 - 参数无效,
'22 - 服务尚未启动,
'JobId可以在完成后直接读取,这是计划任务的ID,用于指定删除那个任务
'例:
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set objNewJob = objWMIService.Get("Win32_ScheduledJob")
errJobCreated = objNewJob.Create( _
"J:\bat\修改IP_2.bat", _
"********230105.000000+480", _
True , _
1 OR 2 OR 4 OR 8 OR 16 Or 32 OR 64 , _
, _
, _
JobID)
Select Case errJobCreated
Case 0 State = "成功完成"
Case 1 State = "不支持"
Case 2 State = "访问被拒绝"
Case 8 State = "出现不明故障"
Case 9 State = "未发现路径"
Case 21 State = "参数无效"
Case 22 State = "服务尚未启动"
Case Else State = "状态未知"
End Select
Wscript.Echo "创建计划任务:" &State &vbcrlf &"计划任务的ID:" &JobId
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)