Reputation: 464
I am trying to launch a shortcut from VBScript, but I am running into a very odd error.
When I use the relative path of the shortcut, the script opens the shortcut perfectly fine. However, if I use the absolute file path (copied from windows explorer so no typos or anything like that) it gives me an error saying file not found.
Relative path code:
dim x
set x = CreateObject("WScript.shell")
x.Run("Shortcut.lnk")
set x = Nothing
This opens the file.
Absolute path code:
dim x
set x = CreateObject("WScript.shell")
x.Run("C:\Users\*****\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Test\Shortcut.lnk")
set x = Nothing
As you can see, the code is exactly the same. However, it gives me a file not found error:
Script: C:\Users\*****\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Test\test.vbs
Line: 3
Char: 1
Error: The system cannot find the file specified.
Code: 80070002
Source: (null)
The file path for the script is exactly the same in the error as the path I have put in the code, but it still gives me an error.
Any help would be appreciated.
Note: My username has been replaced with ***** just for the question.
Upvotes: 0
Views: 1042
Reputation: 38745
For the shell (.Run, .Exec) pathes containing spaces need quotes. So replace
x.Run("C:\Users\*****\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Test\Shortcut.lnk")
with
x.Run """C:\Users\*****\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Test\Shortcut.lnk"""
Upvotes: 2