Link to home
Start Free TrialLog in
Avatar of sirbounty
sirbountyFlag for United States of America

asked on

Programmatically change Icon for desktop shortcut...

First of all - is this possible?  I know it can be done, but can it be done for each profile if the change is applied to say All Users\Desktop\Shortcut.lnk?

Secondly - any guidance on this.  We're using a product called Netbackup and the default shortcut placed on the desktop points to an invalid icon - I'd like to correct this, but across 90+ servers, I'd rather script a solution...

WSH/WMI/VBS preferred
Avatar of yermej
yermej

You'll want to do something like this:

dim strIcon, strCutPath, oShell, oCut

strIcon = "notepad.exe, 0"  ' the correct icon as specified by file name, position in the file
strCutPath = "c:\document & settings\all users\desktop\shorcut.lnk" ' the shortcut you want to change

set oShell = WScript.CreateObject("WScript.Shell")
set oCut = WShell.CreateShortcut(strCutPath)
oCut.IconLocation = strIcon
oCut.Save
Avatar of sirbounty

ASKER

Any way to have this loop through a list of servers?

Or maybe I can just deploy it locally - I already have code to do that...let me test this...thanx.
Using this - I get "unable to save shortcut".  Here's the code:

dim strIcon, strPath
dim oShell, oCut

strIcon="E:\VERITAS\NetBackup\bin\nbconsole.exe, 0"
strPath="%AllUsersProfile%\Desktop\NetBackup Administration Consol (E).lnk"

Set oShell = Wscript.CreateObject("Wscript.Shell")
Set oCut = oShell.CreateShortcut(strPath)

oCut.IconLocation = strIcon
oCut.Save

Set oCut=Nothing
Set oShell=Nothing
 
I've also tried using a dll that contains about 7 different icons - still no go... :(
Any ideas?
ASKER CERTIFIED SOLUTION
Avatar of yermej
yermej

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My apologies; I confused my operators.

This line above:
if oFile.attributes & 1 then oFile.attributes = oFile.attributes - 1

should read:
if oFile.attributes and 1 then oFile.attributes = oFile.attributes - 1

Part of the problem may have been I'm running this from E: and AllUsersProfile is on C:...
But thanx - it works! :^)