Reputation: 21
UPDATE:
Ok below is the current code I wrote up but it errors out saying ERROR: The RPC server is unavailable
If I manually just type in taskkill /s cn /im csmmviewer.exe
within cmd it works, what I'm I missing here?
@echo off
:start
set /p "cn=Enter the computer name "
echo.
set /p "question=You will now close csmmviewer.exe on %cn% are you sure? [Y/N] "
echo.
if /I "%question%" EQU "Y" goto :run
if /I "%question%" EQU "N" goto :start
:run
taskkill /s cn /im csmmviewer.exe
set /p "again=Do you have another computer name? [Y/N] "
echo.
if /I "%again%" EQU "Y" goto :start
if /I "%again%" EQU "N" goto :exit
Hello noob here looking for some much needed help please.
At my job I run into this issue where too many people log into an application and when users that really need to use it can’t because too many people are logged into it (using up all the licenses) and I have to start kicking them off by killing the app remotely. The below command works every time but I have to manually copy and paste it into the command prompt and replace PCJXXXXX with the actual computer name. I will like to create a .bat file or .cmd file that I can just double click on which will then just ask to enter the computer name which I would just then enter and it runs the full command to end the task.
My script:
taskkill /s pcjXXXXX /u domain_name\admin /im csmmviewer.exe
XXXXX is what I delete and enter the actual name, can anyone help, if you need more details please let me know your questions?
Upvotes: 2
Views: 4749
Reputation: 56180
You can use a parameter (like killap PCJ12345
), when you call it from command line. %1
refers to the first parameter.
@echo off
if "%1" == "" (
set /p "PC=Enter PC Name: PCJ"
) else set "pc=%1"
taskkill /s pcj%PC% /u domain_name\admin /im csmmviewer.exe
(or if the string PCJ
is fix, simpler
killap 12345
, when you replace set "pc=%1"
with set "pc=PCJ%1"
)
If you don't give a parameter, (like when you start it by doubleclicking) it will ask you for the name.
Upvotes: 1
Reputation:
Using set /P
by simply prompting the user for input, stores the result in a variable and use the variable from there onwards.
@echo off
set /P "var=Please enter your PC Name: "
taskkill /s pcj%var% /u domain_name\admin /im csmmviewer.exe
for more detail on set
you can run set /?
from cmd.exe
Upvotes: 0