简体   繁体   中英

Inno Setup Using environment variable values from parent program or batch (not global from registry)

Summary:
The program I am working on is not a traditional use of the installer and would really be a standard executable but Inno Setup is the only tool I have and I have made it fit all kinds of purposes so far.

Current trial - is to delete specific files, located by using an environment variable ( PROG_USER ). This part is fine initially, the application works fine if the variables are set in Windows. I have it validate first the variable is set. If so, it allows the user to continue.

The issue:
But here is the issue. I run many test environments each sets variables from the running application, typically any program I launch from this program inherits these variables. But so far Inno Setup always tries to resolve the registry. Is there any way to collect the current session variables?

A simple test would be to execute the program from either a batch or a command prompt after setting the variable eg SET PROG_USER=c:\\testing\\version2\\user_files

Then launch the executable, each time it lets me know the variable is not set even though if I run SET I can see this session does have that value. Like I said maybe this is a stretch too far but I have seen some great answers and I am hoping to find one for this.


Update : I want to use variables but not the one in the registry. eg PROG_USER=USER1 (in registry) But the application I will launch the installer from has set PROG_USER=USER20

My code is like this:

procedure InitializeWizard;
var
  MsgResult: Integer;
  PROG: string;
begin
  PROG := GetEnv('PROG_USER');

  if PROG <> '' then
  begin
    MsgResult :=
      MsgBox('PROG_USER Path = ' + PROG +  #13#10 +'Do you wish to still proceed?',
        mbInformation, MB_YESNO);
    if MsgResult = IDYES then
    begin
      { user pressed Yes do rest of program }
    end
      else
    if MsgResult = IDNO then
    begin
      Abort;
    end
  end
    else
  begin
    MsgBox('PROG_USER variable is not set, this process will now exit!',
      mbInformation, MB_OK);
    
    Abort;
  end;      
end;

This code is fine if you want to check and or use the environment variables as set globally by Windows (as you know Windows stores these in the registry which it seems is where Inno Setup looks?)

I want the current variables used by another application. I am launching my "setup" from another program not by double clicking it.

As I mentioned this can be simulated by a simple batch file that calls the setup.exe . Typically any program called this way will inherit the variables set in that batch (or program) but my Inno Setup does not.

When the installers is elevated to Administrator privileges, it runs in a different context, so it does not inherit a parent process environment.

You have two options:

  • If the installer does not require the Administrator privileges, set

    PrivilegesRequired=lowest

    Then the installer will behave as a normal program, inheriting the environment of the parent process.

  • If the installer does require the Administrator privileges, run the parent process with Administrator privileges straight away. Then the parent process and the installer will use the same context and the environment will be inherited too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM