reganetal Posted January 3, 2006 Share Posted January 3, 2006 (edited) I do not want to add users via NET USER or OOBEINFO.INI methods. I want to add them later via a batch file.I am getting really frustrated. I have been working on this batch file for hours and I can't seem to make it right. It seems like everything I do creates another error. I am going in circles. grrrr@Echo OffEcho.Title Add New UsersEcho.set path="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion"set /p addusers=Add New Users? Y/n: if "%addusers%"=="y" (goto proceed)Echo.Echo Note: The first added user will be set as default userset count=1:ProceedEcho.:Nameset /p name=User Name? if "%name%"=="" Echo. & Echo Invalid Entry & Echo. & goto NameEcho.:UsertypeEcho User Groups:Echo.Echo 1. Administrators: Have complete and unrestricted access to the computer/domain.Echo 2. Power Users: Possess most administrative powers with some restrictions. Echo 3. Users: Prevented from making accidental or intentional system-wide changes. Echo.set /p choice=User Group? if "%choice%"=="" Echo. & Echo Invalid Entry & Echo. & goto usertypeif %choice% gtr 3 Echo. & Echo Invalid entry & Echo. & goto usertypeif %choice%==1 set usertype=administrators if %choice%==2 set usertype=power usersif %choice%==3 set usertype=users Echo.:Passwordset /p pass=Password? if "%pass%"=="" Echo. & Echo Invalid Entry & Echo. & goto passwordEcho.net user %name% %pass% /addnet localgroup %usertype% %name% /addEcho. if "%count%"=="1" CALL Defaultautologon.cmdset /A count=%count%+1set /p addmore=Add More Users? Y/n: if "%addmore%"=="y" GOTO Proceed Echo.Echo Finished Adding Usersnet accounts /maxpwage:unlimitedPING 1.1.1.1 -n 1 -w 3000 >NULuseraccounts.cmdecho REG ADD %path% /v DefaultUserName /d %name% else echo REG ADD %path% /v DefaultPassword /d %pass% else Echo.set /p autologon=Allow %name% to Autologon? Y/n: if "%autologon%"=="" Echo. & Echo Invalid Entry goto setdefaultif %autologon%==y Echo REG ADD %path% /v AutoAdminLogon /d 1GOTO :EOFDefaultautologon.cmdThanks Regan Edited January 3, 2006 by reganetal Link to comment Share on other sites More sharing options...
gunsmokingman Posted January 3, 2006 Share Posted January 3, 2006 Read this thread it may help youUser Account Thread Batch Link to comment Share on other sites More sharing options...
Yzöwl Posted January 5, 2006 Share Posted January 5, 2006 Well, the first thing I noticed was that your %path% variable, should not be named path and also points to the incorrect key. The %choice% variable would also be better renamed too!There is also very little error trapping which could cause many unforseen problems.Try using something like the example below, which is also attached.@ECHO OFF&SETLOCAL ENABLEEXTENSIONS&TITLE Account CreationSET /P TOADD= WOULD YOU LIKE TO ADD ADDITIONAL USERS (Y/N)? SET TOADD=%TOADD:~0,1%IF /I '%TOADD% NEQ 'Y ENDLOCAL&GOTO :EOFSET REGKEY="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"SET CNT1=0CLS&TITLE Account NameECHO/ NOTE&ECHO/ ¯¯¯¯&ECHO/&ECHO/ The First User added will be set as your Default User&ECHO/&ECHO/ It will have Administrator Account privileges&ECHO/:ADDNAMEFOR %%? IN (NAME TIPE UTYPE PASS) DO (SET %%?=)ECHO/ PLEASE ENTER YOUR CHOSEN ACCOUNT (LOGIN) NAMESET /P NAME=IF "%NAME%" EQU "" ECHO/ Blank Names are not accepted!&&GOTO ADDNAMEECHO/&ECHO/ THE ACCOUNT NAME YOU HAVE CHOSEN IS&ECHO/&ECHO/ %NAME%&ECHO/&ECHO/ WOULD YOU LIKE TO CHANGE IT (Y/N)?SET /P ANSR=SET ANSR=%ANSR:~0,1%IF /I %ANSR% NEQ N GOTO ADDNAMENET USER|FIND /I " %NAME% ">NUL 2>&1&&(ECHO/&ECHO/ USER %NAME% ALREADY EXISTS&ECHO/&ECHO/ PLEASE TRY AGAIN&ECHO/&GOTO ADDNAME)CLS&TITLE Account TypeIF %CNT1% EQU 0 SET UTYPE=Administrator&GOTO ADDPASS:ADDTYPEECHO/ YOU CAN NOW CHOOSE AN ACCOUNT TYPE FOR %NAME%&ECHO/&ECHO/ Account Types&ECHO/ ¯¯¯¯¯¯¯¯¯¯¯¯¯&ECHO/ECHO/ 1. Computer Administrator (less secure)&ECHO/ Has unrestricted access to the computer&ECHO/ECHO/ 2. Power User (more secure)&ECHO/ Has only some restricted access to the computer&ECHO/ECHO/ 3. Normal User (recommended)&ECHO/ Has restricted access to the computer&ECHO/SET /P TIPE= Please enter your an account type for %NAME% (1/2/3): SET TIPE=%TIPE:~0,1%ECHO/%TIPE%|FINDSTR/R "[1-3]">NUL||GOTO ADDTYPEIF %TIPE% LSS 2 SET UTYPE=AdministratorIF %TIPE% EQU 2 SET UTYPE=Power UserIF %TIPE% GTR 2 SET UTYPE=UserECHO/&ECHO/ THE ACCOUNT TYPE YOU HAVE CHOSEN IS&ECHO/&ECHO/ %UTYPE%&ECHO/&ECHO/ WOULD YOU LIKE TO CHANGE IT (Y/N)?SET /P ANSR=SET ANSR=%ANSR:~0,1%IF /I %ANSR% NEQ N GOTO ADDTYPECLS&TITLE Account Password:ADDPASSECHO/ PLEASE ENTER A PASSWORD FOR %NAME%&ECHO/ECHO/ NOTE&ECHO/ ¯¯¯¯&ECHO/&ECHO/ Passwords MUST contain a minimum of 6 characters&ECHO/SET /P PASS=IF "%PASS%" EQU "" ECHO/&ECHO/ Blank Passwords are not accepted!&ECHO/&GOTO ADDPASSECHO/%PASS%|FINDSTR/R "[^a-z,0-9,_,-]">NUL&&(ECHO/&ECHO/ Some of the characters you used were not acceptable!&ECHO/&GOTO ADDPASS)ECHO/&ECHO/ THE PASSWORD YOU HAVE CHOSEN FOR %NAME% IS&ECHO/&ECHO/ %PASS%&ECHO/&ECHO/ WOULD YOU LIKE TO CHANGE IT (Y/N)?SET /P ANSR=SET ANSR=%ANSR:~0,1%IF /I %ANSR% NEQ N GOTO ADDPASSSET CNT2=0:LOOPSET /A CNT2+=1CALL SET V=%%PASS:~0,%CNT2%%%IF "%V%" NEQ "%PASS%" GOTO LOOPIF %CNT2% LSS 6 ECHO/ Minimum Password length is 6 characters&ECHO/&ECHO/ Please try again!&ECHO/&GOTO ADDPASSCLS&TITLE Adding AccountNET USER "%NAME%" "%PASS%" /addNET LOCALGROUP "%UTYPE%s" "%NAME%" /addIF %CNT1% EQU 0 CALL :DEFLOGSET /P ADDMORE= WOULD YOU LIKE TO ADD ANOTHER USER (Y/N)? SET %ADDMORE%=%ADDMORE:~0,1%IF /I %ADDMORE% EQU Y SET /A CNT1+=1&CLS&GOTO ADDNAMEECHO/&ECHO/ FINISHED ADDING USERS&ECHO/ ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯&ECHO/NET ACCOUNTS /maxpwage:unlimitedPING -n 4 127.0.0.1>NUL&ENDLOCAL&GOTO :EOF:DEFLOGREG ADD %REGKEY% /V DefaultUserName /D "%NAME%" /FREG ADD %REGKEY% /V DefaultPassword /D "%PASS%" /FSET /P AUTLOG= Would you like %NAME%s Account to Logon Automatically (Y/N)? SET AUTLOG=%AUTLOG:~0,1%IF /I %AUTLOG% EQU Y REG ADD %REGKEY% /V AutoAdminLogon /D 1 /FGOTO :EOFAddUser.zip Link to comment Share on other sites More sharing options...
reganetal Posted January 6, 2006 Author Share Posted January 6, 2006 Yzowl,This is great! I read through the script and there is one thing I just dont understand CALL SET V=%%PASS:~0,%CNT2%%%It seems like this part of the code counts how many characters are in %pass%. Am I correct? But I am really unsure how it does this.ECHO/ NOTE&ECHO/ ¯¯¯¯&ECHO/&ECHO/ The First User added will be set as your Default User&ECHO/&ECHO/ It will have Administrator Account privileges&ECHO/Also, I noticed you wrote a lot of @echo/ ... is the / some kind of carriage return? And how do you get the upper ____ to make >>> characters? When I type that or paste it into my cmd window I get an underline.Lastly, maybe I misunderstand the default user part. When I run this script on my computer to test it out, it changes my settings so that "users must enter a user name and password to use this computer" is unchecked. Thats not what I want to do. I want each user to be required to login under their own name. I am using win2k right now so this may work out different on XP I am unsure. Thanks for all your help.Regan Link to comment Share on other sites More sharing options...
Yzöwl Posted January 6, 2006 Share Posted January 6, 2006 @ reganetal%PASS:~0,1% would expand the PASS variable, and then use only the 1st character, (offset 0), of the expanded result.%PASS:~0,2% would expand the PASS variable, and then use only the 1st two characters, of the expanded result.etc...The loop continues until variable V=variable PASS, at this point, CNT2=number of charactersThe & character is replacing the 'carriage return'ECHO/ NOTE&ECHO/ ¯¯¯¯&ECHO/&ECHO/ The First User added will be set as your Default User&ECHO/&ECHO/ It will have Administrator Account privileges&ECHO/is the same asECHO/ NOTEECHO/ ¯¯¯¯ECHO/ECHO/ The First User added will be set as your Default UserECHO/ECHO/ It will have Administrator Account privilegesECHO/Finally I have changed no settings other than those you used, they are these linesNET USER "%NAME%" "%PASS%" /addNET LOCALGROUP "%UTYPE%s" "%NAME%" /addNET ACCOUNTS /maxpwage:unlimitedREG ADD %REGKEY% /V DefaultUserName /D "%NAME%" /FREG ADD %REGKEY% /V DefaultPassword /D "%PASS%" /FIF /I %AUTLOG% EQU Y REG ADD %REGKEY% /V AutoAdminLogon /D 1 /FFor testing purposes, just add ECHO/ as shownECHO/NET USER "%NAME%" "%PASS%" /addECHO/NET LOCALGROUP "%UTYPE%s" "%NAME%" /addECHO/NET ACCOUNTS /maxpwage:unlimitedECHO/REG ADD %REGKEY% /V DefaultUserName /D "%NAME%" /FECHO/REG ADD %REGKEY% /V DefaultPassword /D "%PASS%" /FIF /I %AUTLOG% EQU Y ECHO/REG ADD %REGKEY% /V AutoAdminLogon /D 1 /F Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now