Environment Variables Example

InstallShield 2019

/********************************************************************\

*  The following code creates an environment variable under Windows

*  for an entire system. You can modify the OnEnd event handler

*  function block (or any other function block) to include this example

*  code.

*

*  NOTE: The current user must have administrator privileges for this

*  code to work.

\********************************************************************/

 

  #define WM_WININICHANGE 0x001A

  #define HWND_BROADCAST 0xffff

  NUMBER nResult;

  STRING szKey, szEnv;

  WPOINTER pEnv;

  

  begin

 

      szKey = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";

      RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);

      nResult = RegDBSetKeyValueEx(szKey, "Fame", REGDB_STRING, "C:\\Test", -1);

      if (nResult < 0) then

          MessageBox("Failed to Set Environment Variable", WARNING);

      else

          MessageBox("Successfully Set Environment Variable", INFORMATION);

          // Flush the registry to all applications.

          szEnv = "Environment";

          pEnv = &szEnv;

          SendMessage (HWND_BROADCAST, WM_WININICHANGE, 0, pEnv );

      endif;

      // RebootDialog("", "", SYS_BOOTMACHINE);

  end;

 

 

/********************************************************************\

*  The following code creates an environment variable under Windows

*  for the current user. You can modify the OnEnd event handler

*  function block (or any other function block) to include this example

*  code.

*

*  NOTE: The current user must have administrator privileges for this

*  code to work.

\********************************************************************/

 

  #define WM_WININICHANGE 0x001A

  #define HWND_BROADCAST 0xffff

 

  NUMBER nResult;

  STRING szKey, szEnv;

  WPOINTER pEnv;

 

  begin

      szKey="Environment";

      RegDBSetDefaultRoot(HKEY_CURRENT_USER);

      nResult=RegDBSetKeyValueEx(szKey,"Fame",REGDB_STRING,"C:\\test",-1);

      if (nResult < 0) then

          MessageBox("Failed to Set Environment Variable",WARNING);

      else

          MessageBox("Successfully Set Environment Variable",INFORMATION);

          // Flush the registry to all applications.

          szEnv = "Environment";

          pEnv = &szEnv;

          SendMessage (HWND_BROADCAST, WM_WININICHANGE, 0, pEnv );

      endif;

      //RebootDialog("","",SYS_BOOTMACHINE);

  end;