前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Windows 符号链接、软硬链接方案(mklink 、subst、psubst、visual subst、Link Shell Extension)

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

原创
作者头像
Windows技术交流
修改2022-06-24 00:17:55
1.7K0
修改2022-06-24 00:17:55
举报
文章被收录于专栏:Windows技术交流Windows技术交流

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

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

一般不推荐嵌套挂载,所谓嵌套挂载,举例来说,\\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://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 Settings\All Users\Shared 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_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:

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

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

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

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

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、Link Shell Extension
  • 二、visual subst
  • 三、psubst
    • Run on boot (batch)
      • Run on boot (registry)
      相关产品与服务
      云服务器
      云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档