From 1aed6a9ee48698d43ce02d4a615be25b5c4dbed6 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sat, 18 Oct 2008 18:48:23 +0000 Subject: Modified modpath.iss to modify HKCU path if user lacks admin privileges. Also fixed case where oldpath is empty (previously this led to the new path beginning with a semicolon). git-svn-id: https://pandoc.googlecode.com/svn/trunk@1464 788f1e2b-df1e-0410-8736-df70ead52e1b --- windows/modpath.iss | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) (limited to 'windows/modpath.iss') diff --git a/windows/modpath.iss b/windows/modpath.iss index ea3cef8e8..73ae434ac 100644 --- a/windows/modpath.iss +++ b/windows/modpath.iss @@ -5,6 +5,10 @@ // Author: Jared Breland // Homepage: http://www.legroom.net/software // +// Modified 10/18/2008 by John MacFarlane to set path in HKCU instead of HKLM if +// user does not have admin privileges. Also correctly handle the case where +// oldpath is empty. +// // Script Function: // Enable modification of system path directly from Inno Setup installers // @@ -41,6 +45,8 @@ var aExecArr: TArrayOfString; i, d: Integer; pathdir: TArrayOfString; + reg: Integer; + regkey: String; begin // Get array of new directories and act on each individually @@ -50,8 +56,17 @@ begin // Modify WinNT path if UsingWinNT() = true then begin + // Select HKLM or HKCU depending on whether user has admin privileges + if (IsAdminLoggedOn or IsPowerUserLoggedOn) then begin + reg := HKEY_LOCAL_MACHINE; + regkey := 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'; + end else begin + reg := HKEY_CURRENT_USER; + regkey := 'Environment'; + end; + // Get current path, split into an array - RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', oldpath); + RegQueryStringValue(reg, regkey, 'Path', oldpath); oldpath := oldpath + ';'; i := 0; while (Pos(';', oldpath) > 0) do begin @@ -80,11 +95,16 @@ begin end; // Append app dir to path if not already included - if IsUninstaller() = false then - newpath := newpath + ';' + pathdir[d]; + if IsUninstaller() = false then begin + if newpath = '' then begin + newpath := pathdir[d]; + end else begin + newpath := newpath + ';' + pathdir[d]; + end; + end; // Write new path - RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 'Path', newpath); + RegWriteStringValue(reg, regkey, 'Path', newpath); // Modify Win9x path end else begin @@ -155,3 +175,4 @@ begin Result := False; end; end; + -- cgit v1.2.3