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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Documents and Settings - how to get the directory

Status
Not open for further replies.

iwtc

Programmer
Aug 1, 2006
1
SE
Hi all,
I have a problem getting the directory name where to store user related files. Normally it is something like:

C:\Documents and Settings\[user_name]\Application Data\...

but on my computer it is

C:\Documents and Settings\[user_name].[computer_name]\Application Data\...

and I believe it could be even different. Do you anybody know about a function that retrieves current user's directory name? I have got Delphi 3...

Thanks, David
 
You need to use the API function SHGetFolderPath:

Code:
function SHGetFolderPath(hwndOwner : THandle;
                         nFolder   : integer;
                         hToken    : THandle;
                         dwFlags   : DWORD;
                         pszPath   : PChar) : HRESULT; stdcall;
                         external 'shell32.dll' name 'SHGetFolderPathA';

Usually you will use Flags = SHGFP_TYPE_CURRENT = 0.

The \C&S\<user>\ApplicationData is queried with nFolder = CSIDL_APPDATA .

Check the SDK for function results, other CSIDLs and OS compatibility.

buho (A).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top