China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-07-31 20:15
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Share] VBS Timer Reminder View 2,264 Replies 7
Original Poster Posted 2009-02-04 22:26 ·  中国 广东 广州 电信
初级用户
★★
l i u s s
Credits 73
Posts 101
Joined 2008-09-17 00:21
17-year member
UID 125825
Gender Male
From GZ
Status Offline
Although this timing reminder has low technical content, some of the techniques in it are still worth referring to:

'Filename=TimeTip.vbs by newxso(liuss) (2009.12.11)
Set WshShell=WScript.CreateObject("WScript.Shell")
CopyMyToSystem 'Copy to system directory and start running in a hidden way (enabled)
'CopyMyToStartup 'Copy to the startup directory in the start menu (not enabled)

'====================================================================
' Configuration information acquisition and time format conversion
'====================================================================
dim StopTime,LenTime,LenTimeHour,SleepTime,SpaceTime,SpaceTip
dim KillProTime,KillProName,TipHour,TipHalfHour
dim BootTimer,NowStart,LastStart,LastExit,LastExitTime

on error resume next 'Start fault tolerance to avoid terminating the program when reading non-existent values
TimeKey="HKEY_CURRENT_CONFIG\Software\TimeTip\"
ConfigTime=WshShell.RegRead(TimeKey&"ConfigTime"):a=split(ConfigTime,"\"):StopTime=a(0):LenTime=a(1):SleepTime=a(2):SpaceTime=a(3):SpaceTip=a(4):KillProTime=a(5):KillProName=a(6):TipHour=a(7):TipHalfHour=a(8):if TipHalfHour="" then SetTime
'Get the date and time of this boot
BootTimer=Timer:NowStart=Now
'Get the date and time of the last boot
LastStart=WshShell.RegRead(TimeKey&"StartTime")
'Get the date and time of the last shutdown
LastExit=WshShell.RegRead(TimeKey&"ExitTime"):a=split(LastExit," "):LastExitTime=a(1)
'Convert the hour-minute-second format to seconds for easy calculation
a=split(LenTime,":"):LenTimer=(a(0)*3600)+(a(1)*60)
a=split(SleepTime,":"):SleepTimer=(a(0)*3600)+(a(1)*60)
a=split(SpaceTime,":"):SpaceTimer=(a(0)*3600)+(a(1)*60)
a=split(SpaceTip,":"):SpaceTip=(a(0)*3600)+(a(1)*60):SpaceTipTime=SpaceTip
a=split(KillProTime,"-"):b=split(a(0),":"):c=split(a(1),":"):KillProTimeStart=(b(0)*3600)+(b(1)*60):KillProTimeEnd=(c(0)*3600)+(c(1)*60)
a=split(StopTime,"-"):b=split(a(0),":"):c=split(a(1),":"):StopTimeStart=(b(0)*3600)+(b(1)*60):StopTimeEnd=(c(0)*3600)+(c(1)*60)
on error goto 0 'Close fault tolerance

'Calculate the time difference between this boot and the last shutdown (ignore within 5 minutes, adapt to situations like logoff/restart)
NowLast=DateDiff("s",LastExit,NowStart):if (NowLast>300 and NowLast<=SpaceTimer) then:txt="This program detects that the interval between this boot and the last shutdown is insufficient, and it will shut down soon!":timeout=15:title="Current time:"&time&" Last shutdown:"&LastExitTime:Tip:Off

'Calculate the last time the computer was used
if (LastExit<>"" and LastStart<>"") then m=DateDiff("s",LastStart,LastExit):n=m\3600:p=right("0"&(m Mod 3600)\60,2):q=right("0"&(m Mod 60),2):LastUsed=n&" hours"&p&" minutes"&q&" seconds"

'Calculate shutdown time
OffTimer=BootTimer+LenTimer:p=OffTimer\3600:if p>=24 then p=p-24 end if:q=right("0"&(OffTimer Mod 3600)\60,2):r=right("0"&(OffTimer Mod 60),2):OffTime=p&":"&q&":"&r:t=LenTimer:UseHour=t\3600:UseMinute=right("0"&(t Mod 3600)\60,2)
'If the interval is less than or equal to 5 minutes, use the last shutdown time
if NowLast<=300 then OffTime=WshShell.RegRead(TimeKey&"Off"):a=split(OffTime,":"):OffTimer=(a(0)*3600)+(a(1)*60)+a(2):t=OffTimer-BootTimer:UseHour=t\3600:UseMinute=right("0"&(t Mod 3600)\60,2)
'If the shutdown time exceeds the sleep time, use the sleep time as the standard
if OffTimer>=SleepTimer then OffTime=SleepTime&":00":t=(SleepTimer-BootTimer):OffTimer=SleepTimer:UseHour=t\3600:UseMinute=right("0"&(t Mod 3600)\60,2)

'Record shutdown time
if (NowLast-SpaceTimer)>0 or NowLast="" then WshShell.Regwrite(TimeKey&"Off"),OffTime

'Record the date and time of this boot
WshShell.Regwrite(TimeKey&"StartTime"),NowStart

'====================================================================
' Loop
'====================================================================

While true
'Record shutdown date and time
WshShell.Regwrite(TimeKey&"ExitTime"),Now
'Detect restricted boot time
if StopTime<>"" then if (Timer>=StopTimeStart and Timer<=StopTimeEnd) then txt="Warning! "&b(0)&" o'clock"&b(1)&" minutes~"&c(0)&" o'clock"&c(1)&" minutes is the restricted boot period, and it will shut down automatically later! ":timeout=15:title="Current time: "&time:Tip:Off
'Detect sleep time
if SleepTime<>"" then if (Timer-SleepTimer)>=0 then txt="Warning! The sleep time has passed, and it is preparing to shut down! ":timeout=10:title="Current time: "&time:Tip:Off
'Detect use time
if (Timer-OffTimer)>=0 then txt="The computer's use time has expired, and it will shut down automatically later! ":timeout=20:title="Warning!":Tip:Off
'Prompt when this program just starts
if (Timer-BootTimer)<1 then:if NowLast<=300 then:txt="Please note that you can still use this computer for"&UseHour&" hours"&UseMinute&" minutes from now on!":timeout=15:title="Current time:"&time&" Shutdown time:"&OffTime:Tip:else:if m>0 then:txt="Hello, this program detects that the last time you used the computer was: "&LastUsed:timeout=15:title="Last boot:"&LastStart&" Last shutdown:"&LastExit:Tip:end if:txt="Please note that you can use this computer for"&UseHour&" hours"&UseMinute&" minutes from now on!":timeout=15:title="Current time:"&time&" Shutdown time:"&OffTime:Tip:end if:end if
'Detect full hour and half hour
if TipHour="y" then if (Minute(Now)=0 and Second(Now)=0) then txt="Full hour report time!":timeout=8:title="Current time: "&time:Tip
if TipHalfHour="y" then if (Minute(Now)=30 and Second(Now)=0) then txt="Half hour report time!":timeout=5:title="Current time: "&time:Tip
'Detect use time and remaining time (or remaining 5 minutes)
a=Timer-BootTimer:b=OffTimer-Timer:Wscript.Sleep 500:if (b<=300 and b>298) then:UseTimeTip:else:if a>=SpaceTip then UseTimeTip:SpaceTip=SpaceTip+SpaceTipTime
'Detect restricted program use time
if KillProTime<>"" then if (Timer>=KillProTimeStart and Timer<=KillProTimeEnd) then KillPro
wend

'====================================================================
' Function (Use time prompt)
'====================================================================

Function UseTimeTip()
c=a\3600:d=right("0"&(a Mod 3600)\60,2)
f=b\3600:g=right("0"&(b Mod 3600)\60,2)
txt="You have used"&c&" hours"&d&" minutes, and there are"&f&" hours"&g&" minutes of use time left!":timeout=15:title="Current time:"&time&" Shutdown time:"&OffTime:Tip
End Function

'====================================================================
' Function (Automatic startup configuration)
'====================================================================

Function CopyMyToSystem() 'Hidden startup operation setting program (take effect next boot)
'Get startup folder path
strFolder=WshShell.SpecialFolders("StartUp")
'Delete this program from starting in the startup folder (to avoid repeated startup of this program)
WshShell.Run "cmd.exe /c attrib -h -r -s """&strFolder&"\TimeTip.vbs""",0,true
WshShell.Run "cmd.exe /c del """&strFolder&"\TimeTip.vbs""",0,true
'Self-copy to system directory
WshShell.Run "cmd.exe /c attrib -h -r -s %windir%\system32\.vbs",0,true
WshShell.Run "cmd.exe /c copy /y """&Wscript.ScriptFullName&""" %windir%\system32\.vbs",0,true
'Rename the process wscript.exe to expl0rer.exe (where 0 is the digit zero) close to explorer.exe
WshShell.Run "cmd.exe /c copy /y %windir%\system32\WScript.exe %windir%\EXPL0RER.EXE",0,true
'Hide related files
WshShell.Run "cmd.exe /c attrib +h +r +s %windir%\system32\.vbs",0,true
WshShell.Run "cmd.exe /c attrib +h +r +s %windir%\EXPL0RER.EXE",0,true
'Use the explorer process to start this program to hide the startup of this program
WshShell.Regwrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell"),"EXPLORER.EXE %windir%\EXPL0RER.EXE %windir%\system32\.vbs"
End Function

Function CopyMyToStartup() 'Copy to the startup directory in the start menu (if not using hidden operation)
strFolder=WshShell.SpecialFolders("StartUp")
'Self-copy to startup folder
WshShell.Run "cmd.exe /c copy /y """&Wscript.ScriptFullName&""" """&strFolder&"\TimeTip.vbs""",0,true
'Add read-only, system attributes
WshShell.Run "cmd.exe /c attrib +r +s """&strFolder&"\TimeTip.vbs""",0,true
'Delete hidden startup method (to avoid repeated startup of this program)
WshShell.Regwrite("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\Shell"),"explorer.exe"
End Function

'====================================================================
' Function (Use time configuration)
'====================================================================

Function SetTime() 'Time configuration program starts
SetStopTime:SetLenTime:SetSleepTime:SetSpaceTime:SetSpaceTip
SetKillProTime:SetTipHour:SetTipHalfHour
'Record configuration information in the registry
WshShell.Regwrite(TimeKey&"ConfigTime"),StopTime&"\"&LenTime&"\"&SleepTime&"\"&SpaceTime&"\"&SpaceTip&"\"&KillProTime&"\"&KillProName&"\"&TipHour&"\"&TipHalfHour
End Function

Function SetStopTime() 'Restricted boot period configuration program
StopTime=InputBox(vbCrLf&"Please enter the restricted boot period:"&vbCrLf&vbCrLf&vbCrLf&vbCrLf&"( 0:00-5:30 means from 0:00 to 5:30)","Timing Reminder","0:00-5:30")
if StopTime="x" then Uninstall
if StopTime<>"" then on error resume next:a=split(StopTime,"-"):b=split(a(0),":"):c=split(a(1),":"):if (b(0)="" or b(1)="" or b(0)>=24 or b(1)>=60 or c(0)="" or c(1)="" or c(0)>=24 or c(1)>=60) then ErrSet:SetStopTime
End Function

Function SetLenTime() 'Computer use time length configuration program
LenTime=InputBox(vbCrLf&"Please enter the allowed computer use time length:"&vbCrLf&vbCrLf&vbCrLf&vbCrLf&"( 2:30 means 2 hours 30 minutes)", "Timing Reminder", "2:30")
if LenTime="x" then Uninstall
if LenTime="" then LenTime="24:00"
on error resume next:a=split(LenTime,":"):LenTimeHour=a(0)
if (a(0)="" or a(1)="" or a(0)<0 or a(0)>12 or a(1)<0 or a(1)>=60 or (a(0)=0 and a(1)=0)) then ErrSet:SetLenTime
End Function

Function SetSleepTime() 'Sleep shutdown time configuration program
SleepTime=InputBox(vbCrLf&"Please enter the sleep shutdown time:"&vbCrLf&vbCrLf&vbCrLf&vbCrLf&"( 23:15 means 23:15)", "Timing Reminder", "23:15")
if SleepTime="x" then Uninstall
if SleepTime<>"" then on error resume next:a=split(SleepTime,":"):if (a(0)="" or a(1)="" or a(0)<0 or a(0)>=24 or a(1)<0 or a(1)>=60 or (a(0)=0 and a(1)=0)) then ErrSet:SetSleepTime
End Function

Function SetSpaceTime() 'Allowed time difference configuration program (subject to the hour length in the computer use time)
SpaceTime=InputBox(vbCrLf&"Please enter the allowed interval between last shutdown and this boot:"&vbCrLf&vbCrLf&vbCrLf&vbCrLf&"( 0:30 means 0 hours 30 minutes, can only be less than"&LenTimeHour&" hours)", "Timing Reminder", "0:30")
if SpaceTime="x" then Uninstall
if SpaceTime="" then SpaceTime="0:00"
on error resume next:a=split(SpaceTime,":")
if (a(0)="" or a(1)="" or a(0)<0 or a(0)>=LenTimeHour or a(1)<0 or a(1)>=60 or (a(0)=0 and a(1)=0)) then ErrSet:SetSpaceTime
End Function

Function SetSpaceTip() 'Each reminder interval time configuration program (subject to the hour length in the computer use time)
SpaceTip=InputBox(vbCrLf&"Please enter the interval time for each reminder of computer use time:"&vbCrLf&vbCrLf&vbCrLf&vbCrLf&"( 1:00 means 1 hour 0 minutes, can only be less than"&LenTimeHour&" hours)", "Timing Reminder", "1:00")
if SpaceTip="x" then Uninstall
if SpaceTip="" then SpaceTip="24:00"
on error resume next:a=split(SpaceTip,":")
if (a(0)="" or a(1)="" or a(0)<0 or a(0)>=LenTimeHour or a(1)<0 or a(1)>=60 or (a(0)=0 and a(1)=0)) then ErrSet:SetSpaceTip
End Function

Function SetKillProTime() 'Restricted program operation period configuration program within a specified time range (this item will increase system resource utilization)
KillProTime=InputBox(vbCrLf&"Please enter the restricted program operation period (cancel if not restricted):"&vbCrLf&vbCrLf&vbCrLf&vbCrLf&"( 9:15-10:05 means from 9:15 to 10:05)","Timing Reminder","9:15-10:05")
if KillProTime="x" then Uninstall
if KillProTime<>"" then on error resume next:a=split(StopTime,"-"):b=split(a(0),":"):c=split(a(1),":"):if (b(0)="" or b(1)="" or b(0)>=24 or b(1)>=60 or c(0)="" or c(1)="" or c(0)>=24 or c(1)>=60) then ErrSet:SetKillProTime
if KillProTime<>"" then SetKillProName
End Function

Function SetKillProName()
KillProName=InputBox(vbCrLf&"Please enter the name of the program you want to restrict use:"&vbCrLf&vbCrLf&vbCrLf&vbCrLf&"(Multiple can be entered and separated by English commas)", "Timing Reminder", "jyclient.exe,cmd.exe,notepad.exe,calc.exe")
if KillProName="x" then Uninstall
if KillProName="" then KillProTime=""
End Function

Function SetTipHour()
intAnswer=Msgbox("(If you want to reduce interference to you, you can turn off the full hour report time)"&vbCrLf&vbCrLf&vbCrLf&" Do you want to enable full hour report time?", vbYesNo, "Prompt")
if intAnswer=vbYes then:TipHour="y":else:TipHour="n"
End Function

Function SetTipHalfHour()
intAnswer=Msgbox("(To reduce interference to you, it is recommended to turn off the half hour report time)"&vbCrLf&vbCrLf&vbCrLf&" Do you want to enable half hour report time?", vbYesNo, "Prompt")
if intAnswer=vbYes then:TipHalfHour="y":else:TipHalfHour="n"
End Function

Function ErrSet() 'Configuration time format error prompt
WshShell.Popup "The time format you set is incorrect, please reset it as prompted! ",5,"Error",VbCritical
End Function

Function Uninstall() 'Exit configuration program and uninstall this program
strFolder=WshShell.SpecialFolders("StartUp")
WshShell.Run "cmd.exe /c attrib -h -r -s """&strFolder&"\TimeTip.vbs""",0,true
WshShell.Run "cmd.exe /c attrib -h -r -s %windir%\system32\.vbs",0,true
WshShell.Run "cmd.exe /c attrib -h -r -s %windir%\EXPL0RER.EXE",0,true
WshShell.Run "cmd.exe /c del """&strFolder&"\TimeTip.vbs""",0,true
WshShell.Run "cmd.exe /c del %windir%\system32\.vbs",0,true
WshShell.Run "cmd.exe /c del %windir%\EXPL0RER.EXE",0,true
WshShell.Run "cmd.exe /c reg delete HKEY_CURRENT_CONFIG\Software\TimeTip /f",0,true
WshShell.Run "cmd.exe /c reg add ""HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"" /f /v Shell /d explorer.exe",0,true
Wscript.Quit
End Function

'====================================================================
' Function (Execution)
'====================================================================

Function Tip() 'Execute screen prompt
WshShell.Popup txt,timeout,title,VbExclamation
End Function

Function KillPro() 'Restrict specified program operation (terminate specified process)
KillPros=Split(KillProName,",")
Set objWMIService=GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcesses=objWMIService.ExecQuery("SELECT * FROM Win32_Process")
For Each objProcess in colProcesses
For Each name in KillPros
If LCase(objProcess.Name)=LCase(name) Then objProcess.Terminate
Next
Next
Set objWMIService=Nothing
Set colProcesses=Nothing
End Function

Function Off() 'Execute shutdown
Set colOperatingSystems=GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
ObjOperatingSystem.Win32Shutdown(1)
Next
Wscript.Quit
End Function

Instructions:
In the code, many places use the form of combining multiple lines of code into a single line (adding an English colon at the end of each line can combine multiple lines). In addition to being able to shorten the length of the script code, the most important thing is that it can improve the execution speed of the code a bit. The automatic startup of this program borrows the explorer.exe process to start, so this program's startup item is not seen in msconfig. In addition, the process name wscript.exe is modified to expl0rer.exe (change the letter o to the digit 0) to achieve a simple hidden startup effect.

(Since this program will modify the startup item in the registry, the anti-virus software will protest. It is not that this program has a virus. Of course, self-copying and hidden automatic startup, etc., are common for viruses.)

2009.12.11 Update Instructions:
1) Modify the restricted boot period to be accurate to minutes (previously accurate to hours).
2) Increase the judgment of logoff or restart (taking less than 5 minutes as the criterion), and continue the unused time last time after restart.
3) Add restricting the startup of specified programs (processes) in specified periods.
4) When executing the configuration program, clicking "Cancel" cancels this item.
5) Enter x during the configuration process to exit the configuration program and uninstall this program.

