pb10中怎样实现时间限制(或倒计时)?
如题,部分源代码如下,但是文件句柄取不到,谁能帮我改改?
open事件中:
ulong l_handle,lu_class
string ls_name
Long i,ll_days,ll_installdateno,ll_days_count_down,ll_days_diff
Blob lbb_installdate[2]
String ls_installdate[2]
Date ldate_installdate[2],ldate_lastacctime,ldate_systime
systemtime lstr_creationtime,lstr_lastaccesstime,lstr_lastwritetime,lstr_systemtime
ls_name='程序'
l_handle=FindWindowA(lu_class,ls_name)
IF l_handle>0 THEN
MessageBox('提示信息','应用程序'+ This.AppName +'已经运行,不能多次启动!')
Halt Close
END IF
//检查软件最近一次运行的时间
l_handle=CreateFile("C:\Windows\system32\nsuser.dat",1,1,0,3,0,0)
GetFileTime(l_handle,lstr_creationtime,lstr_lastaccesstime,lstr_lastwritetime) //取得文件信息
FileTimeToSystemTime(lstr_lastaccesstime,lstr_systemtime) //文件时间转换为系统时间
ldate_lastacctime=date(string(lstr_systemtime.year)+'-'+string(lstr_systemtime.month)+'-'+string(lstr_systemtime.day)) //最后访问时间
GetSystemTime(lstr_systemtime) //取系统时间
ldate_systime=date(string(lstr_systemtime.year)+'-'+string(lstr_systemtime.month)+'-'+string(lstr_systemtime.day)) //系统时间
if ldate_lastacctime>ldate_systime then
Messagebox('机器时间','机器时间已经改变,你不能改变机器时间!',Exclamation!,OK!)
Halt Close
end if
//时间限制,倒计时
ll_days_count_down=30 //倒计时天数,如果为0不使用倒计时
//设置安装时间
RegistryGet("HKEY_LOCAL_MACHINE\SOFTWARE\Modify","Instlltime",RegBinary!,lbb_installdate[1]) //读取安装时间1
RegistrySet("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion","Modify",RegString!,"") //建立主键
RegistryGet("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Modify","Installtime",RegBinary!,lbb_installdate[2]) //读取安装时间2
ls_installdate[1]=string(lbb_installdate[1])
ls_installdate[2]=string(lbb_installdate[2])
if ls_installdate[1]<>'' and ls_installdate[2]<>'' then
for i=1 to 2
ldate_installdate[i]=date(ls_installdate[i])
next
ll_days=DaysAfter(ldate_installdate[1],ldate_installdate[2])
if ll_days>0 then
RegistrySet("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Modify","Installtime",RegBinary!,lbb_installdate[1]) //写入安装时间1
elseif ll_days<0 then
RegistrySet("HKEY_LOCAL_MACHINE\SOFTWARE\Modify","Installtime",RegBinary!,lbb_installdate[2]) //写入安装时间2
end if
if ll_days_count_down<>0 then
if ll_days>0 then
ll_days_diff=DaysAfter(ldate_installdate[1],ldate_systime)
elseif ll_days<0 then
ll_days_diff=DaysAfter(ldate_installdate[2],ldate_systime)
end if
if ll_days_diff>ll_days_count_down then
Messagebox('倒计时','倒计时'+string(ll_days_count_down)+'天完毕,系统停止运行!',Exclamation!,OK!)
Halt Close
end if
end if
else
if ls_installdate[1]='' then ll_installdateno=1
if ls_installdate[2]='' then ll_installdateno=2
if ls_installdate[1]='' and ls_installdate[2]='' then ll_installdateno=3
GetFileTime(l_handle,lstr_creationtime,lstr_lastaccesstime,lstr_lastwritetime) //取得文件信息
FileTimeToSystemTime(lstr_creationtime,lstr_systemtime) //文件时间转换为系统时间
ls_installdate[1]=string(lstr_systemtime.year)+'-'+string(lstr_systemtime.month)+'-'+string(lstr_systemtime.day) //安装时间1
ls_installdate[2]=ls_installdate[1] //安装时间2
for i=1 to 2
lbb_installdate[i]=blob(ls_installdate[i])
next
if ll_installdateno=1 or ll_installdateno=3 then
RegistrySet("HKEY_LOCAL_MACHINE\SOFTWARE\Modify","Installtime",RegBinary!,lbb_installdate[1]) //写入安装时间1
end if
if ll_installdateno=2 or ll_installdateno=3 then
RegistrySet("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Modify","Installtime",RegBinary!,lbb_installdate[2]) //写入安装时间2
end if
end if
//给系统日期赋值
gdate_sysdate=2009-05-31
RegistryGet("HKEY_LOCAL_MACHINE\SOFTWARE\Modify","Password",RegString!,gs_pwd) //登录密码
//RegistryGet("HKEY_LOCAL_MACHINE\SOFTWARE\Modify","SchoolNo",RegString!,ls_school_no) //ID号
ls_school_no="64526586"
IF Today()>gdate_sysdate THEN
MessageBox('日期过期','当前的日期已经超过'+string(gdate_sysdate),Exclamation!,OK!)
Halt Close
END IF