瀏覽代碼

Add HKA which equals HKLM in administrative install mode, HKCU otherwise. Supported by [Code] and [Registry]. Supports HKA32 and HKA64.

(todo: implement [Registry], update whatsnew, update examples)
Martijn Laan 7 年之前
父節點
當前提交
5d6ba5f6ff
共有 5 個文件被更改,包括 40 次插入19 次删除
  1. 13 9
      ISHelp/isetup.xml
  2. 1 1
      ISHelp/isxfunc.xml
  3. 6 0
      Projects/ScriptFunc_C.pas
  4. 17 8
      Projects/ScriptFunc_R.pas
  5. 3 1
      Projects/SetupTypes.pas

+ 13 - 9
ISHelp/isetup.xml

@@ -2328,11 +2328,9 @@ en.LanguageName=English
 
 <precode>
 [Registry]
-Root: HKCU; Subkey: "Software\My Company"; Flags: uninsdeletekeyifempty
-Root: HKCU; Subkey: "Software\My Company\My Program"; Flags: uninsdeletekey
-Root: HKLM; Subkey: "Software\My Company"; Flags: uninsdeletekeyifempty
-Root: HKLM; Subkey: "Software\My Company\My Program"; Flags: uninsdeletekey
-Root: HKLM; Subkey: "Software\My Company\My Program\Settings"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
+Root: HKA; Subkey: "Software\My Company"; Flags: uninsdeletekeyifempty
+Root: HKA; Subkey: "Software\My Company\My Program"; Flags: uninsdeletekey
+Root: HKA; Subkey: "Software\My Company\My Program\Settings"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
 </precode>
 
 <p>The following is a list of the supported <link topic="params">parameters</link>:</p>
@@ -2350,11 +2348,17 @@ Root: HKLM; Subkey: "Software\My Company\My Program\Settings"; ValueType: string
 <tr><td><tt>HKCC</tt></td><td>(HKEY_CURRENT_CONFIG)</td></tr>
 </table>
 </indent>
-<p>The values may have a suffix of <tt>32</tt> or <tt>64</tt>. Root key values with a suffix of <tt>32</tt> (for example, <tt>HKLM32</tt>) map to the 32-bit view of the registry; root key values with a suffix of <tt>64</tt> (for example, <tt>HKLM64</tt>) map to the 64-bit view of the registry.</p>
+<p>Additionally one special value is allowed:</p>
+<indent>
+<table>
+<tr><td><tt>HKA</tt></td><td>(equals HKLM in <link topic="admininstallmode">administrative install mode</link>, HKCU otherwise)</td></tr>
+</table>
+</indent>
+<p>The values (including <tt>HKA</tt>) may have a suffix of <tt>32</tt> or <tt>64</tt>. Root key values with a suffix of <tt>32</tt> (for example, <tt>HKLM32</tt>) map to the 32-bit view of the registry; root key values with a suffix of <tt>64</tt> (for example, <tt>HKLM64</tt>) map to the 64-bit view of the registry.</p>
 <p>Root key values with a suffix of <tt>64</tt> can only be used when Setup is running on 64-bit Windows, otherwise an error will occur. On an installation supporting both 32- and 64-bit architectures, it is possible to avoid the error by adding a <tt>Check: IsWin64</tt> parameter, which will cause the entry to be silently skipped when running on 32-bit Windows.</p>
 <p>A root key value without a suffix (for example, <tt>HKLM</tt>) is equivalent to the value with a suffix of <tt>32</tt> (for example, <tt>HKLM32</tt>) unless the install is running in <link topic="32vs64bitinstalls">64-bit install mode</link>, in which case it is equivalent to the value with a suffix of <tt>64</tt> (for example, <tt>HKLM64</tt>).</p>
 <example>
-<pre>Root: HKCU</pre>
+<pre>Root: HKA</pre>
 </example>
 </param>
 
@@ -2929,14 +2933,14 @@ Filename: "{win}\MYPROG.INI"; Section: "InstallSettings"; Key: "InstallPath"; St
 <ul>
 <li>The <tt>{group}</tt> folder is created in the <i>All Users</i> profile.</li>
 <li>The "auto" form of the directory and Shell Folder constants is mapped to the "common" form.</li>
