Function CheckExpire(strDateStart,iExpireTime) '#检验是否过期函数
On Error Resume next
CheckExpire = False
If DateDiff("d",CDate(strDateStart),Date)>=iExpireTime Then '#如果当前日期减去第一次运行的日期超过设定的天数则
CheckExpire = True
End if
End Function
On Error Resume next
Dim iExpireTime
iExpireTime = 30 '#过期时间为30天
Dim oShell,DateStart
Set oShell = CreateObject("WScript.Shell")
DateStart=oShell.RegRead("HKLM\SOFTWARE\Company\Key\Value")
If DateStart="" Then '#如果读取到的值为空,说明是第一次运行
WScript.Echo "第一次"
oShell.RegWrite "HKLM\SOFTWARE\Company\Key\Value",Date()
End If
If DateStart="" Or Not CheckExpire(DateStart,iExpireTime) Then
WScript.Echo "尚未过期"
Else
WScript.Echo "已过期"
WScript.Quit
End If
如果不懂,可以百度HI我。
On Error Resume Next
Const HKEY_LOCAL_MACHINE = &H80000002
Const REG_EXPAND_SZ = 2
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
StrKeyRoot = HKEY_LOCAL_MACHINE
RegPath = "HKEY_LOCAL_MACHINE"
StrKeyPath = "Software\fastslz"
oReg.CreateKey StrKeyRoot, StrKeyPath
StrValue = "StartDate"
oReg.GetStringValue StrKeyRoot,StrKeyPath,StrValue,StrName
If IsNull(StrName) Then
StrName = "" & Date & ""
oReg.SetExpandedStringValue StrKeyRoot, StrKeyPath, StrValue, StrName
Else
oReg.GetExpandedStringValue StrKeyRoot, StrKeyPath, StrValue, StrName
CreateObject("WScript.Shell").Popup "已经用了 " & DateDiff("D", CDate(StrName), CDate(Date)) &"天!" & vbcrlf & "本软件最多使用30天" ,5,"温馨提示",4096+64
If DateDiff("D", CDate(StrName), CDate(Date)) >= 30 Then
CreateObject("WScript.Shell").Popup DateDiff("D", CDate(StrName), CDate(Date))&"已过期" ,5,"温馨提示",4096+64
WScript.Quit
End If
End If
'写代码也不容易,要注释更不容易再加点分吧 ^_^
'另外说明这种方法系统时间调整下还是可以用,不过还是有办法解决的(只是比较麻烦)
晕,你都说的存到变量A,既然是变量在执行完程序后就没了。
要是存在文件中还差不多 ^_^