質問は、私がこのコードで試していたほど簡単かもしれません:
var
lpProfileDir : tChar;
lpProfileSize : Cardinal;
token : tHandle;
GuestDir,GuestUser : String;
begin
GuestUser:=RadioGroup1.Items[RadioGroup1.ItemIndex];
if LogonUser(PChar(GuestUser), nil, nil, LOGON32_LOGON_SERVICE, LOGON32_PROVIDER_DEFAULT, token) then
begin
SetLength(GuestDir, MAX_PATH);
ZeroMemory(@GuestDir[1], MAX_PATH);
lpProfileSize:=MAX_PATH;
if GetUserProfileDirectoryA(token, PChar(GuestDir), lpProfileSize) then
begin
ShowMessage(GuestDir);
...
これで、現在のユーザーのプロファイル ディレクトリが返されます。このアプリを Windows XP/Vista/7/8 で使用したいと考えています。