SoFunction
Updated on 2025-04-11

Use the net command to make batch updates of LAN files synchronously


Now everyone hopes that there is a synchronization software that can achieve network directory or file updates to reduce their workload. There are also many software on the network that can achieve this goal, such as synchronization experts, but these software require the installation of server and client, and the client must be permanent to use it, and occupy a certain amount of resources.

The following batch processing uses the net command to synchronously update files and directories. The advantage is that any machine can be a server and a client, and does not occupy any resources. Of course, the disadvantage is that it is a bit annoying to write batch processing^^.

I first write out the batch process and then give a detailed explanation:

net use S: \\computer-01\D
attrib -s -h -r S:\ghostC:\WINDOWS\COMMAND\ /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\ /s /e /y D:\ghost S:\ghost
net use * /delete
Write a description of the usage of the net command. Here, one of the parameters of the net command is used.
use, if you are interested in other things, you can type net / in the command window? Show its help screen.

Parameter net use

Function: Connect the computer or disconnect the computer from shared resources, or display the computer's connection information.
Command format: net use [devicename | *] [computernamesharename[volume]]
[password | *]] [/user:[domainname]username] [[/delete] |
[/persistent:{yes | no}]]

Parameter description:

Type net use without parameters to list the network connection.
devicename specifies the name of the resource to connect to or the name of the device to disconnect.
The computernamesharename server and the name of the shared resource.
password to access shared resources.
* Prompt to type your password.
/user specifies another user that connects.
domainname specifies another domain.
username specifies the logged in username.
/home connects the user to its host directory.
/delete unspecified network connection.
/persistent controls the use of permanent network connections.

Here are a simple examples:
(1)net use e: YFANGTEMP Create the YFANGTEMP directory as E disk

(2)net use e: YFANGTEMP /delete Disconnect

Here I only write two lines of batch processing, which means that the network identifiers of these two major lines are different, and others can be compared in turn. My Internet cafe network logo 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 explaining each line of commands, and the actual application will be explained later.

one. Command parsing.

use S: \\computer-01\D

(Connect the shared disk of computer-01 in network connection and map it into a network drive disk S disk. Here, the D disk needs to be fully shared. If the file is not completely shared, it will not be copied. Don't chase me by ^^.

Tip 1: If you are afraid that the file will be deleted by someone, you can set a fully shared password. Assuming that the full shared password of the remote shared disk is 123, then this line of command is changed to the following:

net use S: \\computer-01\D
123。

This way, there is no problem to access the remote client shared disk. Tip 2: Why do you want to choose D disk instead of E disk C disk? It is to correspond to the drive letter of the service machine that is updated synchronously. I want to copy the things under the D disk of the local machine, and of course it must correspond to D disk. )

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

3. C:\WINDOWS\COMMAND\ /y /s /e D:\ghost
S:\ghost\ (Copy the files under the ghost directory under the d disk of the local machine to the ghost directory under the virtual mapping disk of the s disk. The s disk here is the d disk on computer-01. Tip 1: The s disk will automatically disappear after executing the first large line. When executing the second large line, the d disk of computer-02 is virtually mapped to the s disk; Tip 2: /s
/e parameter means copying all subdirectories under ghost, including empty directories. /y Automatically overwrite existing files)
4. net use * /delete (disconnect all connections)

 2. Practical application

1. Update the shared disk directory:


For example, the legend that is now a headache, I installed it in the mir directory under netgames on disk d. Share the d disk completely and set the sharing password to ****. When you want to update files and plug-in files, plug-in files are also placed in the mir directory. In this way, first debug a computer, then write out the following commands and execute them.

net use S: \\computer-01\D ****
attrib -s -h -r S:\netgames\mir
C:\WINDOWS\COMMAND\ D:\netgames\mir S:\netgames\mir
net use * /delete

Tip: 1. /s/e is not used here, just copy the files in the root directory of mir and not the entire directory.

2. We can also insert a sentence C:\WINDOWS\COMMAND\del /y in front of xcopy
S:\netgames\mir\*.*

Delete the file under mir before copying. You can not write it on the safe side.

3.\\computer-01 can be written in sequence, such as computer-02 -03 -04. . . . . . .

 2. Update of shared directory

After we updated the files and plug-ins in the legend directory above, a problem occurred. The desktop icon of the network management software is not updated synchronously, so good things are done to the end. Last time we fully shared the entire drive letter, and this time we only shared one directory completely and set the password ****. Because I am using pubwin4 network management software to install C drive, for security reasons, I will only share folders, not the entire drive. Pubwin's desktop shortcut is installed under hitsoft on the program files on the C drive. Just share hitsoft completely, and put the legend and legend plug-in shortcuts under netgames in the directory. The batch processing is as follows

net use S: \\computer-01\hitsoft ****
attrib -s -h -r S:\netgames
C:\WINDOWS\COMMAND\ c:\program~1\hitsoft\netgames
S:\netgames /s /y /e
net use * /delete

Tip: We can do more, and delete directories. Just convert xcopy to deltree.