使用API函数修改注册表

作者:袖梨 2022-07-02
 
使用API函数修改注册表
 
为了让自己的程序成为自动启动需要修改注册表。下面事例可以供参考
 
Option Explicit
 
Const REG_SZ = 1
Global Const HKEY_LOCAL_MACHINE = &H80000002
 
Public Declare Function RegOpenKey Lib "advapi32" Alias "RegOpenKeyA" _
      (ByVal hKey As Long, ByVal lpszSubKey As String, phkResult As Long) As Long
'该函数用于打开系统注册表中已存在的键函数的返回值:键打开成功返回0,否则返回非0,phkResult被设置为该键的句柄。
 
Public Declare Function RegSetValueEx Lib "advapi32" Alias "RegSetValueExA" _
      (ByVal hKey As Long, ByVal lpszValueName As String, _
      ByVal dwReserved As Long, ByVal fdwType As Long, _
      lpbData As Any, ByVal cbData As Long) As Long
'该函数用于向系统注册表中指定的键添加键名和键值。函数的返回值: 添加键名、键值成功返回0,否则返回非0。
 
Public Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long
'该函数用于关闭系统注册表中打开的键。函数的返回值:键关闭成功返回0,否则返回非0。
 
Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" _
      (ByVal hKey As Long, ByVal lpValueName As String) As Long
'该函数用于删除注册表中打开键的键值
 
Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" _
      (ByVal hKey As Long, ByVal lpSubKey As String) As Long

相关文章

精彩推荐