Inno Setup添加Path变量_半个我
来源:百度文库 编辑:神马文学网 时间:2024/04/25 21:51:20
查看文章
Inno Setup添加Path变量
2009-08-24 11:04
Inno Setup添加Path变量
在[setup]段添加
ChangesEnvironment=true
在[Code]段中添加
procedure SetEnv(aEnvName, aEnvValue: string; aIsInstall, aIsInsForAllUser: Boolean);//设置环境变量函数
var
sOrgValue: string;
S1, sFileName, sInsFlag: string;
bRetValue, bInsForAllUser: Boolean;
SL: TStringList;
x: integer;
begin
bInsForAllUser := aIsInsForAllUser;
if UsingWinNT then
begin
if bInsForAllUser then
bRetValue := RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', aEnvName, sOrgValue)
else
bRetValue := RegQueryStringValue(HKEY_CURRENT_USER, 'Environment', aEnvName, sOrgValue)
sOrgValue := Trim(sOrgValue);
begin
S1 := aEnvValue;
if pos(Uppercase(sOrgValue), Uppercase(s1)) = 0 then //还没有加入
begin
if aIsInstall then
begin
x := Length(sOrgValue);
if (x > 0) and (StringOfChar(sOrgValue[x], 1) <> ';') then
sOrgValue := sOrgValue + ';';
sOrgValue := sOrgValue + S1;
end;
end else
begin
if not aIsInstall then
begin
StringChangeEx(sOrgValue, S1 + ';', '', True);
StringChangeEx(sOrgValue, S1, '', True);
end;
end;
if bInsForAllUser then
RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', aEnvName, sOrgValue)
else
begin
if (not aIsInstall) and (Trim(sOrgValue) = '') then
RegDeleteValue(HKEY_CURRENT_USER, 'Environment', aEnvName)
else
RegWriteStringValue(HKEY_CURRENT_USER, 'Environment', aEnvName, sOrgValue);
end;
end;
end else //非NT 系统,如Win98
begin
SL := TStringList.Create;
try
sFileName := ExpandConstant('{sd}\autoexec.bat');
LoadStringFromFile(sFileName, S1);
SL.Text := s1;
s1 := '"' + aEnvValue + '"';
s1 := 'set '+aEnvName +'=%path%;' + s1 ;
bRetValue := False;
x := SL.IndexOf(s1);
if x = -1 then
begin
if aIsInstall then
begin
SL.Add(s1);
bRetValue := True;
end;
end else //还没添加
if not aIsInstall then
begin
SL.Delete(x);
bRetValue := True;
end;
if bRetValue then
SL.SaveToFile(sFileName);
finally
SL.free;
end;
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);//添加环境变量
begin
if CurStep = ssPostInstall then
begin
SetEnv('path',ExpandConstant('{app}\Package\bpl;{app}\bin'),true,true); //在这儿调用,一定在这儿调用,安装完无须重启,立即生效
//SetEnv('path','{app}\bin',true,true);
end;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);//删除环境变量
begin
SetEnv('path',ExpandConstant('{app}\Package\bpl;{app}\bin'),false,true);
//SetEnv('path','{app}\bin',false,true);
end;
类别:Inno Setup |添加到搜藏 | 浏览(110) |评论 (0)
上一篇:选择文件夹(带新建文件夹)pas文... 下一篇:Inno Setup安装前检测程序是否安...
Inno Setup添加Path变量
2009-08-24 11:04
Inno Setup添加Path变量
在[setup]段添加
ChangesEnvironment=true
在[Code]段中添加
procedure SetEnv(aEnvName, aEnvValue: string; aIsInstall, aIsInsForAllUser: Boolean);//设置环境变量函数
var
sOrgValue: string;
S1, sFileName, sInsFlag: string;
bRetValue, bInsForAllUser: Boolean;
SL: TStringList;
x: integer;
begin
bInsForAllUser := aIsInsForAllUser;
if UsingWinNT then
begin
if bInsForAllUser then
bRetValue := RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', aEnvName, sOrgValue)
else
bRetValue := RegQueryStringValue(HKEY_CURRENT_USER, 'Environment', aEnvName, sOrgValue)
sOrgValue := Trim(sOrgValue);
begin
S1 := aEnvValue;
if pos(Uppercase(sOrgValue), Uppercase(s1)) = 0 then //还没有加入
begin
if aIsInstall then
begin
x := Length(sOrgValue);
if (x > 0) and (StringOfChar(sOrgValue[x], 1) <> ';') then
sOrgValue := sOrgValue + ';';
sOrgValue := sOrgValue + S1;
end;
end else
begin
if not aIsInstall then
begin
StringChangeEx(sOrgValue, S1 + ';', '', True);
StringChangeEx(sOrgValue, S1, '', True);
end;
end;
if bInsForAllUser then
RegWriteStringValue(HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', aEnvName, sOrgValue)
else
begin
if (not aIsInstall) and (Trim(sOrgValue) = '') then
RegDeleteValue(HKEY_CURRENT_USER, 'Environment', aEnvName)
else
RegWriteStringValue(HKEY_CURRENT_USER, 'Environment', aEnvName, sOrgValue);
end;
end;
end else //非NT 系统,如Win98
begin
SL := TStringList.Create;
try
sFileName := ExpandConstant('{sd}\autoexec.bat');
LoadStringFromFile(sFileName, S1);
SL.Text := s1;
s1 := '"' + aEnvValue + '"';
s1 := 'set '+aEnvName +'=%path%;' + s1 ;
bRetValue := False;
x := SL.IndexOf(s1);
if x = -1 then
begin
if aIsInstall then
begin
SL.Add(s1);
bRetValue := True;
end;
end else //还没添加
if not aIsInstall then
begin
SL.Delete(x);
bRetValue := True;
end;
if bRetValue then
SL.SaveToFile(sFileName);
finally
SL.free;
end;
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);//添加环境变量
begin
if CurStep = ssPostInstall then
begin
SetEnv('path',ExpandConstant('{app}\Package\bpl;{app}\bin'),true,true); //在这儿调用,一定在这儿调用,安装完无须重启,立即生效
//SetEnv('path','{app}\bin',true,true);
end;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);//删除环境变量
begin
SetEnv('path',ExpandConstant('{app}\Package\bpl;{app}\bin'),false,true);
//SetEnv('path','{app}\bin',false,true);
end;
类别:Inno Setup |添加到搜藏 | 浏览(110) |评论 (0)
上一篇:选择文件夹(带新建文件夹)pas文... 下一篇:Inno Setup安装前检测程序是否安...
Inno Setup添加Path变量_半个我
Inno Setup添加Path变量_半个我
Inno Setup添加Path变量
Inno Setup使用教程
Inno Setup教程-常见问题解答_槍炮玫瑰之心靈雞湯
Inno Setup教程-常见问题解答
Inno Setup安装和反安装ocx控件_www.3930.com.cn免费基地-VOI...
一键搞定Java桌面应用安装部署 —— exe4j + Inno Setup 带着JRE, 8M起飞
一键搞定Java桌面应用安装部署 —— exe4j + Inno Setup 带着JRE, 8M起飞
一键搞定Java桌面应用安装部署- exe4j + Inno Setup 带着JRE, 8M起飞
2.3 Makefile 变量_网缘
我教你免费添加歌曲的方法_静若处子
博客添加视频_
我教你免费添加歌曲的方法_静若处子的口袋
Servlet path
SVN SetUP
[PHP]预定义变量_边走边看
我的计算机开机后,屏幕显示pressto setup,to resume....
宝宝辅食添加表_辅食添加
懂得中药功效,已是半个大夫_
看守半岛半个世纪的驻韩美军_
如何为文件夹添加背景音乐_一品难
添加或删除文字的方法_
Setting your Path