Helpful Tool/Script for System Admins

DeathmageDeathmage Banned Posts: 2,496
Hey guys,


So I'm one of those admins that likes writing scripts, and there is one tool in system internals that I love the most, if you don't know what system internals is, google it and use it. Needless to say I use one program more than others and that is "PSKILL", this program is amazing.


If you have a pesky program that won't close, pskill it and poof. I made a script since I use the program so much and because I'm lazy, I have about 30 custom scripts; lol at my last job my co-workers would call me a clicky admin since all I did was click on scripts to fix program (Hey I got tired of running the same command over and over again)

A simple script goes like this:

NOTE: you will need pskill.exe from System Internal in the system32 folder (where cmd is located) for this script to work. Also I like putting humor in my programs, lol. lastly whatever you name don't forget to save your batch files as "[file name].bat"


============================================
@echo off
color 0A
title close that program.

:start
echo Welcome, %USERNAME%
echo What would you like to do?
echo.
echo 1. Close the program in question
echo.
echo 2. Click here for a Nude photo!
echo.
echo 0. Quit
echo.

set /p choice="Enter your choice: "
if "%choice%"=="1" goto program-kill
if "%choice%"=="2" goto pervert
echo.
if "%choice%"=="0" exit
echo Invalid choice: %choice%
echo.
pause
cls
goto start

:pervert (lol this is a ":[]P" without the [] , forum emotes ftl)
cls
echo your a pervert, you know it, you clicked on this option shame on you!!!
echo.
goto cancel-special

:program-kill
echo.
set /p computer="Enter computer name:"
set /p program="Enter program name (before .exe): "
echo.
echo Input computer and program to close them
echo.
pskill -t \\%computer% %program%.exe


:cancel-special
set /p cancel="Type cancel to stop action: "
if not "%cancel%"=="cancel" exit
cls
echo Action is cancelled.
echo.

pause
exit



==================================
==================================


Another useful script I made not long ago, very handy, took me about 1 hour to write it, but now I'm super lazy and never type it again! lol!!!! ....system admins that deal with print spooler will love this...




@echo off
color 0A
title Fix Printer Spooler.

:start
echo Welcome, %USERNAME%
echo.
echo What would you like to do?
echo.
echo 1. Stop Print Spooler
echo.
echo. Please select both option 3 and option 4 before starting the printer spooler
echo.
echo 2. Delete .shd files in PRINTERS folder
echo 3. Delete .spl files in PRINTERS folder
echo.
echo 4. Start Print Spooler
echo.
echo 0. Quit
echo.

set /p choice="Enter your choice: "
if "%choice%"=="1" net stop spooler
if "%choice%"=="2" del %systemroot%\System32\spool\printers\*.shd /q
if "%choice%"=="3" del %systemroot%\System32\spool\printers\*.spl /q
if "%choice%"=="4" net start spooler
if "%choice%"=="0" exit
echo Invalid choice: %choice%
echo.
pause
cls

goto start



exit




Comments

  • DevilWAHDevilWAH Member Posts: 2,997 ■■■■■■■■□□
    the PS tool set is still great to this day.

    Many of the tools have been superseded by powershell (or at least you can do the same thing much easier with powershell). But they still great for getting down and dirty.

    psexec and psexplora are two that I still often return to. and if you want to see the heart of windows then looking through Mark Russinovich blog will open your eyes. A guy who knows windows inside and out.
    • If you can't explain it simply, you don't understand it well enough. Albert Einstein
    • An arrow can only be shot by pulling it backward. So when life is dragging you back with difficulties. It means that its going to launch you into something great. So just focus and keep aiming.
  • DeathmageDeathmage Banned Posts: 2,496
    I completely agree. Scripting just isn't used enough anymore. I got a feeling once I get into using PowerShell I'll pick up on it pretty fast. I did COBOL, C++, and Basic in college and got A+'s in all 3 classes. loved programming, just no money in it in my area.


    Here is a conditional shutdown script:

    @echo off
    color 0A
    title Conditional Shutdown.

    :start
    echo Welcome, %USERNAME%
    echo What would you like to do?
    echo.
    echo 1. Shutdown in specified time
    echo 2. Shutdown at a specified time
    echo 3. Shutdown now
    echo 4. Restart now
    echo 5. Log off now
    echo.
    echo 0. Quit
    echo.

    set /p choice="Enter your choice: "
    if "%choice%"=="1" goto shutdown
    if "%choice%"=="2" goto shutdown-timed
    if "%choice%"=="3" shutdown.exe -s -f
    if "%choice%"=="4" shutdown.exe -r -f
    if "%choice%"=="5" shutdown.exe -l -f
    if "%choice%"=="0" exit
    echo Invalid choice: %choice%
    echo.
    pause
    cls
    goto start

    :shutdown
    cls
    set /p min="Minutes until shutdown: "
    set /a sec=60*%min%
    shutdown.exe -s -f -t %sec%
    echo Shutdown initiated at %time%
    echo.
    goto cancel

    :shutdown-timed
    echo.
    echo the time format is HH:MM:SS (24 hour time)
    echo example: 14:30:00 for 2:30 PM
    echo.
    set /p tmg=enter the time that you wish the computer to shutdown on:
    schtasks.exe /create /sc ONCE /tn shutdown /st %tmg% /tr "shutdown.exe -s -t 00"
    echo shutdown initiated at %tmg%
    echo.

    :cancel
    set /p cancel="Type cancel to stop shutdown: "
    if not "%cancel%"=="cancel" exit
    shutdown.exe -a
    cls
    schtasks.exe /end /tn shutdown
    cls
    schtasks.exe /delete /tn shutdown
    cls
    echo Shutdown is cancelled.
    echo.
    pause
    exit




    Here is a roaming profile "forced" ownership script:

    (useful if you need to force ownership of roaming profiles that become corrupt and need to be rebuilt - that was a ***** of a task, hope to never do it again, EVER!!!!! - even with this script it took forever for 1500 users)


    @echo off
    color 0A
    title Corrupt Roaming Profile Change.

    :start
    echo Welcome, %USERNAME%
    echo What would you like to do?
    echo.
    echo 1. Click here for a Nude photo!
    echo 2. Take Ownership of User's Roaming Profile
    echo.
    echo 0. Quit
    echo.

    set /p choice="Enter your choice: "
    if "%choice%"=="1" goto pervert
    if "%choice%"=="2" goto ownership-change
    echo.
    if "%choice%"=="0" exit
    echo Invalid choice: %choice%
    echo.
    pause
    cls
    goto start

    :pervert
    cls
    echo your a pervert, you know it, you clicked on this option shame on you!!!
    echo.
    goto cancel-special

    :ownership-change
    echo.
    set /p profile="Enter user profile: "
    IF EXIST "d:\profiles\%profile%.DOMAIN.V2" psexec -s "icacls" "d:\profiles\%profile%.DOMAIN.V2" /grant administrators:F /t
    echo roaming profile forced ownership change in progress...
    echo.


    :cancel-special
    set /p cancel="Type cancel to stop action: "
    if not "%cancel%"=="cancel" exit
    cls
    echo Action is cancelled.
    echo.

    pause
    exit
Sign In or Register to comment.