Use the net command to synchronously update LAN files in batches

Source: Internet
Author: User
Tags net command

Now everyone wants to have a synchronization software that can update network directories or files to reduce their workload. Now there are a lot of software on the network that can achieve this goal, such as synchronization experts, however, these software must be installed on the server and client, and the client must be resident in order to use it and occupy certain resources.

The following batch processing uses the net command to synchronously update files and directories. the advantage is that any machine can be used as a server or client without occupying any resources. of course, the disadvantage is that writing batch processing is a little annoying ^.

  I will first write out the batch processing, and then give a detailed explanation:

Net use S: \ computer-01 \ D
Attrib-s-h-r S: \ ghostC: \ WINDOWS \ COMMAND \ Xcopy.exe/s/e/y
D: \ ghost S: \ ghost
Net use */delete
Net use S: \ computer-02 \ D
Attrib-s-h-r S: \ ghost
C: \ WINDOWS \ COMMAND \ Xcopy.exe/s/e/y D: \ ghost S: \ ghost
Net use */delete
Write a description of the usage of the net command. Here, a net parameter is used.
Use. If you are interested in others, you can type net/? In the command window /? The help screen is displayed.

Net use Parameter

Purpose: connect the computer or disconnect the computer from the shared resources, or display the connection information of the computer.
Command Format: net use [devicename | *] [computernamesharename [volume]
[Password | *] [/user: [domainname] username] [[/delete] |
[/Persistent: {yes | no}]

  Parameter introduction:

Type "net use" without parameters to list network connections.
Devicename specifies the name of the resource to be connected to or the name of the device to be disconnected.
Name of the computernamesharename server and the shared resource.
Password: the password used to access shared resources.
* The system prompts you to enter the password.
/User specifies another user to connect.
Domainname specifies another domain.
Username specifies the username to log on.
/Home connects the user to its home directory.
/Delete cancels the specified network connection.
/Persistent controls the use of permanent network connections.

The following is a simple example:
(1) net use e: YFANGTEMP create the YFANGTEMP directory as an e Disk

(2) net use e: YFANGTEMP/delete disconnected

Here I only write two lines of batch processing. The two lines of network IDs are different, and the others can be same. My Internet cafe network ID is computer-01 ~ Computer-N
That is, the Network Name of the Internet cafe computer, which can be changed according to your actual situation. For example, user01 ~ UserXX
Start to explain each line of commands. The actual application will be explained later.

  1. Command Parsing.

1. net use S: \ computer-01 \ D

(Connect the shared disk D of computer-01 to the network and map it to the drive disk s of the network. Here, the d drive must be fully shared. If it is not completely shared, the file cannot be copied. Then, do not chase me through the kitchen knife ^.

Tip 1: If you are afraid that the file will be deleted for full sharing, you can set a full sharing password. Assume that the full password for the remote shared disk is 123, then the command line is changed to the following:
  
Net use S: \ computer-01 \ D
123.

In this way, you can access the shared disk of a remote client. Tip 2: Why do I need to select disk D instead of disk C of disk e? It corresponds to the drive letter of the synchronously updated service machine. I want to copy something from disk D of the local machine, of course, it must correspond to disk D .)

2. attrib-s-h-r S: \ ghost \
Remove the file attributes (read-only, hidden, and system) in the target directory to be copied to the target disk. Tip: if the target disk does not have the ghost directory, the next xcopy command will be automatically created)

3. C: \ WINDOWS \ COMMAND \ Xcopy.exe/y/s/e D: \ ghost
S: \ ghost \ (copy the files under the ghost directory on the d disk of the local machine to the ghost directory on the s disk of the virtual ing disk. The s disk here is the D disk on the computer-01. Tip 1: The s disk automatically disappears after the first row is executed. When the second row is executed, the D disk of computer-02 is virtualized to the s disk. Note 2:/s.
The/e parameter indicates that all subdirectories of the ghost, including empty directories, are copied. /Y automatically overwrites existing files)
4. net use */delete (disconnect all connections)

 2. Practical Application

1. Update the shared disk directory:

For example, in the legend of the headache, I installed the mir directory under netgames ON THE D Drive. Completely share the D disk and set the Shared Password ****. To update files and plug-in files, the plug-in files are stored in the mir directory. In this way, debug a computer and then write and execute the following commands.

Net use S: \ computer-01 \ D ****
Attrib-s-h-r S: \ netgames \ mir
C: \ WINDOWS \ COMMAND \ Xcopy.exe D: \ netgames \ mir S: \ netgames \ mir
Net use */delete

Tip: 1. In this case, the/s/e command is not used to copy only the files in the root directory of mir, instead of the entire directory.

2. You can also insert a C: \ WINDOWS \ COMMAND \ del/y statement before xcopy.
S: \ netgames \ mir \*.*

Delete the files in mir and then copy them. Do not write for the sake of insurance.

3. \ computer-01 can be written by analogy, for example, computer-02-03-04 .....

 2. Update shared directories

After updating the files and plug-ins in the legend directory, a problem occurs. The desktop icons of the network management software are not updated synchronously. The last time we shared the entire drive letter, we only shared one directory and set the password ****. Because I am using pubwin4 network management software and installing the C disk, I still share folders instead of the entire disk for security reasons. Pubwin's desktop shortcut is installed under hitsoft of program files on drive C, and hitsoft is fully shared. The legendary and legendary plug-in shortcuts are placed under netgames in the directory. Batch Processing is as follows

Net use S: \ computer-01 \ hitsoft ****
Attrib-s-h-r S: \ netgames
C: \ WINDOWS \ COMMAND \ Xcopy.exe c: \ program ~ 1 \ hitsoft \ netgames
S: \ netgames/s/y/e
Net use */delete

Tip: We can do more and delete directories. You only need to convert xcopy to deltree.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.