常用Shell的路径

#define REG_SHELL "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
#define REG_SHELL "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders"

里面很多很多值,仔细观察

[HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders]
[HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerUser Shell Folders]
[HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders]
[HKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionExplorerUser Shell Folders]
[HKEY_LOCAL_MACHINESoftwareWow6432NodeMicrosoftWindowsCurrentVersionexplorerShell Folders]
[HKEY_LOCAL_MACHINESoftwareWow6432NodeMicrosoftWindowsCurrentVersionexplorerUser Shell Folders]

GetDefaultUserProfileDirectory
GetUserProfileDirectory
例子:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682431(v=vs.85).aspx

Roaming User Profiles
https://msdn.microsoft.com/en-us/library/windows/desktop/bb776897(v=vs.85).aspx

另外还有:

SHGetFolderPath 取CSIDL_APPDATA路径,就是
https://msdn.microsoft.com/en-us/library/windows/desktop/bb762181(v=vs.85).aspx

USERPROFILE := GetEnvironmentVariable('USERPROFILE');

function TDM.CreateBeyskyDirectories:
  string;

begin
  Result := FalseStr;
  try
    if not DirectoryExists(USERPROFILE + 'AppDataRoamingmypath', False) then
      if not forcedirectories(USERPROFILE + 'AppDataRoamingmypath') then Exit;
    Result := TrueStr;
  except
    on E: Exception do Result := E.Message;
  end;
end;

或者

    你可以通过读取注册表来实现这一功能。我这之前写的一个项目里面用到了,代码如下:
function TLoginWindow.ReadReg: string; // 读取reg,获得文件夹路径
var
  myreg: TRegistry;
const
  RegDir: string = 'SoftwareMicrosoftWindowsCurrentVersionExplorerShell Folders';
begin
  myreg := TRegistry.Create;
  myreg.RootKey := HKEY_CURRENT_USER;
  myreg.OpenKey(RegDir, False);
  Result := myreg.ReadString('AppData');
  myreg.Free;
end;

http://bbs.2ccc.com/topic.asp?topicid=517558

原文地址:https://www.cnblogs.com/findumars/p/6002094.html