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 strongm 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 3

Status
Not open for further replies.

michaenh

Programmer
Aug 7, 2002
205
NO
Hi everyone.

Are there any simple code to retrieve the users documents and settings path? Without reading the key from the Microsoft registry?

Are there any simple code to get the %USERPROFILE% ??

Many thanks

Michael
 
I don't know of any other means of getting the docs and settings path.
As to the %USERPROFILE% env var you can use the code below as a starting point:

SetLength(sVarValue,255);
GetEnvironmentVariable('USERPROFILE',PChar(sVarValue),255);
SetLength(sVarValue,StrLen(PChar(sVarValue)));

Note: tested only in Win2k.

HTH,
Porteiro

 
Thanks porteiro.

You gave me a start.. I will try it out soon.. many thanks once more.

michael
 
Hi porteiro.

It is just what I have looking for... smile..
A star for you.

I will try if it work in other OS too, soon.

Michael
 
GetEnvironmentVariable('USERPROFILE',PChar(sVarValue),255);
doesn't work with Win98..

Well.. well.. I had to read from registry.. if anyone have other solution it would be nice.

Michael
 
Michael,

I've just checked it and the Win9x family of OSs doesn't set the USERPROFILE environmental variable, and for this reason the code snippet I sent you doesn't work.

You must check the OS running and take the proper path then.

Porteiro
 
Maybe this will help?
Code:
uses ... ShlObj....
....

function GetMyDocumentsPath():String;
var
  APath      : pChar;
begin
  GetMem(APath, MAX_PATH + 1);
  SHGetSpecialFolderPath(Application.Handle, APath, CSIDL_PERSONAL, False);
  SetString(Result, APath, lstrlen(APath));
  Result:= Trim(Result);
  FreeMem(APath);
end;
HTH

--- markus
 
Hi thanks McMerfy!

It worked... real nice job guys.. thanks for million helps by everyone each day.

I am getting smarter for each day because of you all.. :)

Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top