SoFunction
Updated on 2025-04-11

Cleverly use net commands to update batch synchronously in LAN files

Now everyone hopes that there is a synchronization software that can achieve network directory or file updates to reduce their workload. There are many software on the network that can achieve this goal, such as synchronization experts, but these software require server and client installation, and the client must be resident to use it, and occupy a certain amount of resources. The following batch processing uses net commands to synchronize and update files and directories. The advantage is that any machine can be a server and client, and does not occupy any resources. Of course, the disadvantage is that writing batch processing is a bit annoying ^^.

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 we use one of the parameters of the net command, net use. If you are interested in others, 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, which 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's D disk and map it into a network drive disk S disk. Here, the D disk needs to be fully shared. If it is not a fully shared file, it will not be able to copy it. Don't chase me ^^ at that time. Tip 1: If you are afraid that the file will be deleted by someone, you can set a full shared password. Assuming 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. There is no problem to access the remote client shared disk. Tip 2: Why do you 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 local disk D disk, and of course it must correspond to the 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: The /s /e parameter means copying all subdirectories under ghost, including empty directories. /y automatically overwrites 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 S:\netgames\mir\*.* in front of xcopy
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. Updates to the 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.
I've written so much and was dizzy. I've flashed~ If you don't understand, please come and ask me and try it a few times before using it.

Article entry: dnbm     Editor: dnbm