2016-12-27 56 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方法“页面创建一个新的快捷方式,或打开一个现有的快捷方式。

因此,似乎没有理由检查捷径是否存在,因为它不会创建重复。