Monday, May 16, 2011

Useful DOS Commands

Below are some common commands I have used to do simple automation in the past. I find there are alway repetitive tasks like (stop a service and copy a file then start the service) Tasks like these can be automated so it happens in a matter of seconds, on a scheduler and repeatedly. Not to mention it takes all the human error out of the equation.

ROBOCOPY - Robust Copy, good for large copy jobs and can do multithreaded coping.

REM Examples:
Robocopy /E /MT:32 %SOURCE% %DEST%
Robocopy %SOURCE% %DEST% %FILES%

/E  Copy all subdirectories including empty ones
/MT   Multithreaded copy defaulted to 8 threads
%SOURCE% The source directory
%DEST% The destination
%FILES%  The files to be copied, default is *.*

RMDIR - Remove directory, deletes a driectory

REM Examples:
RMDIR /S /Q

/S Remove all files and directories in the directory
/Q Supress prompting in /S

START - Starts a seprate DOS window
REM Examples:
START /WAIT %EXEC%


/WAIT Wait for the window to terminate
%EXEC% Prorgam/Command to run in new window

NET START - Starts a win32 service


REM Examples:
NET START %SERVICE%

%SERVICE% The name of the service to start

NET STOP - Stops a win32 service

REM Examples:
NET STOP %SERVICE%

%SERVICE% The name of the service to stop

NET USE - Map a network drive

REM Examples:
NET USE %DRIVE% %PATH%
NET USE %DRIVE% %PATH% /USER:%USER% %PSWD%

%Drive% Drive letter "Z:"ECHO %PATH% UNC path to map
/USER User other than current logon
%USER% User name
%PSWD% Password

NET USER - Add and remove users from the local system

REM Examples:
NET USER %USER% %PSWD% /ADD
NET USER %USER% /DELETE


%USER% User name
%PSWD% User Password
/ADD Add user
/DELETE Delete user


NBTSTAT - NetBios information for a remote computer

REM Examples:
NBTSTAT -A %IP%
NBTSTAT -a %COMP%


-A Use the IP address
-a Use computer name
%IP% IP address
%COMP% Computer name

Date Stamp - Create a date stamp to be used as a folder name


for /F "tokens=2-4 delims=/ " %%i in ('date /t') do set tdtd=%%i%%j%%k
for /F "tokens=5-8 delims=:. " %%i in ('echo.^| time ^| find "current" ') do set ttrn=%%i%%j%%k%%l
ECHO %tdtd%%ttrn%

SET - Get User input

SET /P URL=[Please Enter a URL]

Good DOS web sites:
http://www.dostips.com/

1 comment:

Osito said...

To Shutdown and reboot computer from the comandline.

shutdown -r -c "Rebooting for latest updates."

the -r is the reboot switch the -c is a comment displayed if needed