Saturday, September 17, 2011

Useful Script for Network Backup

Here is an interesting backup script from one of our customers. It requires an external tool to be run, but allows to perform backup from many computers over the network:
@echo off
@set dircmd=/b
set folder=Documents and Settings
for /F "tokens=1 usebackq delims==\ " %%i IN (`net view`) DO (
echo Start copying %%i...
start /wait /min /high robocopy.exe "\\%%i\C$" X:\backup\uim\%%i\C *.doc *.xls /S /R:1 /W:120 /XD RECYCLER batmail "Application Data" game* "Default User" "ÿáí½«¡δ" "Local Settings" windows winxp wxp w2k winnt "Program Files" Temp NetHood Recycled Install "The Bat!" "System Volume Information" readme /XF "~*.*" readme /XJ /XO
start /wait /min /high robocopy.exe "\\%%i\D$" X:\backup\uim\%%i\D *.doc *.xls /S /R:0 /W:1 /XD RECYCLER SCANJET batmail "Application Data" game* "Default User" "ÿáí½«¡δ" "Local Settings" Temp Recycled Install readme/XF "~*.*" "System Volume Information" readme /XJ /XO

Wednesday, September 14, 2011

Creating a New User Account via Batch Files

Q: I need to write a batch file that creates a new user account. The account's name and password should be passed as parameters like batch_file name pass. What should I do?

A:
Start Dr.Batcher and type the following script:

@echo off
if "%~2"=="" goto error
if "%~1"=="" goto error
net user %~1 %~2 /add
goto :EOF
:error
echo Usage: %~0 user password

That's all!

Friday, September 9, 2011

Removing Unnecessary Trailing Spaces

Imagine: we have a variable with some string data, and we have to remove unnecessary spaces from the end of this variable. The code below shows how to solve this problem:

@echo off
setlocal
set "a=111 222 "

:loop
set /a n+=1
for /f "tokens=%n%" %%i in ("%a%") do (
if not "%%i"=="" set b=%b%%%i && goto:loop
)

set a=%b:~0,-1%
set b=
echo "%a%"


Of course, you have to change this code a bit before using it. You can do it with the help of our award-winning batch files editor. Hope you'll find this example useful.

Translate