KillPsExec.bat

I’m using PsTools a lot for the moment. These nifty command line tools prove very efficient for remotely administering a bunch of servers (e.g. checking the state of a service or restarting it).

One of the drawbacks however is that the different versions of these tools don’t always seem to cooperate very well. A lengthy and time consuming solution is to use Hyena to remove the psexesvc service.

The little script below relies on SC to get that done a lot quicker. It basically checks if the psexesvc service exists and kills it if it does.

@echo off
cls

:: Checking & removing psexec from the remote host
For /F “Tokens=2” %%I in (‘sc \\%1 query psexesvc ^| find “SERVICE_NAME”‘) Do Set StrPsexecExists=%%I
If /I “[%StrPsexecExists%]”==”[psexesvc]” (echo PsExec running on the remote host; killing it. & sc \\%1 stop psexesvc & sc \\%1 delete psexesvc) else (echo PsExec is not running on the remote host.)

The script accepts 1 input parameter; the computer name.

Apart from using the caret (“^”) to escape the pipe (“|”) there’s nothing special about it. I’m mainly blogging about it because it’s called in some other script I’d like to write about later on.

http://blog.koenvermoesen.be/about-koen/

Tagged with:
Posted in Scripting
IT Pro Summer GP
IT Pro Summer Grand Prix
MVA
Microsoft Virtual Academy
Pro-Exchange
Pro-Exchange / Pro-Lync / Pro-Office365
MEET

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 158 other followers

%d bloggers like this: