Windows:创建不存在驱动器的快捷方式不允许长文件夹和文件名
我正在尝试使用 PowerShell 创建一个针对映射驱动器上的文件的快捷方式。不过,该脚本将在实际映射驱动器之前运行。代码如下:
$Shortcut = (New-Object -ComObject WScript.Shell).CreateShortcut("$Env:USERPROFILE\Desktop\Test.lnk")
$Shortcut.TargetPath = "X:\Folder With Spaces\This is a long filename.txt"
$Shortcut.Save()
由于“X”驱动器尚不存在,因此快捷方式的“目标”字段最终显示的内容如下:
Windows XP:X:\Folder_W\This_is_.txt
Windows 7:X:\Folder_With_Spaces\This_is_a_long_filename。 txt
两个操作系统都会删除周围的双引号并将空格转换为下划线。 Windows XP 还将文件夹和文件名截断为 8 个字符。
有办法解决这个问题吗?
I'm trying to use PowerShell to create a shortcut that targets a file on a mapped drive. This script will be running before the drive is actually mapped, though. Here's the code:
$Shortcut = (New-Object -ComObject WScript.Shell).CreateShortcut("$Env:USERPROFILE\Desktop\Test.lnk")
$Shortcut.TargetPath = "X:\Folder With Spaces\This is a long filename.txt"
$Shortcut.Save()
Because the "X" drive doesn't exist yet, this is what the shortcut's "Target" field ends up saying:
Windows XP: X:\Folder_W\This_is_.txt
Windows 7: X:\Folder_With_Spaces\This_is_a_long_filename.txt
Both operating systems remove the surrounding double quotes and convert the spaces into underscores. Windows XP also truncates the folder and filenames to 8 characters.
Is there a way around this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道您是否可以在不检查 TargetPath 的情况下绕过它。
我建议对目标使用 UNC 路径,这样它就不会依赖于所映射的驱动器。
I don't know that you can get around it not checking the TargetPath.
I would suggest using the UNC path for the target so it does not depend on the drive being mapped.