Title: Windows, System, Application & Temp directories. User ID & Computer ID.
Question: How to retrieve system directories and user information at runtime.
Answer:
// This function returns the Windows Directory
function WinDir: String;
var
WinD : PChar;
begin
GetMem(WinD, 144);
GetWindowsDirectory(WinD, 144);
Result:= String(WinD);
FreeMem(WinD, 144);
end;
// This function returns the Windows\System Directory
function SysDir: String;
var
SysD : PChar;
begin
GetMem(SysD, 144);
GetSystemDirectory(SysD, 144);
Result:= String(SysD);
FreeMem(SysD, 144);
end;
// This function returns the directory of the currently running application
function AppDir: String;
begin
Result:= ExtractFilePath(ParamStr(0));
Result:= Copy(Result,1,Length(Result)-1);
end;
// This function returns the directory of the currently running application
function TempDir: String;
var
TmpD : PChar;
begin
GetMem(TmpD, 144);
GetTempPath(144, TmpD);
Result:=String(TmpD);
FreeMem(TmpD, 144);
Result:=Copy(Result,1,Length(Result)-1);
end;
// This function returns the current UserID
function UserID: String;
var
UID : PChar;
USize : DWord;
begin
GetMem(UID, 40);
USize:=40;
GetUserName(UID, USize);
Result:= String(UID);
FreeMem(UID, 40);
end;
// This function returns the current Computer ID
function ComputerID: String;
var
CID : PChar;
CSize : DWord;
begin
GetMem(CID, 100);
CSize:=100;
GetComputerName(CID, CSize);
Result:= String(CID);
FreeMem(CID, 100);
end;