# Auto switch/command in batch file



## tigsboy (Nov 25, 2001)

We have a batch file that generates new users in W2K. When the file is run,the command window shows the share is created and the line: 
"Command completed successfully" appears 4 times.
Then the line
" Are you sure (Y/N)" Appears.
This means we manually have to accept each new user.

Can anyone suggest and auto switch or command to automate the process.

Thanks in advance.

:: Script starts here
if "%4" == "" goto usage

:: Set Variables
setlocal
set username=%1
set fullname=%2 %3
set yearlevel=%4
set groupdir=Year%4
set userdir=E:\Students\%4\%username%
REM set skeldir=c:\Admin\%groupdir%
set loginscript=logon%6.bat
set password=%5
set pdc=\\default

:: Confirm account details
rem echo The current details for the account to be created are as follows: 
rem echo.
rem echo username: %username%
rem echo fullname: %fullname%
rem echo yearlevel: %yearlevel%
rem echo userdir: %userdir%
REM echo skeldir: %skeldir%
rem echo loginscript: %loginscript%
rem echo password: %password%
rem echo pdc: %pdc%
rem echo.
rem echo Is this correct? Press Ctrl-C to abort or
rem pause

REM :: Error conditions (some very primitive)
rem Skeleton directory doesn't exist
REM if not exist %skeldir%\nul goto skeldirfail

rem Userdirectory already exists
if exist %userdir%\nul goto userdirfail

rem Group directory doesn't exist - you may want to remove this part.
REM ::if not exist c:\admin\%yearlevel%\nul goto groupdirfail

rem Check that there is a login.bat file
REM if not exist c:\winnt\system32\repl\import\scripts\%loginscript% goto loginscriptfail

:: Here is the fun stuff...
mkdir %userdir%
REM xcopy %skeldir% %userdir% /e /i /q /h
REM move %userdir%\base.bat %userdir%\%username%.bat
net share %username%$=%userdir% /users:4 /remark:"Home directory of %fullname%"
net user %username% %password% /fullname:"%fullname%" /homedir:%pdc%\%username%$ /profilepath:%LOGONSERVER%\PROFILES\yr%6.man /scriptpath:%loginscript% /time:M-F,06:00-18:00 /comment:"%yearlevel%" /add /domain 
if errorlevel 1 goto create_error
net group "%yearlevel%" %username% /add /domain
net group "Students" %username% /add /domain
net group "Proxy_Student" %username% /add /domain
cacls %userdir% /t /g %username%:c "Domain Admins":f
echo Account created.
goto end

:usage
echo.
echo Adduser.bat - Add user to NT 4 domain
echo Usage: adduser username firstname surname Yearlevel Password YR(login.bat)
echo e.g. adduser fsmith Fred Smith Sales adg4a3(1 7
echo.
echo.
goto end


----------



## coderitr (Oct 12, 2003)

I'm guessing that the confirmation prompt is coming from the "net user" command. Have you tried /Y on that command? What I've seen with other "net ..." commands is that while undocumented in the /? help text, the /Y switch is an auto-confirmation.


----------



## tigsboy (Nov 25, 2001)

We found that when the confirmation command comes up in the dos window asking for a y/n, if we simply pressed enter, none of the security groups were entered, only the default EVERYONE. We assume that is because we were not actually accepting the CALCS command. 
The same result happens if we append a /Y to the end of the calcs line, no security groups!
We have tried putting a /y right after the CALCS command but it tells us it is not a supported param of CALCS.

Thanks for the suggestion, any other hints.


----------



## tigsboy (Nov 25, 2001)

Solved
It was simlpy a matter of changing to XCACLS from CACLS and adding the /y switch. Seems cacls doesn't support it and xcacls does.
Cheers


----------

