Windows 符号链接、软硬链接方案(mklink 、subst、psubst、visual subst、Link Shell Extension)
介绍几个符号链接的方案。
实践中,发现部分方式挂载网络存储可能会导致所有挂这个网络盘的客户端都出现资源管理器僵住的情况。
一般不推荐嵌套挂载,所谓嵌套挂载,举例来说,\\\\10.0.0.10\\rootfolder 挂到Z:了,然后又把\\\\10.0.0.10\\rootfolder\\subfolder1 挂了别的盘符,或者把Z:\\subfolder1 又挂了别的盘符或目录符号链接。
一、Link Shell Extension
https://schinagl.priv.at/nt/hardlinkshellext/linkshellextension.html
安装后先找到LSEConfig进行配置
然后在需要创建目录符号链接的文件夹上右击 → 点"选择源连接点" → 在其他位置空白处右击 → 创建为 → 有很多选项,根据需要选择
二、visual subst
https://www.ntwind.com/software/visual-subst.html
三、psubst
https://github.com/ildar-shaimordanov/psubst
https://github.com/ildar-shaimordanov/psubst/releases/tag/v3.0.1
How does subst work?
https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-xp/bb491006(v=technet.10)?redirectedfrom=MSDN
https://ss64.com/nt/subst.html
https://superuser.com/questions/644684/mapping-drive-letters-to-local-folders/644706
Print the list of existing drives:
subst
Create new virtual drive:
subst Z: "C:\\Documents and Settings\\All Users\\Shared Documents"
Delete the virtual drive:
subst Z: /D
https://en.wikipedia.org/wiki/SUBST
Importing reg file
The easiest way to do this is to create a registry file (.reg), and double click the file to import the settings into the registry.
Here is an example registry file.
REGEDIT4
[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\DOS Devices]
"F:"="\\\\??\\\\D:\\\\Mount\\\\db"
"G:"="\\\\??\\\\D:\\\\Mount\\\\log"
After configuring the registry the computer must be rebooted for the changes to take effect.
Run on boot (batch)
Create a batch file to run the built-in SUBST
command to create a virtual drive letter for the existing mount points and place it in the user accounts startup folder.
This is not preferred, as the mapping only appears at the end of user logon.
Here is an example:
@ECHO off
SUBST f: d:\\mount\\db
SUBST g: d:\\mount\\log
Run on boot (registry)
Edit the registry to run the built-in subst command during computer startup or user logon by leveraging the appropriate Run registry key. The easiest way to do this is to create a registry file (.reg), and double click the file to import the settings into the registry.
This is not preferred, as the mapping only appears at the end of bootup.
Example to run during computer boot
REGEDIT4
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run]
"F Drive"="SUBST f: d:\\\\mount\\\\db"
"G Drive"="SUBST g: d:\\\\mount\\\\log"
The computer must be rebooted for the changes to take effect.
Example of user logon
REGEDIT4
[HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run]
"F Drive"="SUBST f: d:\\\\mount\\\\db"
"G Drive"="SUBST g: d:\\\\mount\\\\log"
The user must log off and back on for the changes to take effect.
As well as the standard SUBST
command this script named as PSUBST.BAT
implements all standard features of the command.
Print all virtual drives:
psubst
Create the virtual drive:
psubst drive1: drive2:path
Delete the virtual drive:
psubst drive1: /D
Typing the /P
or /PF
argument you run the tool with the extended features to work with persistent virtual disks:
/P
stands for creating, deleting or displaying persistent drives;/PF
stands for creating and deleting persistent drives using elevated privileges; it can be useful for managing persistent drives by non-administrative users.
Print all virtual persistent drives (read from the registry)
psubst /P
Restore a virtual drive from the persistent drive, if any:
psubst drive1: /P
In the following commands the option /P
can be replaced with the option /PF
to elevate privileges.
Create the persistent virtual drive with saving its persistency in the registry:
psubst drive1: drive2:path /P
Delete the persistent drive from the registry:
psubst drive1: /D /P