How do you get there home directory

How do you detect a users home directory in windows? By home directory I mean ("C:/Users/*This*RandomName*This*/
anybody?
Please refrain from double posting, it's kinda frowned upon here. I dont know of any solution, but the people in the windows programming bbs on this site might be better suited to reply.
ok sorry
Use SHGetFolderLocation()
http://www.google.com/search?btnI=1&q=msdn+SHGetFolderLocation
with an nFolder argument of CSIDL_PROFILE.

Be aware that you should not generally be creating files there. Rather, your application should store stuff at the folder returned by CSIDL_LOCAL_APPDATA.

Be sure to read up on the available CSIDL values.

Hope this helps.
can you show me an example using it? Thanks
I should have directed you to a simpler function. Sorry... Use SHGetFolderPath():

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
using namespace std;

#include <windows.h>
#include <shlobj.h>

int main()
  {
  char path[ MAX_PATH ];
  if (SHGetFolderPathA( NULL, CSIDL_PROFILE, NULL, 0, path ) != S_OK)
    {
    cout << "I could not retrieve the user's home directory!\n";
    }
  else
    {
    cout << "Home directory = \"" << path << "\"\n";
    }

  if (SHGetFolderPathA( NULL, CSIDL_LOCAL_APPDATA, NULL, 0, path ) != S_OK)
    {
    cout << "I could not retrieve the user's application data directory!\n";
    }
  else
    {
    cout << "Application data directory = \"" << path << "\"\n";
    }

  return 0;
  }

Hope this helps.
thanks that helped
Topic archived. No new replies allowed.