4

Is it possible to refresh the desktop using Inno Setup in the [Code] section?

Either by using SendMessage or somehow use SHChangeNotify?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992

1 Answers1

5

You can call any function in the Windows API by calling it in the appropriate DLL. The Pascal DLL syntax is documented here. The documentation of the SHChangeNotify function is found at MSDN as usual. This function is found in Shell32.dll (no surprise!).

[Code]
const
  SHCNE_ASSOCCHANGED = $08000000;
  SHCNF_IDLIST = $00000000;

procedure SHChangeNotify(wEventID: integer; uFlags: cardinal; dwItem1, dwItem2: cardinal);
external 'SHChangeNotify@shell32.dll stdcall';

procedure SendChangeNotification;
begin
  SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
end;

Now you can call SendChangeNotification anywhere you like, for instance in an event function.

Update

The text above answers your question, how to "refresh the desktop using Inno Setup in the [Code] section". But did you know that Inno Setup can refresh the desktop for you, automatically? Simply write

ChangesAssociations=yes

in the [Setup] section. See: ChangesAssociations

Andrew Truckle
  • 17,769
  • 16
  • 66
  • 164
Andreas Rejbrand
  • 105,602
  • 8
  • 282
  • 384
  • Thanks for your reply. But how does it work? At the moment i'm trying: external 'SHChangeNotify(0x8000000, 0x1000, 0, 0)@Shell32.dll stdcall'; but i get syntax errors. –  May 01 '11 at 20:49
  • @s0mmer: That is not the right syntax. First, the declaration of the function should only state what the signature is and where the function resides (if it is external). The arguments you put in when you call the function! In addition, MSDN states that `SHCNE_ASSOCCHANGED` has to be used with `SHCNF_IDLIST` which is zero, not `$1000`. – Andreas Rejbrand May 02 '11 at 00:33
  • This is very useful when we use inno for other tasks e.g. **write small pascal programs**. See [http://www.vincenzo.net/isxkb/index.php?title=Writing_quick_Pascal_programs_with_Inno_Setup](http://www.vincenzo.net/isxkb/index.php?title=Writing_quick_Pascal_programs_with_Inno_Setup). Especially since `ChangesAssociations=yes` will **only** be called at the very end of the installation! – fubar Oct 17 '13 at 16:43