问题可能很简单我尝试使用此代码:
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下使用这个应用程序。
答案 0 :(得分:4)
尝试使用GetUserProfileDirectory
代替SHGetFolderPath
。
示例(您需要在UserEnv.dll中绑定GetUserProfileDirectory):
if LogonUser(PChar(GuestUser), 0, 0, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, token) then
begin
SetLength(GuestDir, MAX_PATH);
ZeroMemory(@GuestDir[1], MAX_PATH);
if Succeeded(GetUserProfileDirectoryA(token, PChar(GuestDir), MAX_PATH)) then
ShowMessage(GuestDir);
end;