Windows

Sample of Net View command

In a GUI world, it's easy to forget that you can still perform some very powerful commands from your server's command prompt. In this Daily Drill Down, Brien Posey shows you one of the most powerful commands—the Net command.

If you’ve read many of my Daily Drill Downs, you’ve probably noticed that I tend to use the command prompt excessively. Although I’ve often been ridiculed for using the command prompt in a graphical environment, commands do have their place. One of the biggest uses for commands is in batch files. You can use batch files to automate certain network-related tasks.

Of course, doing so would be very difficult, if not impossible, if you were limited to the basic DOS command set. Fortunately, Windows NT Server and Windows 2000 Server provide an extended set of commands you can use to automate network-related tasks. One such command is the Net command. In this Daily Drill Down, I’ll discuss the Net command. I’ll also show you what the Net command can be used for and explain the syntax behind its various uses.

What is the Net command?
Before you can understand what the Net command is, you must understand a little bit about the way that networks used to work. In the days of DOS and Windows 3.1 (not Windows for Workgroups), Windows had very little built-in network support. The majority of the network functions had to be performed at the DOS level. A typical process was to load the network redirector through the Autoexec.bat file. Once the redirector was loaded, the user could interact with the network. This is where the Net command came into play. The Net command was basically a single command that could be used to accomplish a wide variety of network-related tasks, such as logging in or mapping a network drive.

Over the years, the Net command has become obsolete for anything other than automation purposes. Almost every task that can be performed through the Net command can also be accomplished through the Graphical User Interface (GUI). In spite of this fact, the Net command has evolved over the years. Extra functionality has been added to the command, and the Net command is still supported to this day.

Now that you know the history of the Net command and some of its uses, let’s examine the command in detail. In the sections that follow, I’ll discuss each of the Net command’s functions. The Net command is always a two-part command. The Net commands you can issue include the following:
  • Net Accounts
  • Net Computer
  • Net Config
  • Net Continue
  • Net File
  • Net Group
  • Net Help
  • Net Helpmsg
  • Net Localgroup
  • Net Name
  • Net Pause
  • Net Print
  • Net Send
  • Net Session
  • Net Share
  • Net Start
  • Net Statistics
  • Net Stop
  • Net Time
  • Net Use
  • Net User
  • Net View

Net Accounts
The Net Accounts command provides a method for displaying the account policies for the domain. You can see a sample of the Net Accounts command here.
Z:\USERS\Administrator>net accounts
Force user logoff how long after time expires?:       Never
Minimum password age (days):                          0
Maximum password age (days):                          Unlimited
Minimum password length:                              0
Length of password history maintained:                None
Lockout threshold:                                    Never
Lockout duration (minutes):                           30
Lockout observation window (minutes):                30
Computer role:                                        BACKUP
Primary domain controller for workstation domain:     \\SCOOBY
The command completed successfully.

Net Computer
The Net Computer command allows you to add a computer account to or remove a computer account from a domain. What’s cool about this command is that if you have a list of computer account names, you could write a simple batch file to add or remove those account names. You can see a sample of the Net Computer command’s functionality here.
Z:\USERS\Administrator>net computer
The syntax of this command is:
NET COMPUTER \\computername {/ADD | /DEL}
Z:\USERS\Administrator>net computer \\homer /add
The request will be processed at the primary domain controller for domain BUD.
The command completed successfully.

Net Config
Many times when I’ve been working on someone else’s computer, I’ve needed to know the basic settings, such as the computer name, the workgroup name, and the name of the user who’s logged in. The Net Config command provides a quick and easy way to acquire this information. In a Windows 98 or Windows Me environment, the Net Config command displays the type of information shown below:
C:\WINDOWS>net config
Computer name                  \\TAZ
User name                      ADMINISTRATOR
Workgroup                      BUD
Workstation root directory     C:\WINDOWS
Software version               4.90.3000
Redirector version             4.00
The command was completed successfully.


The Net Config command also works in Windows NT. The main difference is that you have to specify whether you want to display a summary of a server or a workstation. For example, you’d enter Net Config Workstation. You’d then see a summary similar to the one given in Windows Me but with slightly more detail.

Net Continue
You use the Net Continue command to restart a service that has been paused by a Net Pause command. The syntax for the command is
C:\Windows>net continue service

where service is the name of the service you paused.

Net File
Need to find out who’s using files on your server? Just use the Net File command. As you can see here, the Net File command provides you with a quick summary of which users are attached and how many files they have locked.
Z:\USERS\Administrator>net file
ID         Path                            User name            # Locks
-----------------------------------------------------------------------
3          H:\USERS\Administrator          Administrator         0
6          H:\USERS\Administrator         Administrator         0
16         \PIPE\samr                                            0
The command completed successfully.

