Bicho, me ganaste por segundos
Código Delphi
[-]
const
CSIDL_PROFILE = 40;
SHGFP_TYPE_CURRENT = 0;
function SHGetFolderPath(hwndOwner: HWND;
nFolder: Integer;
hToken: THandle;
dwFlags: DWORD;
pszPath: LPTSTR): HRESULT; stdcall;
external 'Shell32.dll' name 'SHGetFolderPathA';
function GetUserProfile: string;
var
Buffer: array[0..MAX_PATH] of Char;
begin
FillChar(Buffer, SizeOf(Buffer), 0);
SHGetFolderPath(0, CSIDL_PROFILE, 0, SHGFP_TYPE_CURRENT, Buffer);
Result := String(PChar(@Buffer));
end;