Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer 1

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, http://nsis.sourceforge.net/TCP_plug-in

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
socket_inuse:
    MessageBox MB_OK "Port 80 is in use by another application."
    Abort
socket_error:
    MessageBox MB_OK "Error connecting to port 80"
    Abort
port_ok:
...
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
add comment

Your Answer

 
discard

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.