[Settings_Begin]
BatchSettings.Delimiter=,
SET AccountName=%col1% // %AccountName% instead of %col1% below = easier to change column
Account.FullName=%col2%
SET EmailAddress=%col3%
Account.Password.col=4
//not used Domain=%col5%
SET PIN=%col6%
SET AccountType=%col7%
SET Unit=%col8%
SET Class=%col9%
SET OldUnit=%col10%
SET OldClass=%col11%
SET AccountActive=%col12%
SET AccountDeleted=%col13%
SET AccountNew=%col14%
Account.Description.Col=19
BatchSettings.MarkerCol=20
Account.Expires=Never
Account.Password.MustChange=No
Account.Password.NeverExpires=No
BatchSettings.AddToValidCharSet=äöåÄÖÅéÉü_ // Allow Swedish characters in user and group names
//BatchSettings.Debug=Yes
// Account.Edit setting for %AccountDeleted%<>notdel
SET 1_Account.Expires=2000-01-01
// Account.Edit setting for %AccountActive%<>active
SET 2_Account.Disabled=Yes
// Account.Edit setting for %AccountActive%=active
SET 3_Account.Disabled=No
// Home directory and home directory permissions
SET HomeRoot=w:\users
SET HomeDir=%HomeRoot%\copy(%PIN%,1,2)\%AccountName% // Two first digits in PIN is birth year
SET HomeDirPermissions=%AccountName%:F administrators:F System:F
SET HomeDirMap=%servername%\%AccountName%$
SET ScriptName=netuse.bat
Printer.Template=%StartDir%\SBprintBatch.txt // For Data.PrintRow
// Initialize counters
SET CounterNew=0
SET CounterActive=0
SET CounterInActive=0
SET CounterDelete=0
SET CounterNewUnit=0
SET CounterNewClass=0
// Formatting strings for event logging and error handling
SET StrSrc=SetupBatcher - Script file: "%ScriptName%". Data file: "%DataFile%".
SET StrInfo=%StrSrc% New accounts: %CounterNew%. Set active: %CounterActive%. Set inactive: %CounterInActive%. Deleted: %CounterDelete%. New class: %CounterNewClass%. New unit: %CounterNewUnit%.
SET StrError=%StrSrc% Failed: %LastErrorCommand% - %LastErrorMsg%
// Directories for data files and help utilities
SET DataFilesDir=c:\data
SET DataSectionBackupDir=c:\databck
SET BlatPath=c:\blat
[Settings_End]
[Machines_Begin]
\\EDU8 NT PDC
[Machines_End]
[DataFiles_Begin]
$GetDataFiles POP3, c:\data, pop.servername.se, account, pass,, Delete,, Log, GnuPG, passph
[DataFiles_End]
[Init_Batch_Begin]
Data.Column.ReplaceText 8,/,_
[Init_Batch_End]
[Batch_Begin]
Data.Loop
// New account
IF %AccountNew%=new THEN
Account.Create %AccountName%
Group.Global.Create %AccountType%
Group.AccountAdd Global, %AccountType%, %AccountName%
IF %Class%<> THEN
Group.Global.Create %Class%
Group.AccountAdd Global, %Class%, %AccountName%
ENDIF
// Create home directory, set permissions
DOS md %HomeDir%
DOS echo y| cacls %HomeDir% /G %HomeDirPermissions%
// Create hidden share for each account (only method that works with all OS:es)
DOS net share %AccountName%$=%HomeDir%
// Print password sheet for new user on printer with index 1 (first index is 0)
Data.PrintRow 1
Inc %CounterNew%
Data.NextLoop
ENDIF
// Move account to other unit
IF %OldUnit%<> THEN
// Insert code here - DOS XCOPY / DOS Delete etc.)
Inc %CounterNewUnit%
Data.NextLoop
ENDIF
// Move account to other class
IF %OldClass%<> THEN
Group.Global.Create %Class%
Group.AccountRemove Global,%OldClass%,%AccountName%
Group.AccountAdd Global,%Class%,%AccountName%
Inc %CounterNewClass%
Data.NextLoop
ENDIF
// Mark account for deletion
IF %AccountDeleted%<>notdel THEN
Account.Edit %AccountName%,1
Inc %CounterDelete%
Data.NextLoop
ENDIF
IF %AccountActive%<>active THEN
Account.Edit %AccountName%,2
Inc %CounterInActive%
ELSE
Account.Edit %AccountName%,3
Inc %CounterActive%
ENDIF
Data.Endloop
// Save current data section
Data.Save %DataSectionBackupDir%\%Date=yymmddhhnnsszzz%_%DataFile%
// Delete current data file - if not deleted it will be run twice
DOS del %DataFilesDir%\%DataFile%
//Write to event log
EventLog.Write Information, 772, %StrInfo%
[Batch_End]
[OnError_Batch_Begin]
//Write to event log
EventLog.Write Error, 770, %StrError%
// Create file with error message for email body (quotes around the file name are needed if it contains space characters)
DOS echo %StrError%>"%StartDir%\error.txt"
// Send e-mail
DOS %BlatPath%\blat.exe "%StartDir%\error.txt" -t test@mymail43.com -server mail.mymail43.com -f test@mymail43.com -s "%LocalName% SetupBatcher Error"
[OnError_Batch_End]
[Data_Begin]
accountname,fullname,emailaddress,password,domain,pin,accounttype,unit,class,oldunit,oldclass,accountactive,accountdeleted,accountnew,,,,,,
[Data_End]