Net Group
The Net Group command allows you to display all of the groups that exist within a domain. You can see a sample of this command here.
Z:\USERS\Administrator>net group
Group Accounts for \\TITANIUM
-----------------------------------------------------------------
*Domain Admins            *Domain Guests            *Domain Users
*Finance                  *MTS Trusted Impersonators*test group
*ZZZZ
The command completed successfully.

Net Help
The Net Help command gives you detailed information on a Net command. To use it, just type net help command, where command is the name of the command you want help with.

Net Helpmsg
If Windows 2000 has a problem, it often coughs up confusing error messages and numbers. You can use the Net Helpmsg command to try to find out what the error messages mean. Just type Net Helpmsg errornumber, where errornumber is the error that Windows 2000 has given you.

Net Localgroup
Just as the Net Group command displays all of the domain’s groups, the Net Localgroup command displays a list of the groups that are specific to the local computer. Here’s a sample of the Net Localgroup command.
Z:\USERS\Administrator>net localgroup
Aliases for \\TITANIUM
-------------------------------------------------------------------
*Account Operators       *Administrators          *Backup Operators
*Guests                  *MTS Impersonators       *Print Operators
*Replicator              *Server Operators        *Users
The command completed successfully.

Net Name
You can use the Net Name command to control the name of the server when it sends and receives messages online. If you use the command by itself, you can see the current names configured for your computer. You can add or delete names by using the /ADD and /DELETE switches, respectively.

Net Pause
The Net Pause command pauses services running on your server. It can be useful if you need to pause a service to troubleshoot or make changes to it. To use it, just type Net Pauseservice, where service is the name of the service you want to pause.

Net Print
I can’t count the number of times I’ve needed to add printing capabilities to a batch file. In older versions of Windows, network printing from a batch file usually meant using the Net Use command to capture a printer port and then printing to the captured port. Unfortunately, this technique can cause confusion for end users the next time they try to print because they may have already been using the printer port that the batch file reassigned. If your users are working in a Windows 98, Me, or NT environment, the Net Print command is a good alternative to traditional batch-file printing. The Net Print command allows you to send print jobs to a network printer without capturing an LPT port. You can see the syntax for the Net Print command here.
Z:\USERS\Administrator>net print
The syntax of this command is:
NET PRINT \\computername\sharename
          [\\computername] job# [/HOLD | /RELEASE | /DELETE]

Net Send
The Net Send command can be used to send a pop-up message to network users. Just enter the username and the message. As you can see in this sample, the command also offers the capability to send messages to users in another domain.
Z:\USERS\Administrator>net send
The syntax of this command is:
NET SEND {name | * | /DOMAIN[:name] | /USERS} message
Z:\USERS\Administrator>net send Administrator This is a test
The message was successfully sent to ADMINISTRATOR.

Net Session
The Net command can even be used to see which computers are attached to your computer. Simply enter the Net Session command, and you’ll see a summary, similar to this one.
Z:\USERS\Administrator>net session
Computer        User name         Client Type        Opens Idle time
--------------------------------------------------------------------
\\TAZMANIA                        Windows 2000 21951     01D 10H 46M
\\TITANIUM                        Windows NT 1381  0     11D 00H 42M
\\TITANIUM      Administrator     Windows NT 1381  2     00:00:00
The command completed successfully.

Net Share
If you’d like to see which shares exist on a PC, you can do so by using the Net Share command. You can see a sample of this command here.
Share name   Resource                        Remark
--------------------------------------------------------------------
C$           C:\                             Default share
ADMIN$      C:\WINNT                        Remote Admin
REPL$        C:\WINNT\System32\Repl\Export
IPC$                                         Remote IPC
H$           H:\                             Default share
F$           F:\                             Default share
print$       C:\WINNT\System32\spool\DRIVERS Printer Drivers
dfs          F:\dfs
home_server  F:\home_server
Microsoft UAM Volume
             F:\Microsoft UAM Volume
NETLOGON     C:\WINNT\System32\Repl\Import\S Logon server share
titanium     F:\titanium
USERS        H:\USERS
4SIMX        LPT1:                  Spooled  Marketing
4SIMX2       LPT1:                  Spooled  Management
4SIMX3       LPT1:                  Spooled  Finance
The command completed successfully.

Net Start
This command starts any of the various services that are running. You can also use the Net Pause or Net Continue command to pause or resume services.

Net Statistics
Perhaps one of the most useful Net commands is Net Statistics. The Net Statistics command provides some hard-core statistics on how a server or workstation is communicating across the network. This command merely requires you to follow the Net Statistics command with the word Server or Workstation, as shown here.
Z:\USERS\Administrator>net statistics workstation
Workstation Statistics for \\TITANIUM
Statistics since 12/1/00 6:27 AM
  Bytes received                              4885909
  Server Message Blocks (SMBs) received        51520
  Bytes transmitted                            6101020
  Server Message Blocks (SMBs) transmitted     51523
  Read operations                              23
  Write operations                            1199
  Raw reads denied                             0
  Raw writes denied                            0
  Network errors                               0
  Connections made                             2433
  Reconnections made                          1
  Server disconnects                           6
  Sessions started                             2824
  Hung sessions                                0
  Failed sessions                              0
  Failed operations                           3
  Use count                                    3212
  Failed use count                             285
