[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference decwet::windows-nt

Title:Windows NT
Notice:See note 15.0 for HCL location
Moderator:TARKIN::LIN.com::FOLEY
Created:Thu Oct 31 1991
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:6086
Total number of notes:31449

5784.0. "Batch job to add user accounts?" by STAR::PITCHER (Steve Pitcher/Pathworks for OpenVMS) Fri Mar 07 1997 10:46

    Is there a way to add user accounts in a batch job?
    
    For a school with hundreds of users to add, I want to write up a .BAT
    file, or similar to add user accounts, create user directories, etc. 
    The directories I can probably handle ok.... but is there a CLI
    interface to the user manager?  I tried running MUSRMGR.EXE, but it
    doesn't appear to take command line input.
    
    If it'll do this, in general, where can I find documentation on command
    line interfaces to GUI aplications like this?
    
    Thanks.
    
    -	stp
T.RTitleUserPersonal
Name
DateLines
5784.1TARKIN::LINBill LinFri Mar 07 1997 11:153
    re: STAR::PITCHER
    
    ADDUSERS.EXE in the NT resource kit?
5784.2free CD-ROM from Microsoft does it!ACISS2::SELLISSat Mar 08 1997 21:5612
    In addition the Feb. k-12 tech newsletter for schools mentions
    a free CD-ROM for schools with the purchase of NT 4.0 server.
    It include a utility to import a comma deliminated ascii file
    from a existing schools database to add multiple users in a 
    batch fashion.
    
    I've only read about it and not seen it or tried it, but you
    may want to call Microsoft and check in to it.  The Feb. K-12
    newsletter is on Microsofts Web page, and can be subscribed to
    if you are interested.
    
    
5784.3NET USER?PGREEN::SACKMANJPedalo'ing the InternetTue Mar 11 1997 00:238
    There is a command line interface to USER MANAGER:
    
    c:\> NET USER params
    
    Try NET HELP USER or NET USER /?
    
    	Jon.
    
5784.4Here's a nice place to startSWAM1::FRANK_BRThe Dr. is in.Tue Mar 11 1997 10:23168
    Here's a Batch file I'm working on for a customer (ie: it's specific
    to the way we're implementing NT, Roaming, ...). But it should
    prove to be a good starting place. FYI, the NetAccess program is based
    almost totally on the Windows NT 4.0 SDK sample AclApi that is included in
    VC++. The NetShare program is also based on a Sample from the SDK.
    NetShare is was needed because we need to be able to run the procedure
    remotely and the Standard Net Share does not work for remote machines.
    
    Warning: This is a work in progress (like I was up 'till 3:00 last
    	     night putting it together). It probably has a problem or two.
    
    -------------------------------------------------------------------------
    @echo off> Nul
    rem +++
    rem     AddUser.Bat             Brock Frank             10-Mar-1997
    rem                             Digital Equipment Corp.
    rem
    rem     This procedure is used to create a user account in the current 
    rem     domain and setup their home directory, Share, and profile.
    rem 
    rem     Sytnax:
    rem
    rem     adduser <username> <fullname> <comment> <loginscript> <Domain>
    rem
    rem     HomeDirSystem   file server hosting Users M: Drive (Personal Share)
    rem
    rem     HomeDirPath     Path to root on file server for personal 
    rem                     share (ex: J:\Users) directories.
    rem
    rem     ProfilePath     Path to Template profile
    rem
    rem     ForceProfile    If set, Procedure will copy the specified profile regardless
    rem                     if one exist.
    rem
    rem     Assumtions: 
    rem     
    rem     1) HomeDirPath on file server is shared as Users$
    rem
    rem ---
    rem
    rem     Check that we have all are parameters
    rem
    if @%1==@ goto SyntaxMessage
    if @%2==@ goto SyntaxMessage
    if @%3==@ goto SyntaxMessage
    if @%4==@ goto SyntaxMessage
    rem
    rem     Set defaults
    rem
    if not defined HomeDirSystem set HomeDirSystem=\\Spanky
    if not defined HomeDirPath set HomeDirPath=J:\Users
    if not defined ProfilePath set ProfilePath=\\Spanky\Default$
    if @%5==@ set Domain=%USERDOMAIN%
    rem
    rem     Try to create the users account. 
    rem
    @echo.
    @echo
    --------------------------------------------------------------------
    @echo.
    @echo            Adding %1 user account to domain %Domain%
    @echo.
    NET USER %1 testing /fullname:%2 /comment:%3 /homedir:%HomeDirSystem%\%1$ /profilepath:%HomeDirSystem%\%1$\Profile /scriptpath:SMSLS /Expires:0 /domain /add > NUL
    if %ERRORLEVEL% GTR 0 goto AccountAddFail
    rem
    rem     Create Home Directory
    rem
    :CreateDirectory
    if exist %HomeDirSystem%\Users$\%1\Profile goto DirExist
    @echo  Creating home directory %HomeDirSystem%\Users$\%1. 
    @MkDir %HomeDirSystem%\Users$\%1\Profile
    if %ERRORLEVEL% GTR 0 goto HomeDirFail
    :DirExist
    @Echo  Home directory already exist. Continuing...
    rem
    rem     Grant permissions to User on FileSystem
    rem
    :GrantDirPerms
    @echo  Granting Permissions to %1 on home directory tree
    %HomeDirSystem%\%1 
    cacls %HomeDirSystem%\Users$\%1 /T /E /P %Domain%\%1:F "%Domain%\Domain Admins:F" /R Everyone /C > nul
    if %ERRORLEVEL% GTR 1 goto PermFail
    @net use %HomeDirSystem%\%1$  > NUL
    if %ERRORLEVEL% LEQ 1 goto ShareExist
    @echo  Sharing Users Home Directory
    @netshare %HomeDirPath%\%1 %1$ %Domain%\%1 %HomeDirSystem%
    if %ERRORLEVEL% GTR 1 goto ShareHomeDirFail
    goto SetAccess
    :ShareExist
    @echo  Share already exist. Continuing...
    @echo  Granting Permissions to %Domain%\Domain Admins on Share %HomeDirSystem%\%1$.
    @Net Use %HomeDirSystem%\%1$ /d > NUL
    :SetAccess
    NetAccess %HomeDirSystem%\%1$ /Grant "%Domain%\DOMAIN ADMINS"
    if %ERRORLEVEL% GTR 1 goto PermFail
    @echo  Granting Permissions to %1 on Share %HomeDirSystem%\%1$.
    NetAccess %HomeDirSystem%\%1$ /Grant %Domain%\%1 
    if %ERRORLEVEL% GTR 1 goto PermFail
    @echo  Revoking Permissions to Everyone on Share %HomeDirSystem%\%1$.
    NetAccess %HomeDirSystem%\%1$ /revoke EVERYONE  
    if %ERRORLEVEL% GTR 1 goto PermFail
    @Echo  Coping Template profile %ProfilePath% to
    %HomeDirSystem%\%1$\Profile.
    rem
    rem ******** Add Check for ProfileForce flag **********
    rem
    xcopy /s /v /e %ProfilePath% %HomeDirSystem%\%1$\Profile > NUL
    if %ERRORLEVEL% GTR 1 goto ProfileFail
    @Echo.
    @Echo                   Successfully Created %1 ...
    goto exit
    :ProfileFail
    @Echo.
    @Echo   Failed to copy profile %ProfilePath% to
    %HomeDirSystem%\%1$\Profile.
    @echo.
    goto exit
    
    :PermFail
    @Echo.
    @Echo   Failed to set share permissions for %DirRoot%\%1
    @echo.
    goto exit
    :ShareHomeDirFail
    @echo.
    @echo   Failed to share users home directory.
    @echo.
    goto exit
    :HomeDirFail
    @echo.
    @echo   Failed to create users home directory.
    @echo.
    goto exit
    :AccountAddFail
    @echo.
    @echo   NET USER command failed for unknown reason. The error message Proceeds this.
    @echo   Continuing...
    @echo.
    goto CreateDirectory
    :SyntaxMessage
    @echo.
    @echo     adduser username fullname comment loginscript domain
    @echo.
    @Echo     Domain will default to %USERDOMAIN%.
    @Echo.
    @Echo     The Following Environment Variables are used:
    @Echo.
    @Echo     HomeDirSystem   file server hosting Users M: Drive (Personal Share).
    @Echo                     User Executing this procedure must have Admins rights on Server.
    @Echo.
    @Echo     HomeDirPath     Path to root on file server for personal 
    @Echo                     share (ex: J:\Users) directories.
    @Echo.
    @Echo     ProfilePath     Path to Template profile
    @Echo.
    @Echo     ForceProfile    If set, Procedure will copy the specified profile regardless
    @echo                     if one exist
    @echo.
    @Echo     Assumptions: 
    @Echo.
    @Echo     1) HomeDirPath on file server is shared as Users$
    @Echo.
    goto Exit
    :Exit
    @echo.
    @echo
    ------------------------------------------------------------------------
    
5784.5Thanks.STAR::PITCHERSteve Pitcher/Pathworks for OpenVMSTue Mar 11 1997 13:384
    Thanks all.  That's all good looking stuff.  I'm going to check out
    each of these replies.
    
    -	stp