Search code examples
nsis

Simulate Standard Windows Popup message Beep sound


I would like to simulate the standard windows popup message Beep sound in order to have each popup message in my script with the same sound effect.

In my script I use the default clause MUI_ABORTWARNING so, when the relative popup message is displayed, the standard windows popup message Beep is played.

For my purpose, I tryed to use the following API call but the sound effect is very different

System::Call "kernel32::Beep(i, i) b (${BEEP_FREQ_HZ}, ${BEEP_DURATION_MSEC})"

How can I do to accomplish the task?

Many thanks in advance to everyone that can help me on this.

Regards,


Solution

  • kernel32::Beep tries to use the little hardware speaker in your machine, if not available it uses the default system sound.

    Use MessageBeep to generate a standard sound:

    !define /IfNDef MB_ICONWARNING 0x00000030 ; You might want MB_ICONINFORMATION or MB_ICONSTOP instead
    System::Call 'USER32::MessageBeep(i ${MB_ICONWARNING})'
    

    If you are actually calling MessageBox in your NSIS code then you don't need to call MessageBeep, MessageBeep will be called for you if you use one of the MB_ICON* flags.