cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
okbrattli
Level 2

SendMessage hangs the installation

When I send a message using SendMessage the installer hangs!

 	/****** set env variable*******/
szKey = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
nResult = RegDBSetKeyValueEx(szKey, "USER_DOC_BUILD_TOOLS", REGDB_STRING, TARGETDIR ^ "\\buildtools\\", -1);

/**** Flush the registry to all applications ***/
#define WM_WININICHANGE 0x001A
szEnv = "Environment";
pEnv = &szEnv;
SendMessage (HWND_BROADCAST, WM_WININICHANGE , 0, pEnv );


This problem has evidently been around for some time, so a version of send message with a timeout is propably expecting to much 😞
(not to mention a setenv() ) Frankly I'm a bit disappointed. This is pretty basic stuff for installers...

Do anyone have a suggestion for an alternative approach to set an environment variable, and not require a reboot to have it visible?
Labels (1)
0 Kudos
(4) Replies
RobertDickau
Flexera Alumni

Please search these forums for "SendMessageTimeout"; I seem to remember seeing examples of prototyping and calling that Windows API function.
0 Kudos
deramor
Level 6

This works for me...

#define HWND_BROADCAST 0xffff
#define WM_SETTINGCHANGE 0x001A


svEnvironment = "Environment";
pEnvironment = &svEnvironment;

SendMessage ( HWND_BROADCAST,WM_SETTINGCHANGE,0, pEnvironment );
0 Kudos
xprt4y
Level 4

This subject should be a sticky post 🙂

Use SendMessageTimeout for sure. We used to have a -NOBROADCAST on our InstallScript setup's command line because my predecessor didn't know anything but InstallScript built-in functions and certain companies do not know how to write software that can process the Windows Message correctly. One was a fairly large anti-virus company, to remain un-named.

Robert's old post:

http://community.flexerasoftware.com/showthread.php?p=424845&pp=1&post=2


Here's one way to implement it (I'm paraphrasing here, you may need to debug this). Also, HWND_BROADCAST and WM_SETTINGCHANGE are defined in InstallScript now and do not need to be defined in 2010, IIRC.



#define HWND_BROADCAST 0xFFFF
#define WM_SETTINGCHANGE 0x001A
#define SMTO_ABORTIFHUNG 0x0002
#define SMTO_TIMEOUT 50

prototype BOOL USER32.SendMessageTimeout(HWND, SHORT, SHORT, POINTER, SHORT, SHORT, POINTER);

function SetEnvVar(szName As STRING , szVal As STRING )
STRING szKey, szEnv ;
NUMBER nResult ;
POINTER pResult, pEnv ;
begin

szKey = "SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment";
RegDBSetDefaultRoot(HKEY_LOCAL_MACHINE);
nResult = RegDBSetKeyValueEx(szKey, szName, REGDB_STRING, szVal, -1);

szEnv = "Environment";
pEnv = &szEnv;
SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, 0, pEnv, SMTO_ABORTIFHUNG, SMTO_TIMEOUT, pResult);

end;

0 Kudos
okbrattli
Level 2

Nice, so then all we need to do is check either of the return values and present the user with a hint that a reboot is required if it failes.

Thanks guys! I agree this should be made sticky. moreover the owners if the product should put this on their agenda!

BR
-Ole
0 Kudos