Inno Setup to add a path variable

Source: Internet
Author: User

Inno Setup to add a path variable

adding in the [Setup] section


Changesenvironment=true

adding in the [Code] section

Procedure setenv (Aenvname, aenvvalue:string; Aisinstall, Aisinsforalluser:boolean)//SET environment variable function
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//not joined
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//non-NT system, such as 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//is not added
        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);//Add environment variable
Begin
If Curstep = Sspostinstall Then
Begin
Setenv (' Path ', Expandconstant (' {app}/package/bpl;{ App}/bin '), true,true); Called here, must be called here, the installation does not need to restart, immediately effective
Setenv (' path ', ' {app}/bin ', true,true);
End
End


Procedure curuninstallstepchanged (curuninstallstep:tuninstallstep);//DELETE environment variable
Begin
Setenv (' Path ', Expandconstant (' {app}/package/bpl;{ App}/bin '), false,true);
Setenv (' path ', ' {app}/bin ', false,true);
End

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.