Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...At last there is indeed a website/forum that deals with professional and serious matters. Keep up with the good work!!"

Geography

Where in the world do Tek-Tips members come from?

Adding an icon to a shortcutHelpful Member!(2) 

JPJeffery (TechnicalUser)
26 May 06 12:25
Hi

I've seen code that will create a .lnk shortcut but I need to do the equivalent for a .url shortcut. I seem to remember finding the code somewhere on t'internet but then abandoning the idea in favour of a .BAT solution (because I know batch far better) only then to be told that I must use vbscript.

So, I've written working vbscript code to copy the .URL shortcuts from a central repository to the All Users Startup folder but I reckon it'll be quicker, and have less of an impact on the network, if I can produce code to create new shortcuts instead. However, what I can't find anything on is how to specify which icon from a (Windows standard and present on the client PC) .DLL to use for the shortcut instead of the rather dull default IE icon.

This must be possible, right? But how?

Thanks for all responses in advance (as well as afterwards!)

Jeff
Helpful Member!  markdmac (MIS)
26 May 06 15:08
Yes it is possible and easy to do.

The property you want to set is iconlocation

Defines the location of the shortcut’s icon. Typically, its value is the complete path and filename to
the file containing the icon followed by a comma and the zero- based position of the icon within
the file. If the default icon is used, the value of IconLocation is ” ,0”.
TargetPath Sets or returns the path and filename to the shortcut’s executable file.

Here is an example of how to do it.

CODE

SET fso = Wscript.CreateObject("Scripting.FileSystemObject")
SET WshShell = WScript.CreateObject("WScript.Shell")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
strDsk = WshShell.SpecialFolders("Desktop")
strshortcut = strDsk & "\Calculator.lnk"
If Not fso.FileExists(strshortcut) Then
    SET oUrlLink = WshShell.CreateShortcut(strshortcut)
    oUrlLink.TargetPath = Windir & "\System32\Calc.EXE"
    oUrlLink.IconLocation = Windir & "\System32\moricons.dll,6"
    oUrlLink.Save
End If

I hope you find this post helpful.  

Regards,

Mark

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

JPJeffery (TechnicalUser)
26 May 06 15:55
That's marvellous. One query though, will this be significantly different bearing in mind I'm creating a url shortcut (http://www.website.com) rather than to a shortcut to an .exe?

And by the by, how do you add an event to an event log (local or to a server)?

Thanks for this.

JJ
markdmac (MIS)
26 May 06 16:02
There is no difference between a LNK or URL when creating the shortcut as far as this property is concerned.

Sorry I can not assist with writing to the event log.  I suggest posting that question in a new thread so you get new sets of eyes looking to respond.

I hope you find this post helpful.  

Regards,

Mark

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

markdmac (MIS)
26 May 06 16:06
OK Curiosity got the best of me and it turns out it is quite simple.

CODE

Const EVENT_SUCCESS = 0

Set objShell = Wscript.CreateObject("Wscript.Shell")

objShell.LogEvent EVENT_SUCCESS, _
    "Payroll application successfully installed."

I like this so much I can see myself adding this feature to most of my scripts.  Thanks for getting my curiosity up. smile

I hope you find this post helpful.  

Regards,

Mark

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

JPJeffery (TechnicalUser)
26 May 06 18:00
Glad I could help...

winky smile

And thanks for yours!

JJ
JPJeffery (TechnicalUser)
31 May 06 5:05
Just for the record, the IconLocation property doesn't seem to work for .URL icons, only .LNK icons.

As a .LNK icon works just as well as a .URL it's hardly a show-stopper but still...

JJ
Helpful Member!  tsuji (TechnicalUser)
31 May 06 8:41
>Just for the record, the IconLocation property doesn't seem to work for .URL icons, only .LNK icons.

If you want to do it for url shortcut, you can take a look at my post here.
    http://tek-tips.com/viewthread.cfm?qid=919812
markdmac (MIS)
31 May 06 9:47
Sorry I neglected to mention how I cheat on my method.  If you give the icon an extension of LNK but point it to a URL all of the above code works without having to do the extra steps that tsuji points to.  Tsuji's solution is really nice however in that it supports pointing to an ICO file where the Shortcut method only supports pointing to an EXE or DLL.  I usually just go with the DLL method and use a program to add my ICO files to the DLL.

Here is an example that create a link to CNN.Com with a world map icon.

CODE


SET fso = Wscript.CreateObject("Scripting.FileSystemObject")
SET WshShell = WScript.CreateObject("WScript.Shell")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
strDsk = WshShell.SpecialFolders("Desktop")
strshortcut = strDsk & "\CNN.lnk"
If Not fso.FileExists(strshortcut) Then
    SET oUrlLink = WshShell.CreateShortcut(strshortcut)
    oUrlLink.TargetPath = "http://www.cnn.com"
    oUrlLink.IconLocation = Windir & "\System32\moricons.dll,61"
    oUrlLink.Save
End If

I hope you find this post helpful.  

Regards,

Mark

Check out my scripting solutions at http://www.thespidersparlor.com/vbscript

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close