ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 效率神器,一键搞定繁琐工作
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
让更多数据处理,一键完成 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 1816|回复: 2

[求助]请高手帮我改正这道程序!

[复制链接]

TA的精华主题

TA的得分主题

发表于 2006-8-12 15:49 | 显示全部楼层 |阅读模式

在运行中,这道程序遇到了问题,请高手帮忙!不胜感谢!

程序在附件中。

Z1iUiy8U.rar (7.23 KB, 下载次数: 16)

TA的精华主题

TA的得分主题

发表于 2006-8-13 12:43 | 显示全部楼层

概念不清。

Global ZHUCE As Integer
'说明:全局变量ZHUCE=-1试用期满,ZHUCE=-2已注册,ZHUCE=其它值为剩余天数
Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, ByRef phkResult As Long) As Long
Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByRef lpType As Long, ByVal lpData As String, ByRef lpcbData As Long) As Long
Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
Sub autoopen()
    Main
End Sub
Private Sub Main() '程序总入口
Dim a As Long, rc(3) As Long, hKey As Long, KeyValType As Long, KeyValSize(3) As Long
Dim c As String, h As String, tmpVal(3) As String
Dim datetime As Integer
datetime = 30 '试用期天数
ZHUCE = -1
On Error GoTo cuowu
'以下从注册表HKEY_LOCAL_MACHINE\Software\MyProgram的三个值中取出相关数据字串tmpVal(3)
a = RegOpenKeyEx(&H80000002, "Software\MyProgram", 0, 131135, hKey) ' 打开注册表关键字
For a = 1 To 3: tmpVal(a) = String$(1024, 0): KeyValSize(a) = 1024: Next
rc(1) = RegQueryValueEx(hKey, "MyProgram3", 0, KeyValType, tmpVal(1), KeyValSize(1))
rc(2) = RegQueryValueEx(hKey, "MyProgram2", 0, KeyValType, tmpVal(2), KeyValSize(2))
rc(3) = RegQueryValueEx(hKey, "MyProgram1", 0, KeyValType, tmpVal(3), KeyValSize(3))
For a = 1 To 3
If (Asc(Mid(tmpVal(a), KeyValSize(a), 1)) = 0) Then
tmpVal(a) = Left(tmpVal(a), KeyValSize(a) - 1)
Else
tmpVal(a) = Left(tmpVal(a), KeyValSize(a))
End If
Next
a = RegCloseKey(hKey) '关闭注册表

'使用期限判断
If tmpVal(3) = "sign3" Then ZHUCE = -2: Exit Sub '查找到已注册标志sign3
If Len(tmpVal(1)) = 1023 And Len(tmpVal(2)) = 1023 And Len(tmpVal(3)) = 1023 Then
'首次使用,将当前日期分别写入tmpVal(1)和tmpVal(2)中,在tmpVal(3)中写入准许运行标志sign1
CreateObject("WScript.Shell").regWrite "HKEY_LOCAL_MACHINE\Software\MyProgram\MyProgram3", Date$, "REG_SZ"
CreateObject("WScript.Shell").regWrite "HKEY_LOCAL_MACHINE\Software\MyProgram\MyProgram2", Date$, "REG_SZ"
CreateObject("WScript.Shell").regWrite "HKEY_LOCAL_MACHINE\Software\MyProgram\MyProgram1", "sign1", "REG_SZ"
ZHUCE = datetime
MsgBox "试用期剩余" & Trim(datetime) & "天"
Else
If tmpVal(3) = "sign2" Then '查找到永久中止标志sign2中止使用
ZHUCE = -1
Exit Sub
MsgBox "试用期已满,请您注册!"
End If
If Date < DateValue(tmpVal(2)) Then '人为将系统日期往回更改中止使用
'写入tmpVal(3)中止使用字串“sign2”
CreateObject("WScript.Shell").regWrite "HKEY_LOCAL_MACHINE\Software\MyProgram\MyProgram1", "sign2", "REG_SZ"
ZHUCE = -1
MsgBox "试用期已满,请您注册!"
Else
If DateValue(Date) - DateValue(tmpVal(1)) > datetime Then '使用期超过datetime天中止使用
'写入tmpVal(3)中止使用字串sign2
CreateObject("WScript.Shell").regWrite "HKEY_LOCAL_MACHINE\Software\MyProgram\MyProgram1", "sign2", "REG_SZ"
ZHUCE = -1
MsgBox "试用期已满,请您注册!"
Else
'写入当前日期于tmpVal(2)中
CreateObject("WScript.Shell").regWrite "HKEY_LOCAL_MACHINE\Software\MyProgram\MyProgram2", Date$, "REG_SZ"
ZHUCE = datetime - (DateValue(Date) - DateValue(tmpVal(1)))
MsgBox "试用期剩余" & Trim(datetime) & "天"
End If
End If
End If
cuowu:
End Sub

TA的精华主题

TA的得分主题

 楼主| 发表于 2006-8-13 21:32 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-11-16 20:51 , Processed in 0.037719 second(s), 10 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表