使用批处理文件在桌面上创建快捷方式并重命名

使用批处理文件在桌面上创建快捷方式并重命名

早上好,
我修改了下面这段代码,以便映射几个网络驱动器。我希望对其进行修改(但我不知道如何修改),以便它映射网络驱动器,在桌面上为每个驱动器创建一个快捷方式,适当地重命名快捷方式,然后我猜他们第一次打开它们时会要求输入密码。如果可能的话,如果你能让一些可更改的内容在哪里显而易见,比如“桌面“名字或其他东西。我会从您的意见中学习!谢谢!”

@net use M: \\10.0.0.120\Media Folder\Movies /persistent: yes

@echo Create new P: drive mapping 
@net use P: \\10.0.0.120\Media Folder\Pictures /persistent: yes

@echo Create new S: drive mapping 
@net use S: \\10.0.0.120\Criticals /persistent: yes

@echo Create new L: drive mapping 
@net use F: \\10.0.0.120\Finances & Banking /persistent: yes

@echo Create new N: drive mapping 
@net use N: \\10.0.0.120\Documents /persistent: yes

:Exit
@Pause

答案1

如果第三方工具可以,那么我建议看看 NirCmd。它有一个子命令“快捷方式”,其中包含几个参数,如名称、目标目录、图标文件等,用于设置链接文件。试试这个页面https://www.nirsoft.net/utils/nircmd2.html并搜索以shortcut [跳转到正确的部分。下载位于页面底部https://www.nirsoft.net/utils/nircmd.html

不过,我不确定 NirCmd 是否可以处理 UNC 路径(\\IP\Folder)。在这种情况下,映射的驱动器号应该用作快捷方式文件的目标。

答案2

这是用于创建快捷方式的脚本/子程序。只需更改传递给子程序的参数即可更改快捷方式属性。我相信我已经充分说明了以下脚本中各功能的作用。

@Echo off
::: [ The full path to the program your creating a shortcut for
    Set "ProgramPath=%~F0"
::: ]
::: [ The Name you want for your shortcut
    Set "ProgramName=%~n0"
::: ]
::: [ The full path to your Icon
    Set "IconLocation=%~dp0IconName.ico"
::: ]
::: [ The directory to create and run the powershell script from.
    Set "RunFrom=%TEMP%"
::: ]

::: [ Pass the properties to the subroutine to create the shortcut via powershell
    Call :CreateShortcut "%ProgramPath%" "%ProgramName%" "%IconLocation%" "%RunFrom%"
::: ]
    Exit /B

::: [ Use batch to create and run a powershell script that makes a .Ink file with the desired properties.
:CreateShortcut <Target Program Path> <Shortcut Name> <Icon Path> <Directory to create powershell file in>
    (
    ECHO # Create a Shortcut with Windows PowerShell
    ECHO $SourceFileLocation = "%~1"
    ECHO $ShortcutLocation = "$env:userprofile\Desktop\%~2.lnk"
    ECHO #New-Object : Creates an instance of a Microsoft .NET Framework or COM object.
    ECHO #-ComObject WScript.Shell: This creates an instance of the COM object that represents the WScript.Shell for invoke CreateShortCut
    ECHO $WScriptShell = New-Object -ComObject WScript.Shell
    ECHO $Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation^)
    ECHO $Shortcut.TargetPath = $SourceFileLocation
    ECHO $Shortcut.IconLocation = "%~3"
    ECHO #Save the Shortcut to the TargetPath
    ECHO $Shortcut.Save(^)
    ) >"%~4\CreateShortcut.ps1"
::: - Execute powershell script to create Shortcut on User Desktop
    Powershell.exe -NoProfile -ExecutionPolicy Bypass -File %~4\CreateShortcut.ps1
Exit /B
::: ]

相关内容