我已经找到并遵循这些方法*将我的用户文件夹移动到外部驱动器,它运行得非常好,但是副作用是robocopy source dest /xj
复制所有文件但是联结,这意味着它在外部驱动器上创建的用户文件夹不再具有目录连接,就像在默认的Windows 7中一样。我已尽力尝试从备份移动联结,创建具有相同属性的新联结,复制它们等我没有尝试过任何努力让他们回来。
我需要一种方法来修复我的用户文件夹中的联结链接, 从备份中复制/移动一些的方法, 或者一种方法来遵循链接中的步骤,但保持所有交叉点完好。
当用户个人资料显示正常工作时,您可能会问我为什么如此关注路口?原因是这些联结用于保持与以前的操作系统的向后兼容性,并且应该存在。我想复制EXACT用户文件夹,而不是大部分。老实说没有理由为何这么难。 :/
有没有人有任何建议?谢谢!
注意:我已经进行了数小时的广泛谷歌搜索,并且无法找到问题的任何解决方案。这是我的最后一招。我不介意得到的答案,即使它是重新安装的。只要有一种方法可以做到这一点。
* http://lifehacker.com/5467758/move-the-users-directory-in-windows-7
答案 0 :(得分:0)
由于我无法在任何地方找到任何真正的答案,我花时间编写并对整个过程进行反向工程。
我希望这对任何想要做同样事情的人都有用。请享受!
注意:这些脚本仅适用于系统上的一个用户,而不是默认用户。它不会为您可能创建的其他用户生成任何内容。
警告:这些脚本没有保修,虽然我尽力使它们完美无缺,但我对使用它们可能造成的任何损害不承担任何责任。使用风险自负!
#
# Restore default Windows 7 symlink and junction points
#
# To run:
# (1) Start CMD as administrator
# (2) cd to directory where script is
# (3) Run: powershell -executionpolicy remotesigned -File restorelinks.ps1
#
# tmp folder for our work
New-Item -ItemType directory -Path .\tmp
$username = [Environment]::UserName
$userObj = New-Object System.Security.Principal.NTAccount("$username")
$userSid = $userObj.Translate([System.Security.Principal.SecurityIdentifier]).Value
# file, target, perms
$symlinks = @(,
("C:\Users\All Users", "C:\ProgramData", "D:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICIIO;GA;;;CO)(A;OICI;0x1200a9;;;BU)(A;CI;DCLCRPCR;;;BU)")
)
# file, target, perms
$junctions = @(
("C:\Users\Default User", "C:\Users\Default", "D:PAI(D;;CC;;;WD)(A;;0x1200a9;;;WD)(A;;FA;;;SY)(A;;FA;;;BA)"),
("C:\Users\Default\Application Data", "C:\Users\Default\AppData\Roaming", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Default\Cookies", "C:\Users\Default\AppData\Roaming\Microsoft\Windows\Cookies", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Default\Local Settings", "C:\Users\Default\AppData\Local", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Default\My Documents", "C:\Users\Default\Documents", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Default\NetHood", "C:\Users\Default\AppData\Roaming\Microsoft\Windows\Network Shortcuts", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Default\PrintHood", "C:\Users\Default\AppData\Roaming\Microsoft\Windows\Printer Shortcuts", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Default\Recent", "C:\Users\Default\AppData\Roaming\Microsoft\Windows\Recent", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Default\SendTo", "C:\Users\Default\AppData\Roaming\Microsoft\Windows\SendTo", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Default\Start Menu", "C:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Default\Templates", "C:\Users\Default\AppData\Roaming\Microsoft\Windows\Templates", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Default\AppData\Local\Application Data", "C:\Users\Default\AppData\Local", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Default\AppData\Local\History", "C:\Users\Default\AppData\Local\Microsoft\Windows\History", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Default\AppData\Local\Temporary Internet Files", "C:\Users\Default\AppData\Local\Microsoft\Windows\Temporary Internet Files", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Default\Documents\My Music", "C:\Users\Default\Music", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Default\Documents\My Pictures", "C:\Users\Default\Pictures", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Default\Documents\My Videos", "C:\Users\Default\Videos", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;ID;0x1200a9;;;BU)(A;OICIIOID;GXGR;;;BU)(A;ID;0x1200a9;;;WD)(A;OICIIOID;GXGR;;;WD)"),
("C:\Users\Public\Documents\My Music", "C:\Users\Public\Music", "D:PAI(D;;CC;;;WD)(A;;0x1200a9;;;WD)(A;;FA;;;SY)(A;;FA;;;BA)"),
("C:\Users\Public\Documents\My Pictures", "C:\Users\Public\Pictures", "D:PAI(D;;CC;;;WD)(A;;0x1200a9;;;WD)(A;;FA;;;SY)(A;;FA;;;BA)"),
("C:\Users\Public\Documents\My Videos", "C:\Users\Public\Videos", "D:PAI(D;;CC;;;WD)(A;;0x1200a9;;;WD)(A;;FA;;;SY)(A;;FA;;;BA)"),
("C:\Users\$username\Application Data", "C:\Users\$username\AppData\Roaming", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)"),
("C:\Users\$username\Cookies", "C:\Users\$username\AppData\Roaming\Microsoft\Windows\Cookies", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)"),
("C:\Users\$username\Local Settings", "C:\Users\$username\AppData\Local", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)"),
("C:\Users\$username\My Documents", "C:\Users\$username\Documents", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)"),
("C:\Users\$username\NetHood", "C:\Users\$username\AppData\Roaming\Microsoft\Windows\Network Shortcuts", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)"),
("C:\Users\$username\PrintHood", "C:\Users\$username\AppData\Roaming\Microsoft\Windows\Printer Shortcuts", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)"),
("C:\Users\$username\Recent", "C:\Users\$username\AppData\Roaming\Microsoft\Windows\Recent", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)"),
("C:\Users\$username\SendTo", "C:\Users\$username\AppData\Roaming\Microsoft\Windows\SendTo", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)"),
("C:\Users\$username\Start Menu", "C:\Users\$username\AppData\Roaming\Microsoft\Windows\Start Menu", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)"),
("C:\Users\$username\Templates", "C:\Users\$username\AppData\Roaming\Microsoft\Windows\Templates", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)"),
("C:\Users\$username\AppData\Local\Application Data", "C:\Users\$username\AppData\Local", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)"),
("C:\Users\$username\AppData\Local\History", "C:\Users\$username\AppData\Local\Microsoft\Windows\History", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)"),
("C:\Users\$username\AppData\Local\Temporary Internet Files", "C:\Users\$username\AppData\Local\Microsoft\Windows\Temporary Internet Files", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)"),
("C:\Users\$username\Documents\My Music", "C:\Users\$username\Music", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)"),
("C:\Users\$username\Documents\My Pictures", "C:\Users\$username\Pictures", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)"),
("C:\Users\$username\Documents\My Videos", "C:\Users\$username\Videos", "D:AI(D;;CC;;;WD)(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;$userSid)")
)
# dump acl file
Add-Content tmp\acl-tmp.dat "Users`r`nD:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;;0x1200a9;;;BU)(A;OICIIO;GXGR;;;BU)(A;;0x1200a9;;;WD)(A;OICIIO;GXGR;;;WD)"
foreach ($symlink in $symlinks) {
Add-Content tmp\acl-tmp.dat "$($symlink[0].Substring(3))`r`n$($symlink[2])"
}
foreach ($junction in $junctions) {
Add-Content tmp\acl-tmp.dat "$($junction[0].Substring(3))`r`n$($junction[2])"
}
# generate formatted acl file
$aclTmp = [io.file]::ReadAllBytes("tmp\acl-tmp.dat")
$acl = New-Object Byte[] ($aclTmp.length*2)
$offset = 0
for ($i = 0; $i -lt $aclTmp.length; $i++) {
$acl[$offset] = $aclTmp[$i]
$acl[$offset+1] = 0x00
$offset += 2
}
[io.file]::WriteAllBytes("tmp\acl.dat", $acl)
# create links
foreach ($symlink in $symlinks) {
cmd /c mklink /D "$($symlink[0])" "$($symlink[1])"
cmd /c attrib +s +h +i "$($symlink[0])" /L
cmd /c icacls "$($symlink[0])" /setowner SYSTEM /L
}
foreach ($junction in $junctions) {
cmd /c mklink /J "$($junction[0])" "$($junction[1])"
cmd /c attrib +s +h +i "$($junction[0])" /L
cmd /c icacls "$($junction[0])" /setowner SYSTEM /L
}
# restore link permissions
cmd /c icacls C:\ /restore tmp/acl.dat
# cleanup tmp folder
Remove-Item -Recurse -Force tmp
如果有人有任何奇怪的需要删除所有生成的符号链接和连接点,您可以使用它。
@echo off
set FILES=(^
"C:\Users\All Users"^
"C:\Users\Default User"^
"C:\Users\Default\Application Data"^
"C:\Users\Default\Cookies"^
"C:\Users\Default\Local Settings"^
"C:\Users\Default\My Documents"^
"C:\Users\Default\NetHood"^
"C:\Users\Default\PrintHood"^
"C:\Users\Default\Recent"^
"C:\Users\Default\SendTo"^
"C:\Users\Default\Start Menu"^
"C:\Users\Default\Templates"^
"C:\Users\Default\AppData\Local\Application Data"^
"C:\Users\Default\AppData\Local\History"^
"C:\Users\Default\AppData\Local\Temporary Internet Files"^
"C:\Users\Default\Documents\My Music"^
"C:\Users\Default\Documents\My Pictures"^
"C:\Users\Default\Documents\My Videos"^
"C:\Users\Public\Documents\My Music"^
"C:\Users\Public\Documents\My Pictures"^
"C:\Users\Public\Documents\My Videos"^
"C:\Users\%username%\Application Data"^
"C:\Users\%username%\Cookies"^
"C:\Users\%username%\Local Settings"^
"C:\Users\%username%\My Documents"^
"C:\Users\%username%\NetHood"^
"C:\Users\%username%\PrintHood"^
"C:\Users\%username%\Recent"^
"C:\Users\%username%\SendTo"^
"C:\Users\%username%\Start Menu"^
"C:\Users\%username%\Templates"^
"C:\Users\%username%\AppData\Local\Application Data"^
"C:\Users\%username%\AppData\Local\History"^
"C:\Users\%username%\AppData\Local\Temporary Internet Files"^
"C:\Users\%username%\Documents\My Music"^
"C:\Users\%username%\Documents\My Pictures"^
"C:\Users\%username%\Documents\My Videos"^
)
for %%a in %FILES% do (
icacls %%a /grant "%username%:(F)" /L
icacls %%a /setowner %username% /L
attrib -S -I -H %%a /L
rmdir %%a
)