为了账号安全,请及时绑定邮箱和手机立即绑定

我该怎么去定义子程序和函数的问题!!急

我该怎么去定义子程序和函数的问题!!急

杨__羊羊 2021-08-18 20:15:37
代码如下:Private Sub Command1_Click() '去掉警告信息Dim hkey As LongRegCreateKey HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion\Winlogon", hkeyRegDeleteValue hkey, "legalnoticecaption"RegDeleteValue hkey, "LegalNoticeText"MsgBox "已完成设置,请重新启动计算机!", , "提示信息"End SubPrivate Sub Command2_Click() '添加警告信息Dim hkey As LongRegOpenKeyEx HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion", 0, 0, hkeyRegCreateKey HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows NT\CurrentVersion\Winlogon", hkeyDim a As Bytea = &O1RegSetValueEx hkey, "legalnoticecaption", 0, REG_SZ, ByVal Text1.Text, 255RegSetValueEx hkey, "LegalNoticeText", 0, REG_SZ, ByVal Text2.Text, 255MsgBox "已完成设置,请重新启动计算机!", , "提示信息"End SubRegCreateKey为何显示子程序或函数未定义??又如何定义?
查看完整描述

3 回答

?
慕尼黑的夜晚无繁华

TA贡献1864条经验 获得超6个赞

该函数是API函数,将下面代码保存为Reg.Bas就可以正常使用了。

'养成好习惯代表所有变量都需要先定义后使用
Option Explicit

'根键常数
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_DYN_DATA = &H80000006

'键值类型

Public Const REG_NONE = 0
Public Const REG_SZ = 1 '字符串值
Public Const REG_EXPAND_SZ = 2
Public Const REG_BINARY = 3 '二进制值
Public Const REG_DWORD = 4 'DWORD 值
Public Const REG_DWORD_BIG_ENDIAN = 5
Public Const REG_MULTI_SZ = 7

'----声明有关注册表API函数 --Start----

'建立一个新的主键
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" _
( _
ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByRef phkResult As Long _
) As Long

'打开一个主键 返回0代表打开成功,返回2代表打开失败
Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" _
( _
ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByRef phkResult As Long _
) As Long

'删除一个主键
Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" _
( _
ByVal hKey As Long, _
ByVal lpSubKey As String _
) As Long

'关闭一个主键 返回0代表关闭成功,6代表关闭失败
Public Declare Function RegCloseKey Lib "advapi32.dll" _
( _
ByVal hKey As Long _
) As Long

'创建或改变一个键值,lpData应由缺省的ByRef型改为ByVal型
Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" _
( _
ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal Reserved As Long, _
ByVal dwType As Long, _
ByVal lpData As Any, _
ByVal cbData As Long _
) As Long

'查询一个键值,lpData应由缺省的ByRef型改为ByVal型
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
( _
ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal lpReserved As Long, _
ByRef lpType As Long, _
ByVal lpData As Any, _
ByRef lpcbData As Long _
) As Long

'删除一个键值
Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" _
( _
ByVal hKey As Long, _
ByVal lpValueName As String _
) As Long

'----声明有关注册表API函数 End----



查看完整回答
反对 回复 2021-08-23
?
慕妹3242003

TA贡献1824条经验 获得超6个赞

在声明里加上
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
其他几个注册表函数也要声明

查看完整回答
反对 回复 2021-08-23
?
MMTTMM

TA贡献1869条经验 获得超4个赞

API函数还没定义,不能直接调用
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 RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (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 Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long



查看完整回答
反对 回复 2021-08-23
  • 3 回答
  • 0 关注
  • 300 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信