Windows: creating a shortcut to a non-exist drive doesn't allow long folder and filenames
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 t开发者_Go百科o 8 characters.
Is there a way around this problem?
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.
精彩评论