Batch file cannot immediately see environment variables created by InstallShield script

We use InstallShield 2008 for our product installation. The product consists of several components. When a component is installed, a batch file is executed with some post-installation procedures specific to that component.

Problem: after installing batch files, some environment variables are used that are set during product installation through InstallScript. But it seems that batch files do not see immediate changes to the registry (and newly created environment variables).

Is there a way to complete the installation without rebooting the system?

Potentially useful information: the target system is Windows XP, currently a registered user, located in the Administrators group.

+3
source share
2 answers

I had the same problem with an earlier version of InstallShield. This is how I solved it (quick and dirty code).

#define HWND_BROADCAST          0xffff
#define WM_SETTINGCHANGE        0x001A
function UpdateEnvironmentVariable(szKey, szValue)
  NUMBER nResult;
  STRING szEnv;
  POINTER pEnv;
begin
  nResult = RegDBSetKeyValueEx(szKey, "PATH", REGDB_STRING, szValue, -1);

  szEnv = "Environment";                    
  pEnv = &szEnv;                  
  SendMessage (HWND_BROADCAST, WM_SETTINGCHANGE, 0, pEnv );
end;

The key is to use SendMessage. Hope this helps.

+4
source

InstallShield users using InstallShield 2010 or later.

Important: The InstallScript engine has changed from 2010 for Unicode.

, POINTER pEnv; . WPOINTER pEnv;. InstallShield 2013 , , "POINTER ", , .

InstallScript InstallShield 2013:

// Flush the NT registry to all applications.
function RefreshEnvironment()
    STRING szEnv;
    WPOINTER pEnv;
begin     
    szEnv = "Environment";
    pEnv = &szEnv;
    SendMessage(HWND_BROADCAST, WM_SETTINGCHANGE, 0, pEnv);
end;

:

// defines
#define WM_SETTINGCHANGE 0x001A
#define HWND_BROADCAST 0xffff

, WM_SETTINGCHANGE . , , .

+1

Source: https://habr.com/ru/post/1729267/


All Articles