繁体   English   中英

如何使用Delphi查找Windows用户(不是当前用户)的Profile Dir?

[英]How do I find a Profile Dir of a Windows User (not the current user) using Delphi?

问题可能很简单我尝试使用此代码:

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下使用此应用程序。

尝试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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM