通常创建网络映射,都是利用 bat 批处理命令的 net use。但这样的缺陷就是,必须指定盘符。这种情况下,26 个盘符就是最大创建数量。为了绕过这个限制,我们可以通过在网络位置里创建快捷方式的方法来处理。这个逻辑简单,也方便操作。
思路
查找“网络位置”的路径,然后在“网络位置”中创建快捷方式
代码实现
- 获取“网络位置” 查找注册表 “softwaremicrosoftwindowscurrentversionexplorershell folders” 获取 Nethood 的值
RegistryKey.GetValue("Nethood").ToString();
2. 创建快捷方式
using IWshRuntimeLibrary;using Microsoft.Win32;public static void CreateRemoteLink(string LocalName, string RemoteName, string TargetFilePath){ WshShell shell = new WshShell(); IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(TargetFilePath); shortcut.TargetPath = RemoteName; shortcut.Save();}