B
Bob Butler
Guest
Vista "virtualizes" the registry so the attempts to access values under HKLM
get redirected to HKCU\Software\Classes\VirtualStore\Machine but I've run
into a problem because it also appears to work the opposite way as well.
I have an app that needs to scan the entire HKCU hive and it works great
except that when I get to the VirtualStore key it picks up all the keys and
values from HKLM as well. I'm running with UAC enabled and am logged on as
a user without admin rights and the code below gives me a whole long list of
keys. The odd thing is that when I run regedit.exe without elevation I see
just a few keys so there must be a way to turn off virtualization when
reading these keys.
I've tried using ImpersonateLoggedOnUser which the MS web page says disables
virtualization and that seems to work for a user that has admin rights
(running elevated or not) but not for a regular user. What am I missing?
Private Const KEY_READ = &H20019
Private Const HKEY_USERS = &H80000003
Private Const HKEY_CURRENT_USER = &H80000001
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" _
Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, _
phkResult As Long) As Long
Private Declare Function RegEnumKey Lib "advapi32.dll" _
Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, _
ByVal lpName As String, ByVal cbName As Long) As Long
x = RegOpenKey(HKEY_CURRENT_USER,
"Software\Classes\VirtualStore\Machine\Software", hKey)
If x = 0 Then
k = 0
Do
sKey = String$(1024, 0)
lSize = Len(sKey)
x = RegEnumKey(hKey, k, sKey, lSize)
If x Then Exit Do
Me.Print k; " "; Left$(sKey, InStr(1, sKey, vbNullChar) - 1)
k = k + 1
Loop
x = RegCloseKey(hKey)
End If
get redirected to HKCU\Software\Classes\VirtualStore\Machine but I've run
into a problem because it also appears to work the opposite way as well.
I have an app that needs to scan the entire HKCU hive and it works great
except that when I get to the VirtualStore key it picks up all the keys and
values from HKLM as well. I'm running with UAC enabled and am logged on as
a user without admin rights and the code below gives me a whole long list of
keys. The odd thing is that when I run regedit.exe without elevation I see
just a few keys so there must be a way to turn off virtualization when
reading these keys.
I've tried using ImpersonateLoggedOnUser which the MS web page says disables
virtualization and that seems to work for a user that has admin rights
(running elevated or not) but not for a regular user. What am I missing?
Private Const KEY_READ = &H20019
Private Const HKEY_USERS = &H80000003
Private Const HKEY_CURRENT_USER = &H80000001
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" _
Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, _
phkResult As Long) As Long
Private Declare Function RegEnumKey Lib "advapi32.dll" _
Alias "RegEnumKeyA" (ByVal hKey As Long, ByVal dwIndex As Long, _
ByVal lpName As String, ByVal cbName As Long) As Long
x = RegOpenKey(HKEY_CURRENT_USER,
"Software\Classes\VirtualStore\Machine\Software", hKey)
If x = 0 Then
k = 0
Do
sKey = String$(1024, 0)
lSize = Len(sKey)
x = RegEnumKey(hKey, k, sKey, lSize)
If x Then Exit Do
Me.Print k; " "; Left$(sKey, InStr(1, sKey, vbNullChar) - 1)
k = k + 1
Loop
x = RegCloseKey(hKey)
End If