Vitaliy Margolen wrote:
- res = RegOpenKeyExW( HKEY_LOCAL_MACHINE, profile_pathname, 0L,
KEY_QUERY_VALUE, &keyProfileDir );
res = RegGetValueW( keyProfileDir, profile_subkey,
profile_keyname, RRF_RT_ANY,
NULL, buffer, &sizePath ); /* RegGetValue
expects pcbData in bytes */
You opening the wrong key and querying the wrong value. You should be opening "Software\Microsoft\Windows NT\CurrentVersion\ProfileList" key and getting the value of "ProfilesDirectory" entry.
Don't see, why this should be wrong. RegKeyGetValue allows to specify a subkey, for a previously opened key and query a value there. My current implementation returned the correct path (imho). But I can change this.
Now about those fixed size buffers in GetUserProfileDirectoryW(). Why can't you use the passed in buffer instead?
I changed it already. Maybe I was overcautious already modifying argument buffers, if subsequent calls may still fail.
And the last thing - token. Look at _GetUserSidStringFromToken() from shell32/shellpath.c how to get the user from the token.
I looked at it. But I did not get a final clue what are going to tell me by referring to this. - should I replace GetUserName() by a user information retrieved from the token? - should I check user access rights to the registry key vs. the access privileges from the token?