VB中应用系统软件申请注册表

VB中应用系统软件申请注册表 公布   阅读文章数:893

ini文档大多数用于寸放自身页面或是原始化信息内容,而运用程序要应用系统软件信息内容或是说要获知已在系统软件申请注册过的别的程序的一些信息内容就需要读去系统软件申请注册表了,例如一些运用必须应用启用MS OutLook Express就必须从HKEY_LOCAL_MACHINE\Software\Microsoft\Outlook Express\中的InstallRoot中载入相对路径。 声明一部分: Option Explicit Public Const READ_CONTROL = &H20000 Public Const STANDARD_RIGHTS_READ = (READ_CONTROL) Public Const STANDARD_RIGHTS_WRITE = (READ_CONTROL) Public Const KEY_QUERY_VALUE = &H1 Public Const KEY_SET_VALUE = &H2 Public Const KEY_CREATE_SUB_KEY = &H4 Public Const KEY_ENUMERATE_SUB_KEYS = &H8 Public Const KEY_NOTIFY = &H10 Public Const KEY_CREATE_LINK = &H20 Public Const SYNCHRONIZE = &H100000 Public Const STANDARD_RIGHTS_ALL = &H1F0000 Public Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE)) Public Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE)) Public Const KEY_ALL_ACCESS = ((STANDARD_RIGHTS_ALL Or KEY_QUERY_VALUE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY Or KEY_CREATE_LINK) And (Not SYNCHRONIZE)) Public Const KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE)) Public Const ERROR_SUCCESS = 0& 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 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 Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Function sdaGetRegEntry(strKey As String, strSubKeys As String, strValName As String, lngType As Long) As String On Error GoTo sdaGetRegEntry_Err Dim lngResult As Long, lngKey As Long Dim lngHandle As Long, lngcbData As Long Dim strRet As String Select Case strKey Case "HKEY_CLASSES_ROOT": lngKey = &H Case "HKEY_CURRENT_CONFIG": lngKey = &H Case "HKEY_CURRENT_USER": lngKey = &H Case "HKEY_DYN_DATA": lngKey = &H Case "HKEY_LOCAL_MACHINE": lngKey = &H Case "HKEY_PERFORMANCE_DATA": lngKey = &H Case "HKEY_USERS": lngKey = &H Case Else: Exit Function End Select If Not ERROR_SUCCESS = RegOpenKeyEx(lngKey, strSubKeys, 0&, KEY_READ, lngHandle) Then Exit Function lngResult = RegQueryValueEx(lngHandle, strValName, 0&, lngType, ByVal strRet, lngcbData) strRet = Space(lngcbData) lngResult = RegQueryValueEx(lngHandle, strValName, 0&, lngType, ByVal strRet, lngcbData) If Not ERROR_SUCCESS = RegCloseKey(lngHandle) Then lngType = -1& sdaGetRegEntry = strRet sdaGetRegEntry_Exit: On Error GoTo 0 Exit Function sdaGetRegEntry_Err: lngType = -1& MsgBox Err & "> " & Error$, 16, "GenUtils/sdaGetRegEntry" Resume sdaGetRegEntry_Exit End Function 看上去很繁杂,用起來却简易的紧,这就做到了繁杂的目地了。 比如:应用OutLook Express Dim outLook_Path As String Dim shstring As String outLook_Path = sdaGetRegEntry("HKEY_LOCAL_MACHINE", "Software\MicroSoft\Outlook Express\", "InstallRoot", 2) shstring = Mid(Trim(outLook_Path), 1, Len(outLook_Path) - 1) & "\msimn.exe" Shell shstring

相关阅读