Killing a Process running on Remote Computer(The batch file way..)
This morning when I came to office, I had a set of tasks which needed to be completed ASAP. My current engagement requires me to work on customer server via RDP. Now RDP has an interesting behavior, in certain cases if the server has a limited resources, it will simply refuse to allow RDP access. And unfortunately, it happened to me today. One of my colleague ran a time-consuming, resource-hungry custom code over the weekend so we can work smoothly during the weekdays, however the application could not complete its work during the weekend and was still running and consuming whatever resources were available and in turn caused a DoS (Denial Of Service). I thought to use VBScript/WMI to kill the remote process as I had the name of the process to be killed and have had used it in past effectively. I started working with the script but, I felt it will take too much time to figure out the script that will help me so I decided to search on my favorite search engine for easier and faster options. Within a few minutes I got the pointers to use tasklist.exe and taskkill.exe. I killed the process manually and easily got my access restored. However at end of the day, spending some time one this and making a batch file will come handy as we run into this situation more often. So I spent few minutes in notepad and here is the batch file that I got. This batch file is not polished but should get the job done in time of needs. And as usual I don't take any responsibility of any kind if you use this script and get into some trouble. So use it at your own risk...
@ECHO OFF
@ECHO WARNING : This script will forcefully kill the process and will not ask for confirmation before killing the process.
SET MESSAGE=
SET SYSTEMNAME=
SET USERNAME=
SET PASSWORD=
SET PID=
SET /P MESSAGE=Press any key to continue...
SET /P SYSTEMNAME=Enter target computer name or IP :
SET /P USERNAME=Enter User Name (domain\username) :
SET /P PASSWORD=Enter Password :
@ECHO Please wait while we get the list of processes...
TASKLIST.EXE /S %SYSTEMNAME% /U %USERNAME% /P %PASSWORD%
SET /P PID=Enter PID(Process ID) of the process you want to kill :
TASKKILL.EXE /F /S %SYSTEMNAME% /U %USERNAME% /P %PASSWORD% /PID %PID%
SET /P MESSAGE=Press any key to continue...
No comments:
Post a Comment