常用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_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders]
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders]
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders]
[HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\explorer\Shell Folders]
[HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\explorer\User 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 + '\AppData\Roaming\mypath', False) then
      if not forcedirectories(USERPROFILE + '\AppData\Roaming\mypath') 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 = '\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell 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

 

posted @ 2016-10-26 22:02  findumars  Views(1578)  Comments(0)    收藏  举报