@@ -5,6 +5,10 @@
55// Author: Jared Breland <jbreland@legroom.net>
66// Homepage: http://www.legroom.net/software
77//
8+// Modified 10/18/2008 by John MacFarlane to set path in HKCU instead of HKLM if
9+// user does not have admin privileges. Also correctly handle the case where
10+// oldpath is empty.
11+//
812// Script Function:
913// Enable modification of system path directly from Inno Setup installers
1014//
@@ -41,6 +45,8 @@ var
4145 aExecArr: TArrayOfString;
4246 i, d: Integer;
4347 pathdir: TArrayOfString;
48+ reg: Integer;
49+ regkey: String;
4450begin
4551
4652 // Get array of new directories and act on each individually
@@ -50,8 +56,17 @@ begin
5056 // Modify WinNT path
5157 if UsingWinNT() = true then begin
5258
59+ // Select HKLM or HKCU depending on whether user has admin privileges
60+ if (IsAdminLoggedOn or IsPowerUserLoggedOn) then begin
61+ reg := HKEY_LOCAL_MACHINE;
62+ regkey := 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
63+ end else begin
64+ reg := HKEY_CURRENT_USER;
65+ regkey := 'Environment';
66+ end;
67+
5368 // Get current path, split into an array
54− RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', oldpath);
69+ RegQueryStringValue(reg, regkey, 'Path', oldpath);
5570 oldpath := oldpath + ';';
5671 i := 0;
5772 while (Pos(';', oldpath) > 0) do begin
@@ -80,11 +95,16 @@ begin
8095 end;
8196
8297 // Append app dir to path if not already included
83− if IsUninstaller() = false then
84− newpath := newpath + ';' + pathdir[d];
98+ if IsUninstaller() = false then begin
99+ if newpath = '' then begin
100+ newpath := pathdir[d];
101+ end else begin
102+ newpath := newpath + ';' + pathdir[d];
103+ end;
104+ end;
85105
86106 // Write new path
87− RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', newpath);
107+ RegWriteStringValue(reg, regkey, 'Path', newpath);
88108
89109 // Modify Win9x path
90110 end else begin
@@ -155,3 +175,4 @@ begin
155175 Result := False;
156176 end;
157177end;
178+