To pause a script for 5 minutes (300 seconds):
ping -n 300 127.0.0.1 > nulTag Archives: DOS
Start/Stop SQL Server Express Service
Start the SQL Server service
@ECHO OFF
NET START MSSQL$SQLEXPRESS
Stop the SQL Server service
@ECHO OFF
NET STOP MSSQL$SQLEXPRESS
View user session information on remote machines
Copy and paste this into a blank text file and save the file with a .bat extension.
@echo off
rem ######################################################################
rem Program Name: Server_Session.bat
rem Developer: Tom Gee
rem Develop Date: 13-JUL-2007
rem Revision: 1.00
rem How to use: Find the NT IDs of the user(s) currently logged into a specific server and reset if desired
rem ######################################################################
title View Server Session(s)
:Begin
SET /P SERVER=Enter the server name or IP address you would like to examine:
echo.
qwinsta /server:%SERVER%
echo.
SET /P RESET=Would you like to reset a user’s session? (Y / N)
if %RESET%==Y goto YES
if %RESET%==N goto NO
if %RESET%==y goto YES
if %RESET%==n goto NO
:YES
echo.
SET /P USERID=What user ID would you like to reset?
rwinsta /server:%SERVER% %USERID%
:NO
echo.
echo Execution Complete.
echo.
SET /P RERUN=Would you like to examine another server? (Y / N)
echo.
if %RERUN%==Y goto Begin
if %RERUN%==y goto Begin
pause
Ping remote machines to test network connectivity
Copy and paste this into a blank text file and save the file with a .bat extension.
@echo off
rem ######################################################################
rem Program Name: Pinger.bat
rem Developer: Tom Gee
rem Develop Date: 13-JUL-2008
rem Revision: 1.00
rem How to use: Ping a specified server to see if it’s online and check response time
rem ######################################################################
title PC Pinger
:Begin
SET /P SERVER=Enter the server name or IP address you would like to ping:
echo.
:Recheck
ping %SERVER%
echo.
echo Execution Complete.
echo.
rem SET /P RERUN=Would you like to examine another server? (Y / N)
SET /P RERUN=Would you like to re-check the same server? (Y / N)
echo.
if %RERUN%==Y goto Recheck
if %RERUN%==y goto Recheck
pause
View system summary for remote PC
Copy and paste this into a blank text file and save the file with a .bat extension.
@echo off
rem ######################################################################
rem Program Name: MSINFO32.bat
rem Developer: Tom Gee
rem Develop Date: 08-AUG-2008
rem Revision: 1.00
rem How to use: View server hardware details
rem ######################################################################
title Remote Server Spec Viewer
:Begin
SET /P SERVER=Enter the server name to view info for:
echo.
cd C:Program FilesCommon FilesMicrosoft SharedMSInfo
msinfo32.exe /computer \%SERVER%
echo Execution Complete.
echo.
SET /P RERUN=Would you like to examine another server? (Y / N)
echo.
if %RERUN%==Y goto Begin
if %RERUN%==y goto Begin
pause
Handy DOS commands
- dir – Shows a list of files and subdirectories in a directory.
- /O – Order the list results
- D – by date/time (oldest first)
- E – by file extension (A-Z)
- G – group directories first
- N – by name (A-Z)
- S – by size (smallest first)
- /P – Pauses after each screen of information
- /Q – Display owner of the file
- /S – Include contents of subdirectories
- /T – Control which time field is used for sorting
- A – Last access
- W – Last written
- /4 – Show 4-digit year
- /O – Order the list results
- findstr – searches through text in files for a specified string value
- /I – Make the search not case sensitive
- /M – Print only the filename of file that contains a match
- /N – Print the line number
- /P – Skip files with non-printable characters
- /S – Search in all subdirectories
findstr /I /M “chocolate” c:Recipes*.*
- nslookup – DNS lookup/Traceroute
- ren – Rename all files in a directory. The following example will replace the .sql file extension for all files in the current directory with .txt.
ren *.sql *.txt
- xcopy – Copies files and directories
- %~d0%~p0 – Shows the path of the current directory
- %~f0 – The full path of the current batch file