从注册表中读取路径后添加另一个目标

时间:2015-09-03 08:12:42

标签: inno-setup

如何在从注册表中读取的路径后面添加两个子文件夹?

[Code]
function GetDirName(Value: string): string;
var          
  InstallPath: string;
begin
  Result := 'C:\Program Files (x86)\myapp\subfolder1\subfolder2';

  if RegQueryStringValue(HKLM, 'SOFTWARE\Wow6432Node\myapp', 'RootPath', InstallPath) then
    Result := InstallPath
  else
  // query the second registry value; if it succeeds, return the obtained value
  if RegQueryStringValue(HKLM, '\SOFTWARE\myapp', 'RootPath', InstallPath) then
    Result := InstallPath;
end;

当我从注册表中获得目的地时,我需要在其后面添加\subfolder1\subfolder2并完成目标设置GetDirName

有人可以指导我吗?

非常感谢。

1 个答案:

答案 0 :(得分:1)

只需连接GetDirName函数末尾的两个字符串:

function GetDirName(Value: string): string;
var          
  InstallPath: string;
begin
  // expand path to the 32-bit Program Files folder with appended 'myapp' subfolder
  Result := ExpandConstant('{pf32}\myapp');

     // query value from 64-bit registry node (notice the used HKLM64 root key)
  if RegQueryStringValue(HKLM64, 'SOFTWARE\myapp', 'RootPath', InstallPath) or
     // query value from 32-bit registry node (notice the used HKLM32 root key)
     RegQueryStringValue(HKLM32, 'SOFTWARE\myapp', 'RootPath', InstallPath) then
  begin
    Result := InstallPath;
  end;

  // ensure the path will have backslash and append the final subdirectory string
  Result := AddBackslash(Result) + 'subfolder1\subfolder2';
end;