Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there any way to start a service and force a service that is already running to stop if it uses the port that the service I want to start is going to be using?

I'm going to be installing apache and mysql, and want the services to be running without having to manually stopping existing services that use port 80/3306 such as existing apache/mysql services.

I'm using NSIS to make my installer.

share|improve this question
up vote 1 down vote accepted

I made my installer abort if it found that the ports 80 or 3306 were in use.

I used a TCP plugin for NSIS,

I used it in this fashion,

TCP::CheckPort "80"
Pop $0
StrCmp $0 "free" port_ok
StrCmp $0 "socket_error" socket_error
StrCmp $0 "inuse" socket_inuse
Goto port_ok
    MessageBox MB_OK "Port 80 is in use by another application."
    MessageBox MB_OK "Error connecting to port 80"
share|improve this answer
+1. It is better to abort and let the user know why, rather than stop existing services. If one did that to a server of mine, I'd have a French-Canadian fit. – Patrick S. Nov 28 '11 at 23:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.