NSIS Installers & Correctly Detecting Running Winamp Instances

This is probably a niche topic but I thought it would be handy to document how to detect all true running Winamp instances if only due to the effort that I’ve put in to get a reliable means to detect if a true Winamp instance is already running so that it can be closed prior to installing a plug-in when using an NSIS installer (e.g. before running a Winamp backup with the Winamp Backup Tool).

A common way to detect Winamp is to look for a windows with the class of Winamp v1.x and for a lot of cases this will work without issue. However if running multiple Winamp instances or if the user has changed the main window class (as can be done via a setting in the paths.ini file or via the /CLASS command-line option), that check will then fail.

Additionally if a modern skin (e.g. Bento or anything that is cPro based) is being used then in some cases it is possible for the check to fail. Finally, that check can also return a seemingly valid but incorrect result if another program is running which provides a fake Winamp window to allow for basic plug-in support to work (which in most cases only emulates Winamp 2.x support).

The NSIS plug-in I’m providing below (which is free to use - and I will likely release source code for it later on) is able to correctly detect Winamp installs irrespective of the skin type and main window class being used and will also filter out anything that is just emulating Winamp but is not a real Winamp instance.

NSIS Ansi Plug-in: Download
Note: Tested with NSIS v2.51

NSIS Unicode Plug-in: Download
Note: Tested with NSIS v3.0 RC1

The plug-in once correctly installed is used via: FindWinamp::find <path> [<filterpath>]

<path> is required and is the location of the file to output the results to (consider using GetTempFileName as a way to help ensure a valid path can be created).
<filterpath> is an optional parameter which can be used to limit the result to only the running Winamp instances which are from that folder.

The output into <path> is like the following example:

exe=C:Program Files (x86)Winampwinamp.exe
class=Winamp v1.x

num in the found section indicates how many found running Winamp instances there were and with that you can then determine how many (if at all) sections need to be inspected which being at zero and increase up to num - 1.

The pid and hwnd values are decimal numbers, so there should be no issue in using them as-is on reading from the ini file.

Multiple calls to the plug-in and using the same file will not clear the file of sections that are no longer applicable and it is always recommended to check num first in-order to know what was found before further processing of the sections (if any exist).

The following example function will detect if there are any running Winamp instances and ask the user if they want to close them or not. If not then the installer will be aborted.If yes then all reported Winamp instances will be closed and it will then re-check to make sure that all were successfully closed (which should happen without issue unless Winamp crashes for some reason).

Function FindAndCloseWinamp
  ;Detect running Winamp instances and close them
  !define WINAMP_FILE_EXIT 40001

  GetTempFileName $R3

  FindWinamp::find $R3

  ReadINIStr $R0 $R3 "found" "num"
  IntCmp $R0 0 ok

    "Close all Winamp instances now?" IDYES process IDNO 0
  Delete $R3

  ; we adjust the total down by one to prevent
  ; an unwanted loop iteration with ${ForEach}
  IntOp $R0 $R0 - 1

  ; loop over the number of sections until done
  ${ForEach} $R2 0 $R0 + 1
    ReadINIStr $R1 $R3 $R2 "hwnd"
    SendMessage $R1 ${WM_COMMAND} ${WINAMP_FILE_EXIT} 0
  Goto checkagain
  Delete $R3

The above is just to show how the plug-in can be used so it may not work as a direct copy+paste into your script due to register usage, etc but should be more than enough to use as a basis.



  1. How about making a voice module for winamp 5.66 so that i can talk thru shoutcast to my audience would be a great plugin to add and benefit many users ……

  2. Gerry: Although this isn’t the best of the posts to have commented on to make such a request I’ll answer here as I cannot easily move this comment to another post on the blog.

    What you’re asking for is something I have thought about doing for the pack. Sadly I’m more than aware of the limitations of the official SHOUTcast Source DSP when it comes to capturing audio and how it doesn’t work well from Vista and newer (as I could never really get time allocated to work on it properly which is what it needed).

    I have briefly started on a few months back making the basis of a new Source DSP plug-in but it’s not at the stage that it will just transmit the audio from Winamp to a server. However as I’ve started on it, it does mean it’s something that I do want to see with it actually able to capture audio from other sources on the machine and if needed correctly overlay it with what Winamp is playing

    The only aspect I’m not sure about trying to do later on with it (once I’ve got the basis of the plug-in up and running) would be to try to accept multiple inputs (i.e. two or more DJs (and possibly from an external machine) or from different line-in inputs) but that then really starts to move into a more professional solution than I’d expect from a hobbyists + Winamp broadcasting solution (if that makes sense). So if it is to happen, it’s going to be a while before I get around to it as I’ve already a fair amount of things queued up or in-progress that need to be addressed first but I’ve not forgotten about the importance of Winamp + streaming :)