Remotely kill processes on Windows

Version 3
    Share:|

    #!/usr/bin/nsh

    #

    #windows-kill-ps.nsh

    1. Kill a process on a remote windows box using nsh

    2. - needs kill.exe from Windows Resource Kit

    #

    1. Written By Andrew Knott

    2. (c) BladeLogic, 2005

    #

     

    if

    then

    echo usage: $0 ' http://server2... '

    exit 1

    fi

     

    1. Process Name to kill (e.g. notepad)

    PS_TO_KILL=$1

    shift

     

    1. A temp directory on the windows boxes

    TMP_DIR=/rsc/temp

     

    #find the Kill.exe program (same directory as script)

    KILL_EXE=`dirname $0`/Kill.exe

    #echo $KILL_EXE

     

    if https://communities.bmc.com/ ! -f $KILL_EXE

    then

      echo Kill.exe does not exist in `dirname $0`

      exit 1

    fi

     

    for i in $*

    do

      cp $KILL_EXE //$i/.$TMP_DIR

      PS=`nps $i | grep -i $PS_TO_KILL$ | cut -c22-28`

     

      if

      then

        echo "Process: $PS_TO_KILL not found on $i"

        continue

      fi

     

      nexec $i $TMP_DIR/kill.exe $PS

      rm //$i/.$TMP_DIR/kill.exe

    done