Search code examples
inno-setuppascalscript

Playing native Windows sounds in Inno Setup


In there any way to play Windows native sounds using Inno Setup?

For example I'm showing a custom message box, and I need to play Windows warning/info/error sound before showing that message. Any way?


Solution

  • Use PlaySound WinAPI function:

    const
      SND_ASYNC = $0001;
      SND_ALIAS = $00010000; 
    
    function PlaySound(pszSound: string; hmod: THandle; fdwSound: DWORD): BOOL;
      external 'PlaySoundW@Winmm.dll stdcall';
    

    Use it like:

    PlaySound('SystemQuestion', 0, SND_ALIAS or SND_ASYNC);
    

    For list of standard sound aliases, see:
    https://learn.microsoft.com/en-us/windows/win32/multimedia/using-playsound-to-play-system-sounds