求救:VBA如何将REG_BINARY类型值写入注册表!!!
比如 将78,02,00,00,de,2e,d0,45这个值写入注册表!
[解决办法]
VBA读写注册表,给个例子给你看。
-------------------
限制软件30天试用
Dim ReValue As Date '声明时间变量
Dim name As String '声明字符串变量,软件名称
Dim dd As Variant '声明数值变量,dd为日期差
name = "gggg " '给变量赋值软件名为gggg
ReValue = GetSetting(name, "MainKey ", "DateValue ", Date) '读取注册表软件名gggg的键值,如果没有则为当前日期
Me.Text1 = ReValue
dd = DateDiff( "d ", ReValue, Date) '计算日期差
Me.Text2 = dd
If dd = 0 Then '如果是第一天运行
SaveSetting name, "MainKey ", "dateValue ", Date '写注册表-
End If
If dd > 30 Then
MsgBox "软件已过期 "
Else
MsgBox "软件可以试用 "
'DoCmd Quit
MsgBox "还剩下 " & 30 - dd & "天试用期! "
End If
[解决办法]
也可以用:API
'定义API
Private Declare Function RegCloseKey Lib "advapi32.dll " (ByVal hKey As Long) As Long
Private Declare Function RegCreateKey Lib "advapi32.dll " Alias "RegCreateKeyA " _
(ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetvalueEx Lib "advapi32.dll " Alias "RegSetvalueExA " _
(ByVal hKey As Long, ByVal lpvalueName As String, ByVal Reserved As Long, _
ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Private Sub command1_Click()
Dim hKey As Long, SubKey As String, strExe As String, Ret As Long
hKey = &H80000001
SubKey = "software\microsoft\windows\currentversion\run "
' 设定运行的程序 C:\C:\Windows\Notepad.exe
strExe = "C:\Windows\Notepad.exe "
RegCreateKey hKey, SubKey, Ret
RegSetvalueEx Ret, "记事本 ", 0, 1, ByVal strExe, LenB(strExe)
RegCloseKey Ret
MsgBox strExe & " 程序已经被设定成 windows 启动时自动被执行的程序! "
End Sub