中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-06-28 22:39
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 限制a.vbs 的运行次数? 查看 973 回复 6
楼 主 限制a.vbs 的运行次数? 发表于 2009-02-23 12:53 ·  中国 北京 联通
中级用户
★★
积分 313
发帖 162
注册 2007-04-02 06:45
19年会员
UID 83693
性别 男
状态 离线
每天限制a.vbs 的运行次数?
如果a.vbs 运行次数超过2,则退出。

[ Last edited by ooaf on 2009-2-23 at 13:16 ]
2 发表于 2009-02-23 13:57 ·  美国 惠普HP
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
本版搜索“次数”,可以找到几个思路。
3 发表于 2009-02-23 16:59 ·  中国 山东 济南 联通
高级用户
★★★
积分 959
发帖 474
注册 2007-10-25 10:40
18年会员
UID 100716
性别 男
状态 离线
for i=1 to 2…………next
这是运行二次
4 发表于 2009-02-23 17:13 ·  中国 北京 联通
中级用户
★★
积分 313
发帖 162
注册 2007-04-02 06:45
19年会员
UID 83693
性别 男
状态 离线
我的意思是,a.vbs 运行结束后,再运行。 而不是重复运行2次。
如: 

我把a.vbs放在启动项里,一天可能开机好几次,那么a.vbs 就会运行好几次,因此,a.vbs 每次运行时,检查 当天的运行次数,超过2就不运行。
5 发表于 2009-02-23 18:54 ·  中国 广东 广州 电信
初级用户
★★
l i u s s
积分 73
发帖 101
注册 2008-09-17 00:21
17年会员
UID 125825
性别 男
来自 GZ
状态 离线
在你的原代码前面加上以下一段代码:

Set WshShell=WScript.CreateObject("WScript.Shell")
Key="HKEY_CURRENT_CONFIG\Software\avbs\"
on error resume next
Last=WshShell.RegRead(Key&"Start")
a=split(Last,"\"):LastDay=a(0)
if LastDay=CStr(date()) then
b=a(1):c=a(2)
if c<>"" then
WshShell.Popup "今天内你已经运行了两次,再见! ",5,"警告!",VbExclamation
Wscript.Quit
end if
else
WshShell.RegDelete(Key&"Start")
end if
on error goto 0
if c="" then WshShell.Regwrite(Key&"Start"),date()&"\1\2"
if b="" then WshShell.Regwrite(Key&"Start"),date()&"\1"


RE:6楼)更新以上代码如下(没有提示):

Set WshShell=WScript.CreateObject("WScript.Shell")
num=2 '设置允许启动次数
Key="HKEY_CURRENT_CONFIG\Software\avbs\"
on error resume next
Last=WshShell.RegRead(Key&"Start")
a=split(Last,"\"):LastDay=a(0)
if LastDay=CStr(date()) then
b=cint(a(1)):if b=num then:Wscript.Quit
else
WshShell.RegDelete(Key&"Start")
end if
on error goto 0
ctr=b+1
WshShell.Regwrite(Key&"Start"),date()&"\"&ctr


[ Last edited by newxso on 2009-2-26 at 19:54 ]
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
ooaf +4 2009-02-27 01:31
6 发表于 2009-02-26 05:11 ·  中国 北京 联通
中级用户
★★
积分 313
发帖 162
注册 2007-04-02 06:45
19年会员
UID 83693
性别 男
状态 离线
没有提示的

Set WshShell=WScript.CreateObject("WScript.Shell")
Key="HKEY_CURRENT_CONFIG\Software\avbs\"
on error resume next
Last=WshShell.RegRead(Key&"Start")
a=split(Last,"\"):LastDay=a(0)
if LastDay=CStr(date()) then
b=a(1):c=a(2)
if c<>"" then
a=a
Wscript.Quit
end if
else
WshShell.RegDelete(Key&"Start")
end if
on error goto 0
if c="" then WshShell.Regwrite(Key&"Start"),date()&"\1\2"
if b="" then WshShell.Regwrite(Key&"Start"),date()&"\1"
7 发表于 2009-02-26 10:37 ·  中国 北京 联通
中级用户
★★
积分 313
发帖 162
注册 2007-04-02 06:45
19年会员
UID 83693
性别 男
状态 离线
谢谢,我知道了。我把提示删去,是因为我想让脚本隐藏执行。
论坛跳转: