ThinkDelphi官方博客ThinkDelphi名博

Email:zgc123@gmail.com
“照亮Delphi的美! 翻开Delphi新一页!”
个人信息
东莞大师兄
  • 今日访问:86
  • 总访问量:55677
  • 开博时间:2022-06-01
博文分类
  • 全部博客 (19)
  • 业界新闻 (1)
  • dotnet (1)
  • innoSetup (1)
  • PowerBuilder (1)
  • 报刊文摘 (1)
  • Delphi技术 (9)
  • Delphi趣闻 (4)
  • ThinkDelphi框架 (1)
博文正文

inno setup添加环境变量path 脚本

   分类: innoSetup 2023-01-31 14:14

inno setup添加环境变量path 脚本

; 脚本用 Inno Setup 脚本向导 生成。
; 查阅文档获取创建 INNO SETUP 脚本文件的详细资料!

#define MyAppName "军字一号pb动态库"
#define MyAppVersion "1.5"
#define MyAppPublisher "新疆天力卓越"
#define MyAppURL "http://zhenggc.com"

[Setup]
; 注意: AppId 的值是唯一识别这个程序的标志。
; 不要在其他程序中使用相同的 AppId 值。
; (在编译器中点击菜单“工具 -> 产生 GUID”可以产生一个新的 GUID)
AppId={{AB40281B-2300-4A1D-AFFF-D19446D47E2A}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName=d:\jzyh\
DefaultGroupName={#MyAppName}
DisableProgramGroupPage=yes
OutputDir=F:\jzyh\oracle_客户端软件_门诊医生站
OutputBaseFilename=pbdll_setup
SetupIconFile=D:\BLOOD\血库.ICO
Compression=lzma
SolidCompression=yes

[Languages]
Name: "default"; MessagesFile: "compiler:Default.isl"
Name: "chinesesimp"; MessagesFile: "compiler:Languages\ChineseSimp.isl"

[Files]
Source: "D:\jzyh\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
; 注意: 不要在任何共享的系统文件使用 "Flags: ignoreversion"

[code]
procedure SetEnv(aEnvName, aEnvValue: string; aIsInstall, aIsInsForAllUser: Boolean);
var
sOrgValue: string;
S1, sFileName: 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(s1), Uppercase(sOrgValue)) = 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 = ssInstall then
  begin
  // 将{app}路径添加到path环境变量中
     SetEnv('path','d:\jzyh\instdll\;d:\jzyh\pb5dll32\;d:\jzyh\pb6dll\;D:\jzyh\Sybase\Shared;',true,true); //在这儿调用,一定在这儿调用,安装完无须重启,立即生效
  end;
end;

//procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
//begin
  // 将{app}路径从path环境变量中删除
//  SetEnv('path',ExpandConstant('{app}'),false,true);
//end;
附件下载


博主: 东莞大师兄
版权声明:版权所有,转载时请注明原作者及网站链接!谢谢!
联系方式: zgc123@gmail.com

分类: innoSetup | 评论:0 | 浏览: 69
上一篇: 无
下一篇: C#简单实现高亮语法编辑器
网友评论:
 正在加载数据,请稍候...
返回顶部
/index.pas?a=list_comments /index.pas?a=ajax_gopage
发布评论:
刷新评论 刷新页面

关于凯蒂 | 联系我们 | 博客后台管理入口

©2018 ThinkDelphi --- 东莞大师兄作品