运行 如何使用 Windows 中的脚本创建多个快捷方式(.lnk 文件)?

How to run several shortcuts (.lnk files) with a script in Windows?

我正在尝试为 运行 我在特定项目中使用的所有工具创建一个脚本(dor 实例,gulp,phpstorm,php 服务器等)

我想要 运行 快捷方式而不是可执行文件。我可以在 Windows:

中看到两种可能的实现方式
  1. VbScript
  2. cmd.exe

不幸的是,我都失败了:

1) WshShell 启动 .lnk 文件,我找不到替代方法:

为此,我正在尝试编写 .cmd 文件或 .vbs 但是,我在各个方面都遇到了问题。

Dim WshShell

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad.exe" ' Works alright
WshShell.Run "C:\Users\eugene\Desktop\gulp EngMe.lnk" ' got an Exception: Unknown Exception

2) .cmd 脚本等待关闭之前启动的应用程序:

@rem urls and filesystem shortcuts start alright:
"C:\Users\eugene\Desktop00.url"
"C:\Users\eugene\Desktop\project_folder.lnk"

@rem the following two commands are starting sequentially, when the previous one has closed.
"notepad.exe"
@rem shortcut to %windir%\system32\notepad.exe:
"C:\Users\eugene\Desktop\Notepad_.lnk"

我做错了什么,有没有其他方法可以做我正在尝试的事情?

尝试使用 powershell 编写脚本。

看问题- Execute shortcuts like programs

查看 Mark Schill 的回答,使用 invoke-item 启动 .lnk 文件,如程序。

这可能是您应对脚本挑战的最佳方式。

您可以检查能够读取.lnk 文件属性的shortcutjs.bat。有了这个,您将在正确的工作目录中执行当前目录中的所有 .lnk 个文件:

@echo off

for %%# in (*.lnk) do (
    call :executeShortcut "%%#"
)

exit /b %errorlevel%
:executeShortcut - %1 - shortcut to execute
setlocal enableDelayedExpansion
for /f "tokens=1,* delims=:" %%a in ('call shortcutjs.bat -examine %1') do (
    if /i "%%a" equ "Target" (
        set "target=%%b"
        set "target=!target:~1!"
    )

    if /i "%%a" equ "Working Directory" (
        set "workdir=%%b"       
        set "workdir=!workdir:~1!"
    )
)

start "%target%" /d "%workdir%" /wait /b "%target%"
exit /b %errorlevel%

带空格的路径必须是 "quoted" 当馈送到 .Run 时,所以:

WshShell.Run """C:\Users\eugene\Desktop\gulp EngMe.lnk"""

会很好用。