[Mklink, junction, icacls] generate junction in the user configuration file using batch processing

Source: Internet
Author: User
Tags robocopy

I recently got a new host. I strongly recommended it to my boss to use an SSD as the system disk. The speed is really a big four. It's so nice !!!

I checked it online and found that there are still a lot of precautions for using SSD. The main purpose is to prolong the service life of the hard disk. The following describes how to transfer the user configuration file and use the mklink command to link the folder.ArticleIt aroused my interest. Since the backup files left by the previous n reinstalls of the system were too messy and there were too many duplicate files, we were prepared to carefully sort them out and then set the user files to other disks using mklink. After several days of hard work, I finally successfully linked the user folder in c: \ Users to drive D. In the meantime, various situations occurred. I would like to share my experiences and lessons with you.

Before getting involved, we should popularize the basic knowledge:

The mklink Command provided by Windows (Vista/win7/Win8) can be used to set file and folder links, also known as joining points or parsing points. You can view them through DIR/A: l.

As shown in, the file or folder with the <junction> mark is the joint point.

Junction: A connection point or joint point. The icon is similar to a shortcut. When a user accesses it, the read/write operation is actually attached to the file or folder pointed to by the contact.

For example, "C: \ Documents ents and settings" in win7, "Application Data" and "my documents ents" in the user directory.

Mklink is a command used to create junction. For details about how to use mklink, refer to symbolic link, mklink, and mklink commands in Windows 7.

Okay, let's do it.

This document uses administrator as an example user. All you need to do is link the user configuration directory c: \ Users \ administrator to D: \ admin.

The procedure is divided into three steps:

1. Use winpe to copy the c: \ Users \ Administrator folder to D: \ admin.

My system is Win8. I used the robocopy command to copy the user directory. Unfortunately, it failed:

 

 
Robocopy "C: \ Users \ Administrator" "D: \ ADMIN"/copyall/e/XJ

 

Summarize the causes of failure:

A. I was going to be lazy. I copied the junction in administrator to disk D, So I removed the/XJ parameter. The consequence is that there is a circular copy. The original directory pointed to by application data has a circular reference. If you move the Administrator folder, the target of the original juncation will become invalid. Therefore, you must add the/XJ parameter.

 

B. After the/XJ parameter is added, the copy is successful, but the system prompts that some folders do not have access permissions, but I ignore it. It turns out that this is incorrect, because c: \ Users \ Administrator \ appdata \ roaming \ Microsoft \ Windows \ libraries has no permission to delete the copy, how can I create a junction ~~

C. Use the user configuration file management provided by the system to copy and delete the files, and access is not permitted.

 

D. It is said that the security mode can be done, but SHIFT + F8 are stuck and cannot enter the Win8 security mode. What a shame!

In the end, I chose to copy the configuration file in the winpe environment.

Reminder:

For Windows 8 OS, it is recommended that you log on to the system with the Administrator account and click the application store. It doesn't matter if you want to download the application. Otherwise, after the competition, you will be pleasantly surprised to find that the app cannot be installed from the app store!

2. Rename the c: \ Users \ administrator and D: \ Administrator folders.

For the sake of insurance, do not delete the c: \ Users \ Administrator folder. You can rename it as administrator. Bak.

D: \ Administrator rename Admin

3. Create a folder link using mklink:

 

Mklink/J "C: \ Users \ Administrator" "D: \ ADMIN"

 

Note: The mklink command can also be used in winpe. You can enter the system directory to execute the command due to the lack of environment variable settings.

4. In the D: \ ADMIN folderCreate"Application Data "," cookies"JUnction joint point.

Run the Dir/S/A: l command to view all juncation In the Administrator Folder:

 

As many junction statements in the directory are scattered in different subdirectories, I wrote a batch to complete this task. To be consistent with junction in the original user directory, attrib and icacls commands are added to batch processing to set system and hidden attributes for these junction commands respectively, and added the permission to deny user access.

Script on ~~!

 

D: CD \ CD adminrem mklinkmklink/J "Application Data" "appdata \ roaming" mklink/J "cookies" "appdata \ roaming \ Microsoft \ Windows \ cookies" mklink/J "Local Settings" "appdata \ Local" mklink/J "My Documents" "documents" mklink/J "nethood" "appdata \ roaming \ Microsoft \ Windows \ Network shortcuts" mklink/J "printhood "" appdata \ roaming \ Microsoft \ Windows \ printer shortcuts "mklink/J" Recent "" appdata \ roaming \ Microsoft \ Windows \ recent "mklink/J" sendto "" appdata \ roaming \ Microsoft \ windows \ sendto "mklink/J" templates "" appdata \ roaming \ Microsoft \ Windows \ templates "mklink/J" "start" menu "" appdata \ roaming \ Microsoft \ Windows \ start Menu "mklink/J" appdata \ Local \ Application Data "" appdata \ Local "mklink/J" appdata \ Local \ history "" appdata \ Local \ Microsoft \ Windows \ history" mklink/J "appdata \ Local \ temporary" Internet Files "appdata \ Local \ Microsoft \ Windows \ Temporary Internet Files" mklink/J "appdata \ roaming \ Microsoft \ Windows \ Start Menu \ Program "" Appdata \ roaming \ Microsoft \ Windows \ Start Menu \ Programs "mklink/J" Documents \ My music "" Music "mklink/J" Documents \ my pictures "" pictures "mklink /J "events \ My videos" "videos" REM attribattrib + S + H + I "Application Data" attrib + S + H + I "cookies" attrib + S + H + I "Local Settings" attrib + S + H + I "My Documents ents" attrib + S + H + I "nethood" attrib + S + H + I "printhood" attrib + S + H + I "Recent" attrib + S + H + I "sendto" attrib + S + H + I "templates" attrib + S + H + I "" menu "attrib + S + H + I "appdata \ Local \ Application Data" attrib + S + H + I "appdata \ Local \ history" attrib + S + H + I "appdata \ Local \ temporary "attrib + S + H + I" appdata \ roaming \ Microsoft \ Windows \ Start Menu \ Program "attrib + S + H + I" Documents \ My music "attrib + S + H + I "Documents \ my pictures" attrib + S + H + I "Documents \ My videos" REM icaclsicacls "Application Data"/deny everyone :( s, rd) icacls "cookies"/deny everyone :( S, RD) icacls "Local Settings"/deny everyone :( S, RD) icacls "My Documents ents"/deny everyone :( S, RD) icacls "nethood"/deny everyone :( S, RD) icacls "printhood"/deny everyone :( S, RD) icacls "Recent"/deny everyone :( S, RD) icacls "sendto"/deny everyone :( S, RD) icacls "templates"/deny everyone :( S, RD) icacls "" start "menu"/deny everyone :( S, RD) icacls "appdata \ Local \ Application Data"/deny everyone :( S, RD) icacls "appdata \ Local \ history"/deny everyone :( S, RD) icacls "appdata \ Local \ temporary"/deny everyone :( S, RD) icacls "appdata \ roaming \ Microsoft \ Windows \ Start Menu \ Program"/deny everyone :( S, RD) icacls "Documents \ My music"/deny everyone :( S, RD) icacls "Documents \ my pictures"/deny everyone :( S, RD) icacls "Documents \ My videos"/deny everyone :( S, RD)

Save the preceding command line as a bat file and then execute it in the CMD command line ~
I hope this script is useful to everyone.

Actually, I used another method to modify the registry.

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion \ profilelist \[User Sid]\ ProfileImagePath

This method has many drawbacks. We recommend that you do not use it at will.

 

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.