Tuesday, April 30, 2013

Restart the windows remote server


To restart after shutdown remote machine.
·       Write below in cmd line
·       Shutdown /r

Stop listening to particular port in windows



·      To get the pids for respective port : 
         type in the below command in command prompt.

        netstat -a -o 

     This will output 

 Proto  Local Address          Foreign Address        State           PID
  TCP    0.0.0.0:80             I2LT189:0              LISTENING       2408
  TCP    0.0.0.0:135            I2LT189:0              LISTENING       924
  TCP    0.0.0.0:443            I2LT189:0              LISTENING       2408
  TCP    0.0.0.0:445            I2LT189:0              LISTENING       4
  TCP    0.0.0.0:1110           I2LT189:0              LISTENING       2888
  TCP    0.0.0.0:2002           I2LT189:0              LISTENING       2092
  TCP    0.0.0.0:3306           I2LT189:0              LISTENING       2244
  TCP    0.0.0.0:4444           I2LT189:0              LISTENING       8984
  TCP    0.0.0.0:5357           I2LT189:0              LISTENING       4
  TCP    0.0.0.0:5800           I2LT189:0              LISTENING       2520
  TCP    0.0.0.0:5900           I2LT189:0              LISTENING       2520
  TCP    0.0.0.0:5938           I2LT189:0              LISTENING       2408

·       To stop listening to port ,use taskkill command.
     taskkill /F /PID <process id>

·       eg:To stop listening to port 4444,type in below
     taskkill /F /PID 8984(where 8984 is process id for 0.0.0.0:4444 )

Terminate multiple processes at a time on windows machine

Terminating multiple tasks from task manager one at a time could be troublesome.
Use the below to kill multiple processes by running a command.
1. Open command prompt
2.   2. type    taskkill /f /im processname.exe
·             ex: taskkill /f /im java.exe
That's it. 


To check if the process is running or not and then terminate,please use below batchscript:
Below code wil first check if the firefox instance is open, only then it kills.

tasklist /FI "IMAGENAME eq firefox.exe" /FO CSV > search.log
FOR /F %%A IN (search.log) DO IF %%A EQU 0 GOTO end

:end
del search.log
taskkill /f /im firefox.exe
exit 0