The command completed successfully.

Net Stop
This command is the opposite of Net Start. As you can probably guess, this command stops services from running on your server.

Net Time
One of the commands that I’ve personally found very useful is the Net Time command. The Net Time command is used to synchronize the time on a workstation with the time on a server. Here’s the syntax for the Net Time command:
NET TIME [\\computer | /WORKGROUP:wgname] [/SET] [/YES]
  • computer—Specifies the name of the computer (time server) whose time you want to check or synchronize your computer's clock with.
  • /WORKGROUP—Specifies that you want to use the clock on a computer (time server) in another workgroup.
  • wgname—Specifies the name of the workgroup containing a computer whose clock you want to check or synchronize your computer's clock with. If there are multiple time servers in that workgroup, NET TIME uses the first one it finds.
  • /SET—Synchronizes your computer's clock with the clock on the computer or workgroup you specify.
  • /YES—Carries out the NET TIME command without first prompting you to provide information or confirm actions.

Net Use
Without a doubt, the most powerful Net command in any version of Windows is the Net Use command. The Net Use command is used to attach to resources such as network shares or printers. For example, to map the Q: drive to a share called Articles on a server called Tazmania, you could enter the following command:
Net Use Q: \\Tazmania\Articles

Likewise, you could map LPT1 to a network printer that’s attached to a server called Scooby and shared as HP by entering the following command:
Net Use LPT1: \\Scooby\HP

The Net Use command also provides mechanisms for removing connections that you’ve made and for entering passwords. Here’s a full summary of the Net Use syntax.
C:\WINDOWS>net use /?
Connects or disconnects your computer from a shared
resource or displays information about your connections.
NET USE [drive: | *] [\\computer\directory [password | ?]]
    [/SAVEPW:NO] [/YES] [/NO]
NET USE [port:] [\\computer\printer [password | ?]]
    [/SAVEPW:NO] [/YES] [/NO]
NET USE drive: | \\computer\directory /DELETE [/YES]
NET USE port: | \\computer\printer /DELETE [/YES]
NET USE * /DELETE [/YES]
NET USE drive: | * /HOME
  drive       Specifies the drive letter you assign to a
              shared directory.
  *           Specifies the next available drive letter.
              If used with /DELETE, specifies to
              disconnect all of your connections.
  port        Specifies the parallel (LPT) port name you
              assign to a shared printer.
  computer    Specifies the name of the computer sharing
              the resource.
  directory   Specifies the name of the shared directory.
  printer     Specifies the name of the shared printer.
  password    Specifies the password for the shared
              resource, if any.
  ?           Specifies that you want to be prompted for the
              password of the shared resource. You don't
              need to use this option unless the password is
              optional.
  /SAVEPW:NO  Specifies that the password you type
              should not be saved in your password-list
              file. You need to retype the password the
              next time you connect to this resource.
  /YES       Carries out the NET USE command without
              first prompting you to provide information or
              confirm actions.
  /DELETE     Breaks the specified connection to a shared
              resource.
  /NO         Carries out the NET USE command, responding
              with NO automatically when you are prompted
              to confirm actions.
  /HOME       Makes a connection to your HOME directory if
              one is specified in your LAN Manager or
              Windows NT user account.

To list all of your connections, type NET USE without options. To see this information one screen at a time, type the following at the command prompt:
NET USE /? | MORE

or
NET HELP USE | MORE

Net User
Another use for the Net command is viewing all of the user accounts that exist on a given machine. To do so, simply enter the Net User command, as shown here.
Z:\USERS\Administrator>net user
User accounts for \\TITANIUM
---------------------------------------------------------------
Admin                    Administrator            Billy_Brown
Brien                    Brien_Posey              Guest
IUSR_SCOOBY             IUSR_TALAINIA            IUSR_TITANIUM
IWAM_SCOOBY              IWAM_TALAINIA            IWAM_TITANIUM
Jeremy_Broyles           Kendall_Hensley          Migrate
Normal                   Rep                      Shamir
Shamir_Dasgupta          Talainia_Posey           Taz
Test
The command completed successfully.

Net View
This command displays the other computers that are visible on the network. You can see a sample of Net View’s output here.
Z:\USERS\Administrator>net view
Server Name            Remark
------------------------------------------
\\SCOOBY
\\TALAINIA
\\TAZ                  BRIEN
\\TAZMANIA
\\TITANIUM
The command completed successfully.

Conclusion
In this Daily Drill Down, I explained how you can use the Net command to automate many common network tasks. As I did, I outlined the syntax used for each type of task.
The authors and editors have taken care in preparation of the content contained herein but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any damages. Always have a verified backup before making any changes.
0 comments

Editor's Picks