首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

各位:用inno setup制作安装程序,如何把在环境变量path中添加路径

2013-09-06 
各位:用inno setup制作安装程序,怎么把在环境变量path中添加路径?下面的这个程序,怎么都没有效果啊???Inno

各位:用inno setup制作安装程序,怎么把在环境变量path中添加路径?
下面的这个程序,怎么都没有效果啊???

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;

innosetup Path 环境变量
[解决办法]
这不是VC吧!
[解决办法]
这个pascal,怎么发到这里来了
[解决办法]
[Setup]: ChangesEnvironment
Valid values:
 yes or no  
Default value:
 no  

Description:
When set to yes, at the end of the installation Setup will notify other running applications (notably Windows Explorer) that they should reload their environment variables from the registry.

If your installation creates or changes an environment variable but doesn't have ChangesEnvironment set to yes, the new/changed environment variable will not be seen by applications launched from Explorer until the user logs off or restarts the computer.

热点排行