-<li>The uninstall info root key will be HKEY_LOCAL_MACHINE.</li>
+<li>The <link topic="registrysection">HKA</link> and uninstall info root keys will be HKEY_LOCAL_MACHINE.</li>
 </ul>
 
 <p>In non administrative install mode:</p>
 <ul>
 <li>The <tt>{group}</tt> folder is created in the current user's profile.</li>
 <li>The "auto" form of the directory and Shell Folder constants is mapped to the "user" form.</li>
-<li>The uninstall info root key will be HKEY_CURRENT_USER.</li>
+<li>The <link topic="registrysection">HKA</link> and uninstall info root keys will be HKEY_CURRENT_USER.</li>
 </ul>
 
 <p><b>Notes:</b></p>

+ 1 - 1
ISHelp/isxfunc.xml

@@ -2584,7 +2584,7 @@ end;</pre></example>
   </enum>
   <enum>
      <description>Reg* - RootKey values (also see the <link topic="registrysection" window="main">[Registry]</link> section documentation)</description>
-     <values>HKEY_CLASSES_ROOT, HKEY_CLASSES_ROOT_32, HKEY_CLASSES_ROOT_64,<br />HKEY_CURRENT_USER, HKEY_CURRENT_USER_32, HKEY_CURRENT_USER_64,<br />HKEY_LOCAL_MACHINE, HKEY_LOCAL_MACHINE_32, HKEY_LOCAL_MACHINE_64,<br />HKEY_USERS, HKEY_USERS_32, HKEY_USERS_64,<br />HKEY_PERFORMANCE_DATA,<br />HKEY_CURRENT_CONFIG, HKEY_CURRENT_CONFIG_32, HKEY_CURRENT_CONFIG_64,<br />HKEY_DYN_DATA,<br />HKCR, HKCR32, HKCR64, HKCU, HKCU32, HKCU64, HKLM, HKLM32, HKLM64, HKU, HKU32, HKU64, HKCC, HKCC32, HKCC64</values>
+     <values>HKEY_AUTO, HKEY_AUTO_32, HKEY_AUTO_64,<br />HKEY_CLASSES_ROOT, HKEY_CLASSES_ROOT_32, HKEY_CLASSES_ROOT_64,<br />HKEY_CURRENT_USER, HKEY_CURRENT_USER_32, HKEY_CURRENT_USER_64,<br />HKEY_LOCAL_MACHINE, HKEY_LOCAL_MACHINE_32, HKEY_LOCAL_MACHINE_64,<br />HKEY_USERS, HKEY_USERS_32, HKEY_USERS_64,<br />HKEY_PERFORMANCE_DATA,<br />HKEY_CURRENT_CONFIG, HKEY_CURRENT_CONFIG_32, HKEY_CURRENT_CONFIG_64,<br />HKEY_DYN_DATA,<br />HKA, HKA32, HKA64, HKCR, HKCR32, HKCR64, HKCU, HKCU32, HKCU64, HKLM, HKLM32, HKLM64, HKU, HKU32, HKU64, HKCC, HKCC32, HKCC64</values>
   </enum>
   <enum>
      <description>TShouldProcessEntryResult</description>

+ 6 - 0
Projects/ScriptFunc_C.pas

@@ -199,6 +199,9 @@ begin
 
   RegisterConst('HWND_BROADCAST', HWND_BROADCAST);
 
+  RegisterConst('HKEY_AUTO', LongInt(HKEY_AUTO));
+  RegisterConst('HKEY_AUTO_32', LongInt(HKEY_AUTO or CodeRootKeyFlag32Bit));
+  RegisterConst('HKEY_AUTO_64', LongInt(HKEY_AUTO or CodeRootKeyFlag64Bit));
   RegisterConst('HKEY_CLASSES_ROOT', LongInt(HKEY_CLASSES_ROOT));
   RegisterConst('HKEY_CLASSES_ROOT_32', LongInt(HKEY_CLASSES_ROOT or CodeRootKeyFlag32Bit));
   RegisterConst('HKEY_CLASSES_ROOT_64', LongInt(HKEY_CLASSES_ROOT or CodeRootKeyFlag64Bit));
