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
LVL 67
sirbountyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

yermejCommented:
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
sirbountyAuthor Commented:
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.
sirbountyAuthor Commented:
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
 
Your Guide to Achieving IT Business Success

The IT Service Excellence Tool Kit has best practices to keep your clients happy and business booming. Inside, you’ll find everything you need to increase client satisfaction and retention, become more competitive, and increase your overall success.

sirbountyAuthor Commented:
I've also tried using a dll that contains about 7 different icons - still no go... :(
Any ideas?
yermejCommented:
I think that error indicates a shortcut with the read-only attribute set. This updated code should fix that, but I've had strange things happen in the past when trying to change file attributes with WSH - sometimes the change worked, others it didn't and I couldn't discern a pattern.

By the way, this is a handy link for any WSH work: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/vtoriMicrosoftWindowsScriptTechnologies.asp

dim strIcon, strPath
dim oShell, oCut, oFS, oFile

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

' this section should fix the issue
Set oFS = Wscript.CreateObject("Scripting.FileSystemObject")
Set oFile = oFS.GetFile(strPath)
if oFile.attributes & 1 then oFile.attributes = oFile.attributes - 1

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

oCut.IconLocation = strIcon
oCut.Save

Set oCut=Nothing
Set oShell=Nothing
Set oFile=Nothing
Set oFS=Nothing

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yermejCommented:
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

sirbountyAuthor Commented:
Part of the problem may have been I'm running this from E: and AllUsersProfile is on C:...
But thanx - it works! :^)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.