Windows 符号链接、软硬链接方案(mklink 、subst、psubst、visual subst、Link Shell Extension)

2024-08-15 08:27:20 浏览数 (3)

介绍几个符号链接的方案。

实践中,发现部分方式挂载网络存储可能会导致所有挂这个网络盘的客户端都出现资源管理器僵住的情况。

一般不推荐嵌套挂载,所谓嵌套挂载,举例来说,\10.0.0.10rootfolder 挂到Z:了,然后又把\10.0.0.10rootfoldersubfolder1 挂了别的盘符,或者把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://www.computerworld.com/article/2694895/how-to-map-a-local-folder-to-a-drive-letter-in-windows.html

https://superuser.com/questions/644684/mapping-drive-letters-to-local-folders/644706#644706

Print the list of existing drives:

代码语言:javascript复制
subst

Create new virtual drive:

代码语言:javascript复制
subst Z: "C:Documents and SettingsAll UsersShared Documents"

Delete the virtual drive:

代码语言:javascript复制
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.

代码语言:javascript复制
REGEDIT4

[HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlSession ManagerDOS 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:

代码语言:javascript复制
@ECHO off
SUBST f: d:mountdb
SUBST g: d:mountlog

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

代码语言:javascript复制
REGEDIT4

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun]
"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

代码语言:javascript复制
REGEDIT4

[HKEY_CURRENT_USERSOFTWAREMicrosoftWindowsCurrentVersionRun]
"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:

代码语言:javascript复制
psubst

Create the virtual drive:

代码语言:javascript复制
psubst drive1: drive2:path

Delete the virtual drive:

代码语言:javascript复制
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)

代码语言:javascript复制
psubst /P

Restore a virtual drive from the persistent drive, if any:

代码语言:javascript复制
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:

代码语言:javascript复制
psubst drive1: drive2:path /P

Delete the persistent drive from the registry:

代码语言:javascript复制
psubst drive1: /D /P

0 人点赞