Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Specify Desktop URL Shortcut icon

Status
Not open for further replies.

jamiehill

Programmer
Oct 22, 2002
6
GB
I'm wishing to send a group email that will install a shortcut to the company website with a defined icon, on employees desktops. I'm currently using VBScript to create the shortcut:

Set WshShell = CreateObject("WScript.Shell")
strDesktopPath = WshShell.SpecialFolders("Desktop")
Set objShortcutUrl = WshShell.CreateShortcut(strDesktopPath & "\Virtual Agency.url")
objShortcutUrl.TargetPath = "objShortcutUrl.Save

But how can I embed deploy the appropriate icon and set the shortcut to use this?
 
The IconLocation property sets or retrieves a String that is the location of the icon used to represent the shortcut. The string is of the form "path,index", where path is the full path to the file containing the icon, and index is the zero-based index of the icon within the specified icon file.

Specifying an invalid value for this property will not cause an error. However, the icon that will be displayed for the shortcut may be changed. Setting this property to the empty string restores the shortcut's default icon.


objShortcutUrl.IconLocation = "C:\winnt\system32\shell32.dll,3"
Jamie Gillespie
j-gillespie@s-cheshire.ac.uk
 
Firstly thanks a lot for such a prompt response. Secondly I've already tried this method, but keep receiving the following error:
---------------------------
Windows Script Host
---------------------------
Script: C:\Documents and Settings\JamieH\Desktop\short.vbs
Line: 6
Char: 1
Error: Object doesn't support this property or method: 'objShortcutUrl.IconLocation'
Code: 800A01B6
Source: Microsoft VBScript runtime error

---------------------------
OK
---------------------------

Any further thoughts?
 
Sorry about that, to set the icon you need to create a true shortcut ie a lnk file not a url shortcut. the following script works fine:

Set WshShell = CreateObject("WScript.Shell")
strDesktopPath = WshShell.SpecialFolders("Desktop")
Set objShortcutUrl = WshShell.CreateShortcut(strDesktopPath & "\test.lnk")
objShortcutUrl.TargetPath = "objShortcutUrl.IconLocation = "c:\windows\system32\shell32.dll,2"
objShortcutUrl.Save Jamie Gillespie
j-gillespie@s-cheshire.ac.uk
 
This method is still posing problems.

---------------------------
Windows Script Host
---------------------------
Script: C:\Documents and Settings\JamieH\Desktop\2.vbs
Line: 4
Char: 60
Error: Expected end of statement
Code: 800A0401
Source: Microsoft VBScript compilation error

---------------------------
OK
---------------------------

Does this script work on your desktop? Might it be something to do with my scripting environment?
 
To deploy your own icon you need to create an icon resource using something like Microangelo (freebie icon editor). Jamie Gillespie
j-gillespie@s-cheshire.ac.uk
 
See also this approach:
Otherwise getting an icon written to the users' hard drives can be a chore from a web browser due to security settings. Then again, getting the shortcut there will be just as hard though security-wise.

Things that work from a page stored on your PC may well NOT work from a page on a web server, due to the system of security zones in IE.

So even if you lick the security issue, you have the problem of getting the icon written to a user's hard drive. FSO can create files if your page gets access to it, but it doesn't include binary write capabilities. This might be a toughie.

Look at favicons again perhaps (link above).

Another option may be a custom ActiveX Control written in VB or something. VB can write the binary data (icon) and create a WshShell object to set up the shortcut. Once again you'll have browser ActiveX security to deal with, but that should be the only hurdle.
 
If I specify the IconLocation as a remote server it seems to handle this fine. Obviously should my internet access be stopped, it would no longer find the server and hence no icon.

Would it not be possible having already approved the ActiveX control upon page load - code inserted into homepage HTM - to copy the icon from server to hard disk? eg.

Set WshShell = CreateObject("WScript.Shell")
strDesktopPath = WshShell.SpecialFolders("Desktop")
strWindowsPath = WshShell.SpecialFolders("Windows")
Set objShortcutUrl = WshShell.CreateShortcut(strDesktopPath & "\Virtual Agency.lnk")

// copy file from server to hard disk?
CopyFile "
objShortcutUrl.TargetPath = "objShortcutUrl.IconLocation = strWindowsPath&"\vaicon.ico"
objShortcutUrl.Save

Should this method not theoretically work? My coding probably doesn't but is this not the way forward?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top