标题: VBS固定循环命令 [打印本页]
作者: zinet 时间: 2008-10-21 00:16 标题: VBS固定循环命令
例一:有一脚本代码如下:
set ws=createobject("wscript.shell")
ws.run "aaa.exe"
wscript.sleep 10000
ws.run"taskkill /f /im aaa.exe",0
如何让vbs脚本自动循环运行10后,自动关机
命令该如何写?????
例二:有一脚本代码如下:
set ws=createobject("wscript.shell")
ws.run "aaa.exe"
当aaa.exe启动时,相继调用bbb.exe和ccc.exe启动
当aaa.exe关闭时,bbb.exe和ccc.exe依然运行
请问能否用脚本命令当aaa.exe退出时,bbb.exe和ccc.exe也跟着关闭
命令该如何写?????
作者: lixiaodaoaaa 时间: 2008-10-21 02:42 标题: 第一个比较好写
第一个好写点,第二个貌似不好写。。-
-
- set ws = CreateObject("WScript.Shell")
-
- i=0
-
- do until i=10
- i=i+1
- ws.run "aaa.exe"
- loop
- ws.run"taskkill /f /im aaa.exe",0
- shutdown -s -t 0
复制代码
或者下面的代码也可以循环10次,就可以了
实际上,我是用vbs实现的。
- set ws = CreateObject("WScript.Shell")
- i=0
- while i<10
- i=i+1
- ws.run "aaa.exe"
- wend
- ws.run "cmd /c taskkill /im aaa.exe /f"
- ws.run "shutdown -s -t 0"
复制代码
完了。特别感谢 zqz0012005 看了他的东西模仿过来的,自己仔细看他的帖子,回答的非常的经典!
参考帖子 http://bbs.bathome.net/thread-1979-1-1.html
[ 本帖最后由 lixiaodaoaaa 于 2008-10-21 02:49 编辑 ]
作者: rat 时间: 2008-10-21 12:52
第二个:- a = "aaa.exe"
- b = "bbb.exe"
- c = "ccc.exe"
-
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:" _
- & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
- Set colMonitoredProcesses = objWMIService. _
- ExecNotificationQuery("select * from __instancedeletionevent " _
- & "within 1 where TargetInstance isa 'Win32_Process'")
- i = 0
-
- Do While i = 0
- Set objLatestProcess = colMonitoredProcesses.NextEvent
- If LCase(objLatestProcess.TargetInstance.Name) = LCase(a) Then
- KillProcess(b)
- KillProcess(c)
- End If
- Loop
-
-
-
- Sub KillProcess(sProcessName)
- strComputer = "."
- Set objWMIService = GetObject("winmgmts:" _
- & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
-
- Set colProcessList = objWMIService.ExecQuery _
- ("Select * from Win32_Process Where Name = '" & sProcessName & "'")
-
- For Each objProcess in colProcessList
- objProcess.Terminate()
- Next
- End Sub
复制代码
[ 本帖最后由 rat 于 2008-10-21 12:53 编辑 ]
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |