net - Manage Users, Services, and Shares
Table of Contents
The net command lets you manage user accounts, groups, services, shared folders, and network connections in Windows from one place. You add a subcommand after net to choose what to do.
It has been around for a long time and often appears in batch files for environment setup and common tasks such as restarting a service.
Basic syntax of net
net <subcommand> [arguments]
| Subcommand | Purpose |
|---|---|
net user | Show, add, change, and delete user accounts |
net localgroup | Show local groups and add or remove members |
net start | List running services and start a service |
net stop | Stop a service |
net share | Show, create, and remove shared folders |
net use | Map and disconnect network drives |
net helpmsg | Show the meaning of an error number |
Adding users, stopping services, and similar operations fail unless Command Prompt is running as administrator. If you see “System error 5 has occurred. Access is denied.”, run Command Prompt as administrator and try again.
Work with user accounts (net user)
Show the user list and details
net user
This lists the local users on this computer. Specify a user name to see details such as whether the account is active, the last logon, and group membership.
net user taro
Add and delete users
net user taro * /add
net user taro /delete
With *, you enter the password interactively. The characters you type are not displayed.
You can write something like net user taro password /add, but then the password remains on screen and in the batch file as plain text. Use * when running it by hand.
Disable and enable a user
You can make an account unable to sign in without deleting it.
net user taro /active:no
net user taro /active:yes
By default, net user targets local accounts on this computer. To work with accounts in a domain environment, add /domain.
Work with groups (net localgroup)
net localgroup
net localgroup Administrators
The first line lists the local groups, and the second lists the members of the Administrators group. Use /add and /delete to add or remove users.
net localgroup Administrators taro /add
net localgroup Administrators taro /delete
Group names such as Administrators can have different names depending on the Windows display language. Run net localgroup on your own system and check the actual name before using it.
Start and stop services (net start / net stop)
net start with no arguments lists the services that are currently running.
net start
Specify a service name to start that service. Use net stop to stop it.
net stop spooler /y
net start spooler
You can specify either the service name, such as spooler, or the display name, such as "Print Spooler". If the display name contains spaces, enclose it in double quotation marks.
net start and net stop wait until the service has finished starting or stopping before returning. sc start and sc stop, on the other hand, return as soon as the request is sent. When a batch file needs to stop a service before moving on, net stop is the simpler choice. Use the sc command for detailed service settings and status checks.
Work with shared folders (net share)
net share
This lists the folders shared from this computer. Shares ending in $, such as C$, ADMIN$, and IPC$, are created automatically for administrative purposes.
To share a folder, write the following.
net share Data=C:\Data /grant:everyone,read
With /grant:user,permission, you specify the user to allow and the permission (read, change, or full). To remove a share, add /delete.
net share Data /delete
/delete removes only the share setting. The original folder and files remain.
Work with network drives (net use)
net use
This shows the current connections. To disconnect all of them, do the following.
net use * /delete /y
Mapping network drives and keeping the connection after a restart are covered in detail in the related article.
Look up the meaning of an error number (net helpmsg)
When a net command returns a numbered error such as “System error 5 has occurred.”, you can check its meaning with net helpmsg.
net helpmsg 5

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超入門

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
Batch file example
This example restarts a service and shows a message if it fails.
@echo off
net stop spooler /y
net start spooler
if errorlevel 1 (
echo Failed to start the service. Check that you are running as administrator.
exit /b 1
)
echo Restarted.
A net command returns exit code 0 on success and a nonzero value on failure, so you can detect failure with if errorlevel 1.
PowerShell equivalents
The net command remains for backward compatibility, and in new scripts you can also use PowerShell cmdlets.
| Goal | net command | PowerShell |
|---|---|---|
| List users | net user | Get-LocalUser |
| Add a user | net user username * /add | New-LocalUser |
| Disable a user | net user username /active:no | Disable-LocalUser |
| Add a member to a group | net localgroup group user /add | Add-LocalGroupMember |
| Start a service | net start service | Start-Service |
| Stop a service | net stop service | Stop-Service |
| List shared folders | net share | Get-SmbShare |
See the related article for how to call PowerShell from Command Prompt.
Summary
| Goal | Command |
|---|---|
| List users | net user |
| Add a user | net user username * /add |
| Disable a user | net user username /active:no |
| Add to the Administrators group | net localgroup Administrators username /add |
| Stop or start a service | net stop / net start |
| Share a folder | net share name=path /grant:... |
| Look up an error number | net helpmsg number |