1 // Copies a NULL
-terminated
array of characters
to a
string.
2 function ArrayToString(Chars
:array of Char):String;
6 Len
:=GetArrayLength(Chars
);
10 while (i
<Len
) and (Chars
[i
]<>#
0) do begin
11 Result
[i
+1]:=Chars
[i
];
18 // Copies a
string to a NULL
-terminated
array of characters
.
19 function StringToArray(Str
:String):array of Char;
24 SetArrayLength(Result
,Len
+1);
35 // Returns the path
to the common
or user shell folder
as specified
in "Param".
36 function GetShellFolder(Param
:string):string;
38 if IsAdminLoggedOn
then begin
39 Param
:='{common'+Param
+'}';
41 Param
:='{user'+Param
+'}';
43 Result
:=ExpandConstant(Param
);
46 // Returns the
value(s
) of the environment variable
"VarName", which
is tokenized
47 // by
";" into an
array of strings
. This makes it easy query PATH
-like variables
48 // in addition
to normal variables
. If "AllUsers" is true, the common variables
49 // are searched
, else the user
-specific ones
.
50 function GetEnvStrings(VarName
:string;AllUsers
:Boolean):TArrayOfString
;
58 // See http
://www
.jrsoftware
.org
/isfaq
.php#env
59 if AllUsers
then begin
60 // We ignore errors here
. The resulting
array of strings will be empty
.
61 RegQueryStringValue(HKEY_LOCAL_MACHINE
,'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',VarName
,Path
);
63 // We ignore errors here
. The resulting
array of strings will be empty
.
64 RegQueryStringValue(HKEY_CURRENT_USER
,'Environment',VarName
,Path
);
67 // Fallback
for built
-in variables which are
not stored
in the Registry
.
68 if Length(Path
)=0 then begin
69 Path
:=ExpandConstant('{%'+VarName
+'}');
72 // Make sure we have at least one semicolon
.
75 // Split the directories
in PATH into an
array of strings
.
77 SetArrayLength(Result
,0);
81 SetArrayLength(Result
,i
+1);
83 Result
[i
]:=Copy(Path
,1,p
-1);
86 Path
:=Copy(Path
,p
+1,Length(Path
));
91 // Sets the contents
of the specified environment variable
for the current process
.
92 function SetEnvironmentVariable(lpName
,lpValue
:String):Boolean;
94 external 'SetEnvironmentVariableW@Kernel32.dll stdcall delayload setuponly';
96 external 'SetEnvironmentVariableA@Kernel32.dll stdcall delayload setuponly';
99 // Sets the environment variable
"VarName" to the concatenation
of "DirStrings"
100 // using
";" as the delimiter
. If "AllUsers" is true, a common variable
is set,
101 // else a user
-specific one
. If "DeleteIfEmpty" is true and "DirStrings" is
102 // empty
, "VarName" is deleted instead
of set if it exists
.
103 function SetEnvStrings(VarName
:string;AllUsers
,DeleteIfEmpty
:Boolean;DirStrings
:TArrayOfString
):Boolean;
108 // Merge all non
-empty directory strings into a PATH variable
.
110 for i
:=0 to GetArrayLength(DirStrings
)-1 do begin
111 if Length(DirStrings
[i
])>0 then begin
112 if Length(Path
)>0 then begin
113 Path
:=Path
+';'+DirStrings
[i
];
120 // See http
://www
.jrsoftware
.org
/isfaq
.php#env
121 if AllUsers
then begin
122 KeyName
:='SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
123 if DeleteIfEmpty
and (Length(Path
)=0) then begin
124 Result
:=(not RegValueExists(HKEY_LOCAL_MACHINE
,KeyName
,VarName
)) or
125 RegDeleteValue(HKEY_LOCAL_MACHINE
,KeyName
,VarName
);
127 Result
:=RegWriteStringValue(HKEY_LOCAL_MACHINE
,KeyName
,VarName
,Path
);
130 KeyName
:='Environment';
131 if DeleteIfEmpty
and (Length(Path
)=0) then begin
132 Result
:=(not RegValueExists(HKEY_CURRENT_USER
,KeyName
,VarName
)) or
133 RegDeleteValue(HKEY_CURRENT_USER
,KeyName
,VarName
);
135 Result
:=RegWriteStringValue(HKEY_CURRENT_USER
,KeyName
,VarName
,Path
);
139 // Also update the environment
of the current process
.
140 SetEnvironmentVariable(VarName
,Path
);
143 // As IsComponentSelected() is not supported during uninstall
, this work
-around
144 // simply checks the Registry
. This
is unreliable
if the user runs the installer
145 // twice
, the first time selecting the component
, the second deselecting it
.
146 function IsComponentInstalled(Component
:String):Boolean;
148 UninstallKey
,UninstallValue
:String;
153 UninstallKey
:='SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{#APP_NAME}_is1';
154 UninstallValue
:='Inno Setup: Selected Components';
156 if RegQueryStringValue(HKEY_LOCAL_MACHINE
,UninstallKey
,UninstallValue
,Value
) then begin
157 Result
:=(Pos(Component
,Value
)>0);