Archive

Posts Tagged ‘batch’

Windows – Set User Account Details

October 9, 2008 scripthacks Leave a comment

The Windows built in command “net user” allows modification of local account settings.   

: Creates account and sets password + user full name & description
net user <username> <password> /ADD /fullname:"name" /comment:"description"
 
: Set Account Password to never expire and add account description
net user <username> /EXPIRES:NEVER /COMMENT:"<comment>"

:D isable Account
net user <username>  /ACTIVE:NO

:D elete Account
net user <username>  /DELETE

:Full net user configuration flags and options
net user /help

Robocopy – Best Damn Windows Comand line Copy Util!

September 29, 2008 scripthacks Leave a comment

I’m a huge fan of the windows robocopy program.  It allows you to perform migrations and copies between servers. Recurvsive copy capabilities are included as well as copies based on file archive bit settings.

Basic Robocopy syntax:

robocopy <source dir> <destination dir> <file> <options>

Copy 1 file:

robocopy c:\test\ d:\test move-this-file.txt /z /r:1 /w:1 /v /eta /e /L

/z = copy the file in restartable mode… if the file copy breaks it will just pick up where it left off.

/r:1= When copying a large number of files and or folders I always set the retry count to be really low. That way if it gets hung up on a file it just skips it.

/w:1= Same as /r except this pertains to the wait timeout. ie. if there is a ton of latency the file is skipped.

/v = show output on screen during the copy

/eta = show me how long it expects the copy to take

/e = recursively copy all sub folders and files including empy ones empty directories.

/L ALWAYS use /L before running any robocopy script or command. It will show you what is going to be copied by the command being run.

Robocopy is included in the Windows 2000+ Resource pack which can be download in my Utilities link found at the top of the page.

Windows Services – Query Current Status

September 15, 2008 scripthacks Leave a comment

Find the current status of a service running on a server or windows workstation/laptop. 

sc query <Service Name> | findstr STATE

To find a list of all installed services launch the services computer management window by running Services.msc or by launching start -> programs -> Administrative Tools -> Services 

  1. Right click the service in question
  2. The Service Name will be the name that you reference in your service query. 
Example Service: Indexing Service = CiSvc
Example Status Output: sc query CiSvc | findstr STATE
Output:                          STATE              : 1  STOPPED
Categories: Uncategorized Tags: , , ,

Batch – Common Variables & Shortcuts

September 15, 2008 scripthacks Leave a comment

:: Keep variables local
SETLOCAL (Define at beginning of script)
ENDLOCAL (Release variables at end of script)

:: Set Date Variable
set CurrentDATE=%date:~4,2%-%date:~7,2%-%date:~10,4%
set CurrentTime=%time:~0,2%.%time:~3,2%

Output: 09-15-08

:: Current Host Name
set name=%hostname%

::Current working directory
%CD% – Gives current working directory with no preceding \
%~dp0 – Gets current working directory with a preceding \