Batch Script Net User
Net User
The net user command is used to:
- View the details of a particular user account.
- Add a user account.
- Delete a user’s account.
- Modify a user’s account.
net user [<UserName> {<Password> | *} [<Options>]] [/domain]
net user [<UserName> {<Password> | *} /add [<Options>] [/domain]]
net user [<UserName> [/delete] [/domain]]
where:
<UserName>
specifies 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. Type an asterisk (*
) to produce a prompt for the password. The password is not displayed when the user types it at the password prompt./domain
performs the operation on the domain controller in the computer's primary domain.<Options>
specifies a command-line option. Refer to the next table for descriptions of the command-line option syntax.
Command-line option syntax | Description |
---|---|
/active:{no | yes} | Enables or disables the user account. If the user account is not active, the user cannot access resources on the computer. The default is yes (that is, active). |
/comment:"<Text>" | Provides a descriptive comment about the user's account. This comment can have as many as 48 characters. Enclose the text in quotation marks. |
/countrycode:<NNN> | Uses the operating system Country/Region codes to implement the specified language files for a user's Help and error messages. A value of 0 signifies the default Country/Region code. |
/expires:{{<MM/DD/YYYY> | <DD/MM/YYYY> | <mmm,dd,YYYY>} | never} | Causes the user account to expire if you specify the date. Expiration dates can be in [MM/DD/YYYY], [DD/MM/YYYY], or [mmm,dd,YYYY] formats, depending on the Country/Region code. Note that the account expires at the beginning of the specified date. For the month value, you can use numbers, spell it out, or use a three-letter abbreviation (that is, Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec). You can use two or four numbers for the year value. Use commas or slashes to separate parts of the date. Do not use spaces. If you omit <YYYY> , the next occurrence of the date (that is, according to your computer's date and time) is assumed. For example, the following entries are equivalent if entered between Jan. 10, 1994, and Jan. 8, 1995: jan,9 1/9/95 january,9,1995 1/9 |
/fullname:"<Name>" | Specifies a user's full name rather than a user name. Enclose the name in quotation marks. |
/homedir:<Path> | 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. |
/profilepath:[<Path>] | Sets a path for the user's logon profile. This path points to a registry profile. |
/scriptpath:<Path> | Sets a path for the user's logon script. <Path> cannot be an absolute path. <Path> is relative to %systemroot%\System32\Repl\Import\Scripts . |
/times:{<Day>[<-Day>][,<Day>[-<Day>]],<Time>[-<Time>][,<Time>[-<Time>]][;] | all} | Specifies the times that users are allowed to use the computer. <Time> is limited to one-hour increments. For the <Day> values, you can spell out the names of the days or use abbreviations (that is, M,T,W,Th,F,Sa,Su). You can use 12-hour or 24-hour notation for hours. If you use 12-hour notation, use AM and PM, or A.M. and P.M. The value all means a user can always log on. A null value (blank) means a user can never log on. Separate day and time with commas, and separate units of day and time with semicolons (for example, M,4AM-5PM;T,1PM-3PM). Do not use spaces when you designate times. |
/usercomment:"<Text>" | Specifies that an administrator can add or change the "User comment" for the account. Enclose the text in quotation marks. |
/workstations:{<ComputerName>[,...] | *} | Lists as many as eight workstations from which a user can log on to the network. Separate multiple entries in the list with commas. If /workstations has no list or if the list is an asterisk (* ), users can log on from any computer. |
- When using
net users
without parameters, a list of user accounts on the computer is displayed. You can also typenet users
. - A password must meet the minimum password length value set with the
net accounts /minpwlen
command. A password can contain up to 127 characters.
Example
The following example displays a list of all user accounts for the local computer:
net user
The following example displays information about the user account tomnolan:
net user tomnolan
The following example adds a user account for a user whose full name is Tom Nolan and whose user account name is tomn, with logon rights from 8 A.M. to 5 P.M., Monday through Friday (no spaces in time designations), a mandatory password (LvA1^g0B), and the user's full name:
net user tomn LvA1^g0B /add /passwordreq:yes /times:monday-friday,8am-5pm /fullname:"Tom Nolan"
The following example sets the logon time (8 A.M. to 5 P.M.) for user rayanrain by using 24-hour notation:
net user rayanrain /time:M-F,08:00-17:00
The following example sets the logon time (8 A.M. to 5 P.M.) for rayanrain by using 12-hour notation:
net user rayanrain /time:M-F,8AM-5PM
The following example specifies logon hours of 4 A.M. until 5 P.M. on Monday, 1 P.M. until 3 P.M. on Tuesday, and 8 A.M. until 5 P.M. Wednesday through Friday for johnsmith:
net user johnsmith /time:M,4AM-5PM;T,1PM-3PM;W-F,8:00-17:00