幸运飞艇投注平台app
全國服務熱線:0597-2297794 24小時咨詢:15080281944 15080287989
設為首頁加入收藏聯系我們

VB中使用系統注冊表

來源:互聯網   發布時間:2013/12/27 21:55:47     閱讀數:555

  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 = &H80000000  Case "HKEY_CURRENT_CONFIG": lngKey = &H80000005  Case "HKEY_CURRENT_USER": lngKey = &H80000001  Case "HKEY_DYN_DATA": lngKey = &H80000006  Case "HKEY_LOCAL_MACHINE": lngKey = &H80000002  Case "HKEY_PERFORMANCE_DATA": lngKey = &H80000004  Case "HKEY_USERS": lngKey = &H80000003  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

 如果您覺得此文對您有啟發或者幫助,可以花3秒鐘收藏到QQ空間。平時注意多收集,用時不會干著急!

[您可能感興趣的文章]
最新案例
網站建設資訊
  1. [資訊]Google Adsense ?
  2. [資訊]如何防止google adse?
  3. [資訊]使你的網站更專業--談網站優化?
  4. [資訊]優化你的站點,讓它加載的再快一?
  5. [資訊]網站建設:提高網站訪問量的策略?
  6. [資訊]揭開虛擬主機供應商的面紗?
SEO常見問題解答
  1. [SEO]什么是ALT屬性?
  2. [SEO]什么是鏈接錨文本?
  3. [SEO]什么是動態頁面?
  4. [SEO]HTTP狀態碼是什么意思??
  5. [SEO]鏈接養殖場?
  6. [SEO]首選域?
點擊立刻咨詢
幸运飞艇投注平台app