Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get User's Home Directory

Status
Not open for further replies.

abp

Programmer
Sep 14, 2000
134
FR

Hi,

How do I get a the current user's home directory
within a program, on Windows2000. The following code
which works on NT fails in Windows2000 which uses
Active Directory to retrieve directory information...
It returns the HOMEDRIVE instead of HOME.

Any help in this is welcome.
Here is the code.

Thanks

Anand

#define MAXSTR 1024
define RET_STRING_SIZE 256

get_nt_user_home(char* user_home)
{
int size=MAXSTR;
WCHAR wuser_name[MAXSTR];
USER_INFO_1 *user_info;

if( GetUserName( user_name, &size ) )
{
MultiByteToWideChar( CP_ACP, 0, user_name, size,
wuser_name, sizeof(wuser_name ) );
{
status = NetUserGetInfo( NULL,
wuser_name, 1,
(LPBYTE *)&user_info);

if( status == NERR_Success )
{
WideCharToMultiByte( CP_ACP, 0,
user_info->usri1_home_dir, wcslen( user_info->usri1_home_dir, user_home, RET_STRING_SIZE, "\0", NULL );
}
}
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mail me at abpillai@excite.com if you want additional help. I dont promise that I can solve your problem, but I will try my best.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Look up the api for:
[tab]SHGetSpecialFolderPath

It needs v4.71 or later of shell32.dll

Chip H.
 
Hi

Thanks for the reply. But the function should
work across the LAN. Isnt there any *Net* function
that would do the work ?

Anand ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mail me at abpillai@excite.com if you want additional help. I dont promise that I can solve your problem, but I will try my best.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top