@@ -217,6 +220,9 @@ begin
   RegisterConst('HKEY_CURRENT_CONFIG_64', LongInt(HKEY_CURRENT_CONFIG or CodeRootKeyFlag64Bit));
   RegisterConst('HKEY_DYN_DATA', LongInt(HKEY_DYN_DATA));
 
+  RegisterConst('HKA', LongInt(HKEY_AUTO));
+  RegisterConst('HKA32', LongInt(HKEY_AUTO or CodeRootKeyFlag32Bit));
+  RegisterConst('HKA64', LongInt(HKEY_AUTO or CodeRootKeyFlag64Bit));
   RegisterConst('HKCR', LongInt(HKEY_CLASSES_ROOT));
   RegisterConst('HKCR32', LongInt(HKEY_CLASSES_ROOT or CodeRootKeyFlag32Bit));
   RegisterConst('HKCR64', LongInt(HKEY_CLASSES_ROOT or CodeRootKeyFlag64Bit));

+ 17 - 8
Projects/ScriptFunc_R.pas

@@ -387,16 +387,25 @@ end;
 { CmnFunc2 }
 function CmnFunc2Proc(Caller: TPSExec; Proc: TPSExternalProcRec; Global, Stack: TPSStack): Boolean;
 
-  procedure CrackCodeRootKey(const CodeRootKey: Longint; var RegView: TRegView;
+  procedure CrackCodeRootKey(CodeRootKey: Longint; var RegView: TRegView;
     var RootKey: HKEY);
   begin
-    { Allow only predefined key handles (8xxxxxxx). Can't accept handles to
-      open keys because they might have our special flag bits set.
-      Also reject unknown flags which may have a meaning in the future. }
-    if (CodeRootKey shr 31 <> 1) or
-       ((CodeRootKey and CodeRootKeyFlagMask) and not CodeRootKeyValidFlags <> 0) then
-      InternalError('Invalid RootKey value');
-
+    if (CodeRootKey and not CodeRootKeyValidFlags) = HKEY_AUTO then begin
+      { Change HKA to HKLM or HKCU, keeping our special flag bits. }
+      CodeRootKey := CodeRootKey and CodeRootKeyValidFlags;
+      if IsAdminInstallMode then
+        CodeRootKey := CodeRootKey or HKEY_LOCAL_MACHINE
+      else
+        CodeRootKey := CodeRootKey or HKEY_CURRENT_USER;
+    end else begin
+      { Allow only predefined key handles (8xxxxxxx). Can't accept handles to
+        open keys because they might have our special flag bits set.
+        Also reject unknown flags which may have a meaning in the future. }
+      if (CodeRootKey shr 31 <> 1) or
+         ((CodeRootKey and CodeRootKeyFlagMask) and not CodeRootKeyValidFlags <> 0) then
+        InternalError('Invalid RootKey value');
+    end;
+    
     if CodeRootKey and CodeRootKeyFlag32Bit <> 0 then
       RegView := rv32Bit
     else if CodeRootKey and CodeRootKeyFlag64Bit <> 0 then begin

+ 3 - 1
Projects/SetupTypes.pas

@@ -45,12 +45,14 @@ type
 
 const
   crHand = 1;
-
+  
   CodeRootKeyFlagMask  = $7F000000;
   CodeRootKeyFlag32Bit = $01000000;
   CodeRootKeyFlag64Bit = $02000000;
   CodeRootKeyValidFlags = CodeRootKeyFlag32Bit or CodeRootKeyFlag64Bit;
 
+  HKEY_AUTO = 0; { Any value will work as long as it doesn't match a predefined key handle (8xxxxxxx) nor includes any of the CodeRootKeyValidFlags flags. }
+
 function StringsToCommaString(const Strings: TStrings): String;
 procedure SetStringsFromCommaString(const Strings: TStrings; const Value: String);
 function StrToVersionNumbers(const S: String; var VerData: TSetupVersionData): Boolean;