2016-01-15 106 views
0

我需要的快捷方式目標的路徑從 「google.com」 到 「yahoo.com」 使用下面的VBScript改變:當我從CMD修改快捷方式目標路徑?

cscript file.vbs 

我運行此

Set sh = CreateObject("WScript.Shell") 
Set shortcut = sh.CreateShortcut("C:\Wherever\Shortcut.lnk") 
shortcut.TargetPath = "C:\Program Files(x86)\Internet Explorer\iexplore.exe" http://www.google.com" 
shortcut.Save 

出現以下錯誤:

excepted end of statement

我需要添加<script language=script>或其他什麼?

+0

什麼類型的錯誤? – manRo

+0

你的腳本對我來說非常棒,即使是所有奇怪的間距。請發佈您收到的錯誤。 –

回答

0

這個工作對我來說:

Set sh = CreateObject("WScript.Shell") 
Set shortcut = sh.CreateShortcut("C:\temp\Shortcut.lnk") 
shortcut.TargetPath = "c:\temp" 
shortcut.Save 

另外,你的腳本完全擔任,是我創建c:\wherever\後。

enter image description here

請發表您的錯誤,如果它仍然不能確保該文件夾存在後工作。

0

目標路徑字符串的語法不正確。您需要在整個字符串周圍放置雙引號,並且需要在字符串內部的Internet Explorer路徑中放置雙引號,因爲該路徑包含空格。在VBScript中,通過加倍雙引號可以避免雙引號內的雙引號。

改變這一行:

shortcut.TargetPath = "C:\Program Files(x86)\Internet Explorer\iexplore.exe" http://www.google.com" 

到這一點:

shortcut.TargetPath = """C:\Program Files(x86)\Internet Explorer\iexplore.exe"" http://www.google.com" 

和錯誤將消失。