运行VBScript母路径下的所有快捷方式



我想有一个可执行的VBS,在我的VBS的当前文件夹中运行所有windows快捷方式。我的快捷方式是Excel和PDF。我已经做了这个代码,但我有一个错误"WshShell。objFile.Path&quot运行;其他行看起来工作正常

Dim FSO
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
GetCurrentFolder = FSO.GetAbsolutePathName(".")
Set objFolder = FSO.GetFolder(GetCurrentFolder)
For Each objFile in objFolder.Files
If LCase(Right(objFile.Path, 4)) = ".lnk" Then
WshShell.Run objFile.Path
End If
Next

我希望母亲路径适应VBS,所以我可以复制过去的VBS,并把它放在其他文件夹由于

该错误是由于一个或多个文件路径中的空格造成的。通过在路径周围加上引号来纠正这个错误:WshShell.Run """" & objFile.Path & """"

发布的脚本将运行当前目录中的所有快捷方式,而不一定是脚本的目录(例如,如果脚本通过命令行从另一个文件夹启动)。要解决这个问题,请使用:FSO.GetParentFolderName(WScript.ScriptFullName).

这是完整的,修改后的脚本:

Set WshShell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")
GetCurrentFolder = FSO.GetParentFolderName(WScript.ScriptFullName)
Set objFolder = FSO.GetFolder(GetCurrentFolder)
For Each objFile in objFolder.Files
If LCase(Right(objFile.Path, 4)) = ".lnk" Then
WshShell.Run """" & objFile.Path & """"
WScript.Sleep 1000 'adjust as needed 
End If
Next

最新更新