2016-12-27 55 views
-2

我做了一個腳本,檢查用戶桌面上是否存在鏈接,如果沒有找到,它會創建它。 但是然後我想要那個鏈接改變圖標,我不知道該怎麼做。我嘗試使用我創建的objDesktop,但它似乎是不同類型的對象,所以我不能使用ParseNameGetLink來對付它。如何在創建鏈接後更改鏈接的圖標?

代碼示例如下:

Set wShell = CreateObject("Wscript.Shell") 
Set objFso = WScript.CreateObject("Scripting.FileSystemObject") 
Set objDesktop = objFso.GetFolder(wShell.SpecialFolders("Desktop")) 

linkName = "\Notepad.lnk" 
fullLinkPath = objDesktop & linkName 

If (objFso.FileExists(fullLinkPath)) = False Then 
    Set shortcut = wShell.CreateShortcut(fullLinkPath) 
    shortcut.targetpath = "c:\Windows\notepad.exe" 
    shortcut.Save 
End If 

'from here, I want that freshly created link to have its icon replaced with 
'another ico file that will be provided. 

我想保持代碼的簡單和最小的越好,所以如果我的方法到現在爲止是不會導致我到一個一致的結果,請給我一個更好的代碼示例。

+3

與創建鏈接的方式非常相似,只需刪除if並更改圖標即可。 'shortcut.IconLocation =「%SystemRoot%\ system32 \ SHELL32.dll,1」' – LotPings

回答

0

發現祕密:通過不使用if並直接調用.CreateShortcut。 「從MSDN上的」CreateShortcut方法「頁面創建一個新的快捷方式,或打開一個現有的快捷方式。

因此,似乎沒有理由檢查捷徑是否存在,因爲它不會創建重複。