1 // Returns the path
to the common
or user shell folder
as specified
in "Param".
2 function GetShellFolder(Param
:string):string;
4 if IsAdminLoggedOn
then begin
5 Param
:='{common'+Param
+'}';
7 Param
:='{user'+Param
+'}';
9 Result
:=ExpandConstant(Param
);
12 // Returns the
value(s
) of the environment variable
"VarName", which
is tokenized
13 // by
";" into an
array of strings
. This makes it easy query PATH
-like variables
14 // in addition
to normal variables
. If "AllUsers" is true, the common variables
15 // are searched
, else the user
-specific ones
.
16 function GetEnvStrings(VarName
:string;AllUsers
:Boolean):TArrayOfString
;
24 // See http
://www
.jrsoftware
.org
/isfaq
.php#env
25 if AllUsers
then begin
26 // We ignore errors here
. The resulting
array of strings will be empty
.
27 RegQueryStringValue(HKEY_LOCAL_MACHINE
,'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',VarName
,Path
);
29 // We ignore errors here
. The resulting
array of strings will be empty
.
30 RegQueryStringValue(HKEY_CURRENT_USER
,'Environment',VarName
,Path
);
33 // Make sure we have at least one semicolon
.
36 // Split the directories
in PATH into an
array of strings
.
38 SetArrayLength(Result
,0);
42 SetArrayLength(Result
,i
+1);
44 Result
[i
]:=Copy(Path
,1,p
-1);
47 Path
:=Copy(Path
,p
+1,Length(Path
));
52 // Sets the environment variable
"VarName" to the concatenation
of "DirStrings"
53 // using
";" as the delimiter
. If "AllUsers" is true, a common variable
is set,
54 // else a user
-specific one
. If "DeleteIfEmpty" is true and "DirStrings" is
55 // empty
, "VarName" is deleted instead
of set if it exists
.
56 function SetEnvStrings(VarName
:string;AllUsers
,DeleteIfEmpty
:Boolean;DirStrings
:TArrayOfString
):Boolean;
61 // Merge all non
-empty directory strings into a PATH variable
.
63 for i
:=0 to GetArrayLength(DirStrings
)-1 do begin
64 if Length(DirStrings
[i
])>0 then begin
65 if Length(Path
)>0 then begin
66 Path
:=Path
+';'+DirStrings
[i
];
73 // See http
://www
.jrsoftware
.org
/isfaq
.php#env
74 if AllUsers
then begin
75 KeyName
:='SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
76 if DeleteIfEmpty
and (Length(Path
)=0) then begin
77 Result
:=(not RegValueExists(HKEY_LOCAL_MACHINE
,KeyName
,VarName
)) or
78 RegDeleteValue(HKEY_LOCAL_MACHINE
,KeyName
,VarName
);
80 Result
:=RegWriteStringValue(HKEY_LOCAL_MACHINE
,KeyName
,VarName
,Path
);
83 KeyName
:='Environment';
84 if DeleteIfEmpty
and (Length(Path
)=0) then begin
85 Result
:=(not RegValueExists(HKEY_CURRENT_USER
,KeyName
,VarName
)) or
86 RegDeleteValue(HKEY_CURRENT_USER
,KeyName
,VarName
);
88 Result
:=RegWriteStringValue(HKEY_CURRENT_USER
,KeyName
,VarName
,Path
);