Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Batch file to create a new user

Posted on 2010-08-26
9
Medium Priority
?
704 Views
Last Modified: 2012-05-10
How do I right a batch file that creates a profile for one of the domain users on the local machine? Win XP OS
0
Comment
Question by:iamdieter
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 4

Expert Comment

by:Geek_Nabil
ID: 33532522
NET USER
[username [password | *] [options]] [/DOMAIN]
         username {password | *} /ADD [options] [/DOMAIN]
         username [/DELETE] [/DOMAIN]
         username [/TIMES:{times | ALL}]

NET USER creates and modifies user accounts on computers. When used
without switches, it lists the user accounts for the computer. The
user account information is stored in the user accounts database.

username     Is the name of the user account to add, delete, modify, or
             view. The name of the user account can have as many as
             20 characters.
password     Assigns or changes a password for the user's account.
             A password must satisfy the minimum length set with the
             /MINPWLEN option of the NET ACCOUNTS command. It can have as
             many as 14 characters.
*            Produces a prompt for the password. The password is not
             displayed when you type it at a password prompt.
/DOMAIN      Performs the operation on a domain controller of
             the current domain.
/ADD         Adds a user account to the user accounts database.
/DELETE      Removes a user account from the user accounts database.

Options      Are as follows:

   Options                    Description
      --------------------------------------------------------------------
   /ACTIVE:{YES | NO}         Activates or deactivates the account. If
                              the account is not active, the user cannot
                              access the server. The default is YES.
   /COMMENT:"text"            Provides a descriptive comment about the
                              user's account.  Enclose the text in
                              quotation marks.
   /COUNTRYCODE:nnn           Uses the operating system country code to
                              implement the specified language files for a
                              user's help and error messages. A value of
                              0 signifies the default country code.
   /EXPIRES:{date | NEVER}    Causes the account to expire if date is
                              set. NEVER sets no time limit on the
                              account. An expiration date is in the
                              form mm/dd/yy(yy). Months can be a number,
                              spelled out, or abbreviated with three
                              letters. Year can be two or four numbers.
                              Use slashes(/) (no spaces) to separate
                              parts of the date.
   /FULLNAME:"name"           Is a user's full name (rather than a
                              username). Enclose the name in quotation
                              marks.
   /HOMEDIR:pathname          Sets the path for the user's home directory.
                              The path must exist.
   /PASSWORDCHG:{YES | NO}    Specifies whether users can change their
                              own password. The default is YES.
   /PASSWORDREQ:{YES | NO}    Specifies whether a user account must have
                              a password. The default is YES.
   /LOGONPASSWORDCHG:{YES|NO} Specifies whether user should change their
                              own password at the next logon.The default is NO.
   /PROFILEPATH[:path]        Sets a path for the user's logon profile.
   /SCRIPTPATH:pathname       Is the location of the user's logon
                              script.
   /TIMES:{times | ALL}       Is the logon hours. TIMES is expressed as
                              day[-day][,day[-day]],time[-time][,time
                              [-time]], limited to 1-hour increments.
                              Days can be spelled out or abbreviated.
                              Hours can be 12- or 24-hour notation. For
                              12-hour notation, use am, pm, a.m., or
                              p.m. ALL means a user can always log on,
                              and a blank value means a user can never
                              log on. Separate day and time entries with
                              a comma, and separate multiple day and time
                              entries with a semicolon.
   /USERCOMMENT:"text"        Lets an administrator add or change the User
                              Comment for the account.
   /WORKSTATIONS:{computername[,...] | *}
                              Lists as many as eight computers from
                              which a user can log on to the network. If
                              /WORKSTATIONS has no list or if the list is *,
                              the user can log on from any computer.

NET HELP command | MORE displays Help one screen at a time.
0
 
LVL 3

Expert Comment

by:madhubabus
ID: 33532634
try this code

strComputer = "your computer name"
Set colAccounts = GetObject("WinNT://" & strComputer & "")
Set objUser = colAccounts.Create("user", "Admin2")
objUser.SetPassword "Test@123"
objUser.SetInfo
0
 

Author Comment

by:iamdieter
ID: 33532748
So does my batch file need to look like this? These are the logon credentials that must be used: username: test
password: P@$$word
domain: abc
---------------------

NET USER
[test [P@$$word | *] [options]] [/abc]
        username {P@$$word | *} /ADD [options] [/abc]
       
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 

Author Comment

by:iamdieter
ID: 33532764
@madhubabus

This will be a batch file that runs on all pc's on my network.
0
 
LVL 4

Expert Comment

by:Geek_Nabil
ID: 33532858
Let me get this straight, for example domain user john, logs-on a computer. As soon as he logs-on, a local user named john will be created.
So the basically creating domain users on the local machines?

Is that what you are trying to do?
0
 

Author Comment

by:iamdieter
ID: 33533114
No, domain user John logs-on, but runs the batch file and domain user paul's profile gets created on the same computer without user Paul physically logging on to the computer.
0
 
LVL 14

Accepted Solution

by:
Ben Personick (Previously QCubed) earned 2000 total points
ID: 33539210
@iamdieter (BTW: Nice SNL/Mike Meyer's reference):

I believe what you are asking is this:

You want a user's profile to be created on every machine so the user will not have to load the profile on the first time they log on, then go about and change settings, correct?


The way in which you do this is to COPY the user profile from the machine where the user had been logged on, to every machine in the network.

If you only care about windows settings you only need a few files, if you care about application settings and the like you will want most of the user's profile and you might as well just take the whole thing.

To do this when 'JOHN' logs in John should be an administrator on the machine where this will be copied to.
First, we do a bit of prep work to create the profile fresh, or grab an existing profile (see below)

  1. Stage a copy of the profile by having Paul log into a single machine using his domain user name and password and set things up how he wants them (or use an existing machine Paul already uses.)
  2. Then reboot the machine just to be 100% certain that Paul's user profile has no locks against it.
  3. Now log onto the machine as a DIFFERENT User than Paul, who is an Administrator on the local machine.
  4. Navigate to C:\Documents and Settings, look for a folder with Paul's user name.  Copy this entire folder to a file server where John will have access (we'll call it \\Fileserver1\Share$\Paul'sUsername)
Next, assuming that John's domain account is an administrator on every machine you need the profile created on, we can run the attached script by adding it to his logon script in your domain.

:: Script Name: CopyProfile.bat
ECHO OFF
::Set the Profile Name to be Copied
SET "ProfileName=PaulsUsername"

:: Notice DO NOT PUT A TRAILING "\" on the Source
SET "Source=\\FileServer1\Share$\%ProfileName%"

:: Automatically Set the correct Path for the Destination.
CALL SET "Destination=%%UserProfile:%UserName%=%%%ProfileName%"

XCopy "%Source%" "%Destination%" /E /C /I /Q /H /R /Y /Z

ECHO Copy Complete!

Open in new window

0
 

Author Comment

by:iamdieter
ID: 33539473
Hi QCubed

This is exactly what I was looking for. I save the profile on a shared drive on the server and copied from there. The only problem was that i had to enter the password. This batch file does not require you to add the password, which makes it perfect.

Thanks for your help
0
 
LVL 14
ID: 33540847
Great!  Glad I was able to be of assistance!
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question