Command-Line Utilities for Managing Shared Resources

advertisement
Command-Line Utilities for Managing
Shared Resources
Some users prefer a terse command prompt to a wizard or even an MMC window. If you're in
that group, you'll want to use Net.exe for managing resource sharing.
In the following sections, we describe only the most common Net commands (and their most
common parameters) for managing network connections. This isn't an exhaustive reference,
however. You can get more information from online help or by typing net help command ,
replacing command with the word that follows Net in the examples. For example, to get more
information about the Net Use command, type net help use. This provides more help than
typing net use /? , which shows only the command syntax.
Net Share
The Net Share command lets you view, create, modify, or delete shared resources on your
computer.
Viewing Share Information
Typing net share with no parameters causes the program to display a list of the shared
resources on your computer, as shown in the following sample:
C:\> net share
Share name
Resource??
Remark
--------------------------------------------------------------------------IPC$
Remote IPC
D$
D:\
Default share
C$
C:\
Default share
print$
D:\WINDOWS\System32\spool\drivers
Printer Drivers
ADMIN$
HyperSnap
SharedDocs??
D:\WINDOWS
Remote Admin
C:\HyperSnap
D:\DOCUMENTS AND SETTINGS\ALL USERS\DOCUMENTS
LJ4000
LPT1:
PS
The command completed successfully.
Spooled
HP LaserJet 4000 Series
If you follow Net Share with the name of a local shared resource, it displays information
about that share. For example, the command net share shareddocs displays the following:
C:\>net share shareddocs
Share name
SharedDocs
Path
D:\DOCUMENTS AND SETTINGS\ALL USERS\DOCUMENTS
Remark
Maximum users
No limit
Users
JAN
CARL
Caching
Manual caching of documents
The command completed successfully.
Adding or Modifying a Share
You can share the folder C:\Spreadsheets, for use by an unlimited number of users, and add
the comment "Budgets" with the following command:
C:\>;net share Spreadsheets=C:\spreadsheets /unlimited /remark:"Budgets"
Spreadsheets was shared successfully.
Setting a sharename "equal" to a folder creates a share. To modify an existing share, you use
only the sharename (and no folder), as in the following command, which changes the remark
on the Spreadsheets share to "Year 2002 Budgets":
C:\>net share Spreadsheets /remark:"Year 2002 Budgets"
The command completed successfully.
Several parameters can be used with the Net Share command, as shown in Table 32-4.
Table 32-4. Useful Parameters for the Net Share Command
Parameter
Description
/Users: number
Sets the maximum number of concurrent users
/Unlimited
Lets the maximum number of users connect to the share at one time
Adds or changes a comment that appears in Details view in
/Remark:"text"
Windows Explorer
/Cache:manual,
/Cache:documents,
Sets the document and program caching option for offline files; for
/Cache:programs, or
details, see "Setting Caching Options on the Server."
/Cache:no
Deleting a User Share
To remove a share, simply use the /Delete switch with the Net Share sharename command:
C:\>net share spreadsheets /delete
spreadsheets was deleted successfully.
Net Use
The Net Use command connects your computer to shared resources on other computers. It can
also disconnect, or display, all the resources to which you are connected.
Viewing Connections
Type net use with no parameters to display the resources to which you are currently
connected.
C:\> net use
New connections will be remembered.
Status
Local
Remote
Network
--------------------------------------------------------------------------OK
G:
\\everglades\programs
Microsoft Windows
Network
OK
K:
\\everglades\document
Microsoft Windows
Network
OK
P:
\\everglades\company
Microsoft Windows
Network
OK
LPT2
\\badlands\lj4000
Microsoft Windows
Network
\\www.msnusers.com\xxxxx@msn.com
Web Client Network
The command completed successfully.
Adding a Mapped Network Drive
You can create drive mappings with a command like this:
C:\>net use e: \\badlands\spreadsheets
The command completed successfully.
This maps the network share Spreadsheets on the computer named Badlands to the local drive
letter E. If you want to use the next available drive letter, use an asterisk (*) instead of the
drive letter and colon. You can add any of the parameters shown in Table 32-5.
Table 32-5. Useful Parameters for the Net Use Command
Parameter
Description
password
Enter your password following the share name if a password is required.
To connect using a user name that is different from the one you are currently
logged on with, you can use the /User parameter. The domain name is
/User: domain \
necessary only if you are not in the same domain as the resource you're
username
connecting to. You can also enter the domain and user name in the format of
an e-mail address (for example, user @ domain).
Disconnects the connection. You need only specify the drive letter and
/Delete
/Delete to disconnect.
/Persistent:yes The yes option causes connections to persist so that they are reconnected the
or /Persistent:no next time you log on.
Disconnecting a Mapped Drive
To disconnect a mapped drive, simply use the /Delete switch with the Net Use command:
C:\>net use e: /delete
e: was deleted successfully.
Net Session
The Net Session command lets you view or disconnect connections between your computer
and clients that are accessing it.
Viewing Session Information
Type net session with no parameters to display the current connections to your computer:
C:\> net session
Computer
User name
Client Type
Opens Idle time
--------------------------------------------------------------------------\\127.0.0.1
Windows 2002 2600
1 01:20:24
\\GLACIER
CARL
Windows NT 1381
0 00:00:07
The command completed successfully.
Disconnecting a Session
Following Net Session \\ computername, append /Delete to disconnect a session. If you don't
include \\ computername, all active sessions are disconnected.
Net File
The Net File command lets you view or close the open shared files on your computer. Typing
net file with nothing following it causes the program to list all the open files, including a file
ID, the user name of the person who has the file open, and the number of locks each has.
C:\> net file
ID
Path
User name
# Locks
--------------------------------------------------------------------------24
E:\Catalog
JAN
0
32
C:\spreadsheets\Q1 Budget.xls
CARL
3
The command completed successfully.
You can close a file by following Net File with the ID of the file and /Close:
C:\>net file 24 /close
The command completed successfully.
Net Statistics
The Net Statistics command displays the statistics log for the local Workstation or Server
service. Type net statistics workstation to view the Workstation statistics. Type net
statistics server to view the Server statistics.
The workstation statistics log looks like this:
C:\>net statistics workstation
Workstation Statistics for \\SEQUOIA
Statistics since 11/17/2001 4:06 PM
Bytes received
Server Message Blocks (SMBs) received
Bytes transmitted
Server Message Blocks (SMBs) transmitted
Read operations
Write operations
Raw reads denied
Raw writes denied
232765115
394263
65653800
393773
187879
1258
0
0
Network errors
Connections made
Reconnections made
Server disconnects
0
20
24
7
Sessions started
Hung sessions
Failed sessions
Failed operations
Use count
Failed use count
102
0
0
0
126
2
The command completed successfully.
Download