OK, this is getting serious... According to what I understand about Win 7 registry and VirtualStore, this should not be happening. (Or I don't understand why it's happening.)
After some more testing I have the following routine:
Note I have two statements with OpenKey. One that accesses the HKLM\SOFTWARE branch and one that accesses the VirtualStore path explicitly. I also manually created the key and value in the HKLM hive so the program would not get the error: [Error 2] The system cannot find the file specified
""" Initialize the working environment as needed.
logger.info('-> initEnv Enter')
rtnStatus = 0
newPath = pConfig.get('ConvertParms', 'currdir')+ '\\tmp'
logger.debug('-- New tmp path: %s',newPath)
if not os.path.exists(newPath):
ConnKey = OpenKey(HKEY_LOCAL_MACHINE, r'SOFTWARE\Interface Software\ConnMgr', 0, KEY_READ)
# ConnKey = OpenKey(HKEY_CURRENT_USER, r'Software\Classes\VirtualStore\MACHINE\SOFTWARE\Interface Software\ConnMgr', 0, KEY_READ)
except OSError as err:
logger.error('Failed to retrieve DB Path. Err: %s',err)
rtnStatus = -1
if not rtnStatus:
ConnValue = QueryValueEx(ConnKey, "DB Path")
EWDataSource = os.path.split(str(ConnValue))
logger.debug('-- EWDataSource: %s',EWDataSource)
except OSError as err:
logger.error('Failed to Initialize Environment. Error: %s', err)
except Exception as err:
logger.error('Unexpected Exception found. Error: %s',err)
logger.debug('-- InitEnv: ConvertParms: %s', pConfig.items('ConvertParms'))
I have a standard user that is running this module so in theory this user should NOT have elevated permissions to access HKLM and when I try to access the HKLM I should be transparently getting the VS version. Here's what I find.
1. With mode KEY_READ, I can retrieve the HKLM key. This is expected.
2. With mode KEY_ALL_ACCESS, I get the error: [Error 5] Access is denied. What I don't get is the value in the VS as I expect.
3. When I run the OpenKey('HKEY_CURRENT_USER... I can access the key with KEY_READ or KEY_ALL_ACCESS.
So, what am I overlooking, or is _winreg accessing the registry in a way that is unvirtualizing it? How do I make Python access it virtualized? As a windows app, I should not be needing to access the VS explictly. That should be completely hidden from a windows app with un-elevated privileges. Also I am not getting the UAC prompt so Windows is not complaining.
Any help will be greatly appreciated by many I'm sure.