VB读取注册表

Private Type SECURITY_ATTRIBUTES   nLength As Long   lpSecurityDescriptor As Long   bInheritHandle As BooleanEnd TypeDim lang As StringPrivate Declare Function RegOpenKeyEx Lib "advapi
摘要由CSDN通过智能技术生成

Private Type SECURITY_ATTRIBUTES
   nLength As Long
   lpSecurityDescriptor As Long
   bInheritHandle As Boolean
End Type

Dim lang As String

Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hkey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hkey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hkey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Lo

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用微软提供的CReg类可以方便地读写注册表,具体用法如下: ```cpp #include <creg.hxx> // 读取注册表 CRegKey reg; if (reg.Open(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion"), KEY_READ) == ERROR_SUCCESS) { DWORD dwType = REG_SZ; TCHAR szValue[1024] = { 0 }; ULONG ulCount = 1024; if (reg.QueryStringValue(_T("ProgramFilesDir"), szValue, &ulCount) == ERROR_SUCCESS) { // 读取成功 // szValue中存储了ProgramFilesDir的值 } reg.Close(); } // 写入注册表 CRegKey reg; if (reg.Create(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\MyCompany\\MyApp")) == ERROR_SUCCESS) { if (reg.SetStringValue(_T("MyValue"), _T("Hello, World!")) == ERROR_SUCCESS) { // 写入成功 } reg.Close(); } ``` 另外,在VB中,可以使用自身的SaveSetting、GetSetting函数读写注册表,也可以使用API函数来实现注册表任意读写。具体用法可以参考以下代码: ```vb ' 读取注册表 Dim hKey As Long Dim dwType As Long Dim dwSize As Long Dim sValue As String hKey = OpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows\CurrentVersion", KEY_READ) If hKey <> 0 Then dwType = REG_SZ sValue = String$(1024, 0) dwSize = Len(sValue) If QueryValueEx(hKey, "ProgramFilesDir", 0, dwType, ByVal sValue, dwSize) = ERROR_SUCCESS Then ' 读取成功 ' sValue中存储了ProgramFilesDir的值 End If RegCloseKey hKey End If ' 写入注册表 hKey = CreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\MyCompany\MyApp") If hKey <> 0 Then If SetValueEx(hKey, "MyValue", 0, REG_SZ, "Hello, World!", Len("Hello, World!")) = ERROR_SUCCESS Then ' 写入成功 End If RegCloseKey hKey End If ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值