windows 当值仅使用默认名称时,如何在 Inno Setup 中获取注册表值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/913938/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 06:25:19  来源:igfitidea点击:

How do I get a registry value in Inno Setup when the value only uses the default name?

windowsregistryinno-setuppascal

提问by kraryal

I'm trying to get the install directory of an application from the Windows Registry (Google Sketchup in this case) with Inno Setup's Pascal scripting so I can install a plugin there.

我正在尝试使用 Inno Setup 的 Pascal 脚本从 Windows 注册表(在本例中为 Google Sketchup)获取应用程序的安装目录,以便我可以在那里安装插件。

The registry key doesn't have a name, it just has "(Default)" in Regedit.

注册表项没有名称,它在 Regedit 中只有“(默认)”。

I tried this:

我试过这个:

RegQueryStringValue( HKLM, 'SOFTWARE\Google\Google Sketchup 6', '(Default)', pluginLoc );

but it doesn't return a value. Any suggestions?

但它不返回值。有什么建议?

回答by mghie

Just leave the SubKeyNameempty, like so:

只留下SubKeyName空的,像这样:

[Code]
function InitializeSetup(): Boolean;
var
  V: string;
begin
  if RegQueryStringValue(HKLM, 'SOFTWARE\Google\Google Sketchup 6', '', V) then
    MsgBox('Value is "' + V + '"', mbInformation, MB_OK);
  Result := TRUE;
end;

The matching documentation for the underlying API call is for RegQueryValueEx(), which states:

底层 API 调用的匹配文档适用于RegQueryValueEx(),其中指出:

The name of the registry value.

If lpValueName is NULL or an empty string, "", the function retrieves the type and data for the key's unnamed or default value, if any.

注册表值的名称。

如果 lpValueName 为 NULL 或空字符串 "",则该函数检索键的未命名或默认值的类型和数据(如果有)。