1 // ----------------------------------------------------------------------------
3 // Inno Setup Ver
: 5.2.1
4 // Script Version
: 1.3.1
5 // Author
: Jared Breland
<jbreland
@legroom
.net
>
6 // Homepage
: http
://www
.legroom
.net
/software
7 // Modified by
: Sebastian Schuberth
<sschuberth
@gmail
.com
>
10 // Enable modification
of system path directly from Inno Setup installers
13 // Copy modpath
.iss
to the same directory
as your setup script
15 // Add this statement
to your
[Setup
] section
16 // ChangesEnvironment
=yes
18 // Add this statement
to your
[Tasks
] section
19 // You can change the Description
or Flags
, but the Name must be modifypath
20 // Name
: modifypath
; Description
: &Add application directory
to your
system path
; Flags
: unchecked
22 // Add the following
to the
end of your
[Code
] section
23 // setArrayLength must specify the total number
of dirs
to be added
24 // Dir
[0] contains first directory
, Dir
[1] contains second
, etc
.
25 // function ModPathDir(): TArrayOfString
;
27 // Dir
: TArrayOfString
;
29 // setArrayLength(Dir
, 1)
30 // Dir
[0] := ExpandConstant('{app}');
33 // #include
"modpath.iss"
34 // ----------------------------------------------------------------------------
40 pathArr
: TArrayOfString
;
42 aExecArr
: TArrayOfString
;
44 pathdir
: TArrayOfString
;
46 // Get
array of new directories
and act on each individually
47 pathdir
:= ModPathDir();
48 for d
:= 0 to GetArrayLength(pathdir
)-1 do begin
51 if UsingWinNT() = true then begin
53 // Get current path
, split into an
array
54 RegQueryStringValue(HKEY_CURRENT_USER
, 'Environment', 'Path', oldpath
);
55 oldpath
:= oldpath
+ ';';
57 while (Pos(';', oldpath
) > 0) do begin
58 SetArrayLength(pathArr
, i
+1);
59 pathArr
[i
] := Copy(oldpath
, 0, Pos(';', oldpath
)-1);
60 oldpath
:= Copy(oldpath
, Pos(';', oldpath
)+1, Length(oldpath
));
63 // Check
if current directory matches app dir
64 if pathdir
[d
] = pathArr
[i
-1] then begin
65 // if uninstalling
, remove dir from path
66 if IsUninstaller() = true then begin
68 // if installing
, abort because dir was already
in path
74 // Add current directory
to new path
76 newpath
:= pathArr
[i
-1];
78 newpath
:= newpath
+ ';' + pathArr
[i
-1];
82 // Append app dir
to path
if not already included
83 if IsUninstaller() = false then
84 newpath
:= newpath
+ ';' + pathdir
[d
];
87 RegWriteStringValue(HKEY_CURRENT_USER
, 'Environment', 'Path', newpath
);
92 // Convert
to shortened dirname
93 pathdir
[d
] := GetShortName(pathdir
[d
]);
95 // If autoexec
.bat exists
, check
if app dir already exists
in path
96 aExecFile
:= 'C:\AUTOEXEC.BAT';
97 if FileExists(aExecFile
) then begin
98 LoadStringsFromFile(aExecFile
, aExecArr
);
99 for i
:= 0 to GetArrayLength(aExecArr
)-1 do begin
100 if IsUninstaller() = false then begin
101 // If app dir already exists
while installing
, abort add
102 if (Pos(pathdir
[d
], aExecArr
[i
]) > 0) then
105 // If app dir exists
and = what we originally
set, then delete at uninstall
106 if aExecArr
[i
] = 'SET PATH=%PATH%;' + pathdir
[d
] then
112 // If app dir
not found
, or autoexec
.bat didn
't exist, then (create and) append to current path
113 if IsUninstaller() = false then begin
114 SaveStringToFile(aExecFile, #13#10 + 'SET PATH
=%PATH
%;' + pathdir[d], True);
116 // If uninstalling, write the full autoexec out
118 SaveStringsToFile(aExecFile, aExecArr, False);
122 // Write file to flag modifypath was selected
123 // Workaround since IsTaskSelected() cannot be called at uninstall and AppName and AppId cannot be "read" in Code section
124 if IsUninstaller() = false then
125 SaveStringToFile(ExpandConstant('{app}') + '\uninsTasks
.txt
', WizardSelectedTasks(False), False);
129 procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
132 selectedTasks: String;
134 appdir := ExpandConstant('{app}')
135 if CurUninstallStep = usUninstall then begin
136 if LoadStringFromFile(appdir + '\uninsTasks
.txt
', selectedTasks) then
137 if Pos('modifypath
', selectedTasks) > 0 then
139 DeleteFile(appdir + '\uninsTasks
.txt
')
143 function NeedRestart(): Boolean;
145 if IsTaskSelected('modifypath
') and not UsingWinNT() then begin