Advertisement
ascend4nt

Registry Query Empty Key - FreeBASIC

Jan 3rd, 2013
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define _UNICODE 1
  2. #define UNICODE 1
  3. #include "crt\string.bi"
  4. #include "windows.bi"
  5.  
  6. '' Author: Ascend4nt
  7.  
  8. Function RegistryOpenKey(ByVal hKey As HKEY, ByRef sSubKey As WString, ByVal nAccess As UInteger) As HKEY
  9.     Dim hRet As HKEY
  10.    
  11.     If (hKey = 0) Then
  12.         Return 0
  13.     End If
  14.    
  15.     If (ERROR_SUCCESS = RegOpenKeyEx(hKey, sSubKey, 0, nAccess, @hRet) ) Then
  16.         Return hRet
  17.     End If
  18.     Return 0
  19. End Function
  20.  
  21. Function RegistryCloseKey(ByVal hKey As HKEY) As Integer
  22.     If (hKey = 0) Then
  23.         Return FALSE
  24.     End If
  25.     If (RegCloseKey(hKey) <> ERROR_SUCCESS) Then
  26.         Return FALSE
  27.     End If
  28.     Return True
  29. End Function
  30.  
  31.  
  32. Function RegistryIsKeyEmpty(ByVal hKey As HKEY) As Integer
  33.     Dim dwSubKeys As DWORD
  34.     Dim dwSubValues As DWORD
  35.    
  36.     If (ERROR_SUCCESS <> RegQueryInfoKey(hKey, 0,0,0, @dwSubKeys, 0,0, @dwSubValues, 0,0,0,0)) Then
  37.         Return FALSE
  38.     End If
  39.     If (dwSubKeys = 0 And dwSubValues <= 1) Then
  40.         Return TRUE
  41.     End If
  42.     Return FALSE
  43. End Function
  44.  
  45.  
  46. '' === MAIN CODE ===
  47.  
  48.     Dim myKey As HKEY
  49.     Dim bEmpty As Integer
  50.     bEmpty = FALSE
  51.    
  52.     ''myKey = RegistryOpenKey(HKEY_CURRENT_USER, "Software\7-Zip\Compression\Options", KEY_QUERY_VALUE)
  53.     myKey = RegistryOpenKey(HKEY_CURRENT_USER, "System\CurrentControlSet\Policies", KEY_QUERY_VALUE)
  54.     If (myKey <> 0) Then
  55.         bEmpty = RegistryIsKeyEmpty(myKey)
  56.         RegistryCloseKey(myKey)
  57.     End If
  58.    
  59.     Print "Reg Key empty?:";bEmpty
  60.        
  61.     Sleep
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement