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.
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论