No.
It is not me who is looking, but my code.
And my code is looking at ntuser.dat located in the current user profile.
"C:\Documents and Settings\<current user name>\ntuser.dat"
<Current User Name> is determined by API call.
It works 99.5% of the time but .remaining 05% is the reason I would like to
find the answer.
Jack
You should have a look here to make sure you're looking at
the right profile folder:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\hivelist\
\REGISTRY\USER\S-1-5-21-4233798886-620521722-3728218106-1004
> No.
> It is not me who is looking, but my code.
[quoted text clipped - 19 lines]
>>
>> You're probably looking in the wrong profile folder.
Jack - 03 Jul 2007 22:02 GMT
The API call I use is:
GetUserName()
http://msdn2.microsoft.com/en-us/library/ms724432.aspx
This is a recommended method by Microsoft to obtain the current user name.
Jack
> You should have a look here to make sure you're looking at
> the right profile folder:
[quoted text clipped - 24 lines]
>>>
>>> You're probably looking in the wrong profile folder.
Olof Lagerkvist - 03 Jul 2007 23:12 GMT
> The API call I use is:
> GetUserName()
> http://msdn2.microsoft.com/en-us/library/ms724432.aspx
>
> This is a recommended method by Microsoft to obtain the current user name.
That is the recommended way to get the current user name but NOT the
recommended way to get the current user profile path. Please note that
there is no guarantee that the the current user path is C:\Documents and
Settings\<current user name>, if for example the ntuser.dat in the user
profile is damaged in some way and cannot be loaded when the user logs
on the user will get a new profile with a new path. Same goes if there
is already another directory present with the name C:\Documents and
Settings\<current user name> when the user logs on for the first time.
Either do like "Pegasus" said, look at the
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\hivelist registry
key for loaded hive files or use the GetUserProfileDirectory() API.

Signature
Olof Lagerkvist
ICQ: 724451
Web: http://here.is/olof
Jack - 04 Jul 2007 02:58 GMT
Olof,
Thank you for the insight. I see I have not explained all
properly.
I do not use a hardcoded path.
What I do is:
In Windows registry I look up the path to 'Desktop'
HKEY_CURRENT_USER/"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell
Folders\"
From that key I extract path, then I add the current user name (returned
from API) and that is the way I create path to the ntuser.dat file.
What can be wrong with that approach?
Thanks,
Jack
>> The API call I use is:
>> GetUserName()
[quoted text clipped - 15 lines]
> HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\hivelist registry key
> for loaded hive files or use the GetUserProfileDirectory() API.
Olof Lagerkvist - 04 Jul 2007 13:23 GMT
> Olof,
> Thank you for the insight. I see I have not explained all
[quoted text clipped - 7 lines]
> from API) and that is the way I create path to the ntuser.dat file.
> What can be wrong with that approach?
Still the same problem. You are using the user name returned by
GetUserName() and may not necessarily be part of the path to the user's
profile.
Think about this situation:
You have a user 'user1' and log on that user. A profile 'C:\Documents
and Settings\user1' is created and the ntuser.dat is then 'C:\Documents
and Settings\user1\ntuser.dat'. Your technique will find the ntuser.dat
successfully because you get the path 'C:\Documents and
Settings\user1\Desktop' from the registry and the user name 'user1' from
GetUserName(), you extract 'C:\Documents and Settings' and then add
'\user1\ntuser.dat' and that will work.
Now, example 1:
Someone renames the user account 'user1' to 'user2'. The profile is
still 'C:\Documents and Settings\user1' but the GetUserName() function
will return 'user2' and your approach will no longer work.
Example 2:
Someone changes the location for the user's desktop from 'C:\Documents
and Settings\user1\Desktop' because he wants to share the desktop of
another user's profile and set it to 'C:\Documents and
Settings\anotheruser\Desktop'. Your method will find the wrong directory
in this case too.
Example 3:
Someone adds the computer to the domain 'domainname' and makes a domain
logon with a domain account that also has the name 'user1'. A new user
profile is created for this domain account 'C:\Documents and
Settings\user1.domainname'. GetUserName() will return just 'user1'...
etc...

Signature
Olof Lagerkvist
ICQ: 724451
Web: http://here.is/olof
Jack - 06 Jul 2007 07:17 GMT
Olof,
What is your opinion about using:
SHGetFolderPath() with CSIDL_PROFILE?
I appreciate your comments,
Jack
>> Olof,
>> Thank you for the insight. I see I have not explained all
[quoted text clipped - 41 lines]
>
> etc...
Olof Lagerkvist - 06 Jul 2007 14:09 GMT
> Olof,
> What is your opinion about using:
> SHGetFolderPath() with CSIDL_PROFILE?
> I appreciate your comments,
That should work (as long as you specify the SHGFP_TYPE_CURRENT flag),
or you can use GetUserProfileDirectory().
Either of them should return the same, currently correct, user profile path.

Signature
Olof Lagerkvist
ICQ: 724451
Web: http://here.is/olof
Jack - 06 Jul 2007 19:00 GMT
Thank you.
Jack
>> Olof,
>> What is your opinion about using:
[quoted text clipped - 6 lines]
> Either of them should return the same, currently correct, user profile
> path.
Jack - 03 Jul 2007 22:04 GMT
Also, by the exchanging emails with the user I confirmed that the user name
is correct.
There must be something else causing that.
Jack
> You should have a look here to make sure you're looking at
> the right profile folder:
[quoted text clipped - 24 lines]
>>>
>>> You're probably looking in the wrong profile folder.
Jack - 04 Jul 2007 04:01 GMT
I have tried that key.
On my computer the value is:
\Device\HarddiskVolume1\Documents and Settings\Jacek\ntuser.dat
How to translate that path to the generally accepted format?
Jack
> You should have a look here to make sure you're looking at
> the right profile folder:
[quoted text clipped - 24 lines]
>>>
>>> You're probably looking in the wrong profile folder.
Pegasus (MVP) - 04 Jul 2007 06:40 GMT
To remove any doubt about the location of this file, do this while
the user is logged on:
- Unhide it (this will work).
- Try to rename it to "ntuser.dat" (this won't work while the user is logged
on).
>I have tried that key.
> On my computer the value is:
[quoted text clipped - 32 lines]
>>>>
>>>> You're probably looking in the wrong profile folder.