vbs定时执行

vbs定时执行

为了避免多次点击重复执行,首先要判断是否已经在运行wscript.exe

Dim OK
set bag=getobject("winmgmts:\\.\root\cimv2") 
set pipe=bag.ExecQuery("select * from win32_process where name='wscript.exe'")
if pipe.count > 1 then
OK = True 
else 
OK = False
end if

因为第二次点击的时候会再生成一个wscript.ext的进程,所以这里要判断pipe.count大于1,才能证明原来已经有wscript在运行了

定时执行

Set ws = CreateObject("Wscript.Shell")
Do
ws.run "cmd /c 1.bat",0
Wscript.Sleep(1000)
Loop

合并之后为

Dim OK
set bag=getobject("winmgmts:\\.\root\cimv2") 
set pipe=bag.ExecQuery("select * from win32_process where name='wscript.exe'")
if pipe.count > 1 then
    Msgbox "do not touch again"
else 
Set ws = CreateObject("Wscript.Shell")
Do
    ws.run "cmd /c 1.bat",0
    Wscript.Sleep(1000)
Loop
end if

保存在记事本里,然后文件改名为run.vbs就行了

猜你喜欢

转载自blog.csdn.net/wodecc_u/article/details/72899408
vbs
今日推荐