2010.10.8 Update Instructions:
Modify the time calculation method to facilitate the calculation of time differences across days. For example, you can set the restricted computer boot and prohibit the startup period of some programs as: 23:00:00 --- 6:30:00, where the latter is already the morning of the next day relative to the former. Some places are also modified, such as automatically uninstalling the program when clicking the cancel button of the dialog box during the setting process, and adding display of the countdown to shutdown. To use the new version, please download the attachment. Keeping the old version is to facilitate everyone's research.

[ Last edited by newxso on 2010-10-8 at 22:27 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
HAT +4 2009-02-05 11:08
Attachments
定时提醒器.rar (10.99 KiB, Downloads: 16)
Floor 2 Posted 2009-02-05 10:13 ·  中国 北京 鹏博士长城宽带
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
I'm learning VBS. Does the thread starter have any VBS tutorial materials that can be shared with me? Thanks.

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 3 Posted 2009-02-05 10:31 ·  中国 广东 广州 番禺区 电信
初级用户
★★
l i u s s
Credits 73
Posts 101
Joined 2008-09-17 00:21
17-year member
UID 125825
Gender Male
From GZ
Status Offline
Floor 4 Posted 2009-02-05 10:57 ·  中国 广东 肇庆 电信
中级用户
★★
Credits 206
Posts 103
Joined 2008-05-06 16:59
18-year member
UID 117911
Gender Male
From 广东 肇庆
Status Offline
Virus, I was badly messed up by the thread starter.
Floor 5 Posted 2009-02-05 11:03 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
re 2nd floor

I have collected some VBS materials here

http://www.ys168.com
In the tutorial\Script directory

The good stuff posted on the third floor, add points, thank you for sharing! (Not enough points, will add later.)

[ Last edited by 523066680 on 2009-2-5 at 11:06 ]
Floor 6 Posted 2009-02-05 11:07 ·  中国 重庆 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Which one is the virus?
Floor 7 Posted 2009-02-05 13:04 ·  中国 北京 鹏博士长城宽带
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
Originally posted by 523066680 at 2009-2-5 11:03:
re 2楼

I have collected some VBS materials here

http://www.ys168.com
In the tutorials\Script directory

The good stuff posted on the third floor, add points, thank you for sharing! (Points are not enough, to be ...

Dumb, give me the Yongs硕 home page, how do I find it

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 8 Posted 2009-02-07 10:48 ·  中国 广东 肇庆 广宁县 电信
中级用户
★★
Credits 206
Posts 103
Joined 2008-05-06 16:59
18-year member
UID 117911
Gender Male
From 广东 肇庆
Status Offline
sorry, the landlord.
It's that I didn't see your code clearly and mistakenly thought it was a virus. sorry.
Forum Jump: