vbs定时执行

来源:互联网 发布:浙江剑龙网络案件 编辑:程序博客网 时间:2024/06/08 05:27

vbs定时执行

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

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

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

定时执行

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

合并之后为

Dim OKset 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)Loopend if

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

原创粉丝点击