Headline News
GoPro Returns with New Range (September 26, 2016 7:31 pm)
TRAILER: Doctor Strange (April 13, 2016 8:23 am)
TRAILER: Dawn of Justice Trailer 2 (December 3, 2015 6:25 pm)
Luther Season 4 Returns to the BBC (December 2, 2015 9:13 pm)
Sherlock Special (December 2, 2015 9:01 pm)

SuperScript

April 9, 2014
693 Views

This batch file which uses some of the Windows Sysinternals tools should provide a convenient way of performing a wide range of system administrative tasks. Make sure you read and understand the commands this script will perform, and tailor it appropriately to suit your environment. This is particularly useful for performing tasks remotely, without displaying anything on the end user’s screen. You can for instance, use option 5 to open a remote command prompt to the machine of your choice. You can then run commands as if you were sitting in front of the user’s PC, but without them seeing anything on their screen.

First, download the Sysinternals PsTools package and extract the following files to a folder (details of the PsTools applications can be found on the Sysinternals site):

  • PsExec.exe
  • PsKill.exe
  • PsList.exe
  • PsLoggedon.exe
  • PsShutdown.exe

Now we need to create the batch file in the same folder as the files you extracted. Open notepad or a similar text editor and enter the following:

ECHO.
SET /P computer=Enter the name of the remote PC :
SET /P username=Enter your Domain\Username  :
GOTO MENU

So when the file is executed, it will ask the you for a name of a PC to connect to and the domain\username, in that format.

Now we will create the menu:

:MENU
ECHO.
ECHO.
ECHO What would you like to do?
ECHO.
ECHO.
ECHO 1  - Ping the PC
ECHO 2  - Ping the PC continuously
ECHO 3  - Run a Tracert
ECHO 4  - Open the C drive
ECHO 5  - Open a remote command prompt
ECHO 6  - Get IP address
ECHO 7  - Get the MAC Address
ECHO 8  - Get info about the PC
ECHO 9  - Flush DNS
ECHO 10 - Run a GPUpdate /force
ECHO 11 - Defrag the PC
ECHO 12 - Clear temp files
ECHO 13 - Run a full Checkdisk
ECHO 14 - Run a Checkdisk scan
ECHO 15 - See who is logged on to the PC
ECHO 16 - Log the user off
ECHO 17 - Reboot the PC
ECHO 18 - View running processes
ECHO 19 - Kill a process
ECHO 20 - Sync the time
ECHO 21 - Exit
ECHO.
SET /P N=Type 1 to 21 then press ENTER:
IF %N%==1  GOTO ping
IF %N%==2  GOTO continuousPing
IF %N%==3  GOTO tracert
IF %N%==4  GOTO remoteC$
IF %N%==5  GOTO remoteCMD
IF %N%==6  GOTO remoteIPConfig
IF %N%==7  GOTO remoteGetMAC
IF %N%==8  GOTO remoteSysInfo
IF %N%==9  GOTO remoteFlushDNS
IF %N%==10 GOTO remoteGPUpdateForce
IF %N%==11 GOTO remoteDefrag
IF %N%==12 GOTO remoteClearTempFiles
IF %N%==13 GOTO remoteCHKDSK_FULL
IF %N%==14 GOTO remoteCHKDSK_ScanOnly
IF %N%==15 GOTO remoteUsersLoggedOn
IF %N%==16 GOTO remoteLogOff
IF %N%==17 GOTO remoteReboot
IF %N%==18 GOTO remoteTaskManager
IF %N%==19 GOTO remoteProcessKill
IF %N%==20 GOTO remoteSyncTime
IF %N%==21 GOTO EOF

When run, this will provide the you with a menu of options listed with numbers. If you enter a number, the script will perform the corresponding command.

Finally, we have the actual commands that will be run based on the option selected above:

:ping
ping %computer%
pause
GOTO MENU

:continuousPing
ECHO Press ctrl + c to stop then N to go back to the menu
ping -t %computer%
pause
GOTO MENU

:tracert
tracert %computer%
pause
GOTO MENU

:remoteC$
start \\%computer%\c$
pause
GOTO MENU

:remoteCMD
psexec -u %username% \\%computer% cmd
pause
GOTO MENU

:remoteIPConfig
psexec -u %username% \\%computer% ipconfig
pause
GOTO MENU

:remoteGetMAC
psexec -u %username% \\%computer% getmac
pause
GOTO MENU

:remoteSysInfo
systeminfo /u %username% /s %computer%
pause
GOTO MENU

:remoteFlushDNS
psexec -u %username% \\%computer% ipconfig /flushdns
pause
GOTO MENU

:remoteGPUpdateForce
psexec -u %username% \\%computer% gpupdate /force
pause
GOTO MENU

:remoteDefrag
psexec -u %username% \\%computer% defrag c: -v
pause
GOTo MENU

:remoteClearTempFiles
ECHO You will be prompted for your password at each stage of the process
SET /P userusername=User's username     :
ECHO.
ECHO.
ECHO Clearing C:\Temp...
psexec -u %username% \\%computer% cmd /c del /Q /F /S "C:\Temp\*.*"
ECHO.
ECHO.
ECHO Clearing C:\Windows\Temp
psexec -u %username% \\%computer% cmd /c del /Q /F /S "C:\WINDOWS\Temp\*.*"
ECHO.
ECHO.
ECHO Clearing cookies
psexec -u %username% \\%computer% cmd /c del /Q /F /S "C:\Documents and Settings\%userusername%\Cookies\*.*"
ECHO.
ECHO.
ECHO Clearing user profile local temp files...
psexec -u %username% \\%computer% cmd /c del /Q /F /S "C:\Documents and Settings\%userusername%\Local Settings\Temp\*.*"
ECHO.
ECHO.
ECHO Clearing user profile IE files...
psexec -u %username% \\%computer% cmd /c del /Q /F /S "C:\Documents and Settings\%userusername%\Local Settings\Temporary Internet Files\*.*"
pause
GOTO MENU

:remoteCHKDSK_FULL
psexec -u %username% \\%computer% chkdsk /F c:
pause
GOTO MENU

:remoteCHKDSK_ScanOnly
psexec -u %username% \\%computer% chkdsk c:
pause
GOTO MENU

:remoteUsersLoggedOn
psloggedon -l -x \\%computer%
pause
GOTO MENU

:remoteLogOff
psshutdown -o -u %username% \\%computer%
pause
GOTO MENU

:remoteReboot
psshutdown -r -c -u %username% \\%computer%
pause
GOTO MENU

:remoteTaskManager
pslist -s -u %username% \\%computer%
pause
GOTO MENU

:remoteProcessKill
SET /P process=Process name     :
pskill -u %username% \\%computer% %process%
pause
GOTO MENU

:remoteSyncTime
psexec -u %username% \\%computer% net time /set /y 
pause
GOTO MENU

Now save the script as SuperScript.bat or something similar (needs the .bat extension). When you run it, you will be prompted for a hostname, your domain and username, and then the menu will appear. Type in a number of an action you want to perform and the command should run. Please note, the batch file will need to be in the same folder as the PsTools executable files.