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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieve Shortcut Properties

Status
Not open for further replies.

Beard36

Programmer
Sep 4, 2003
69
GB
I know that using the CreateShortcut method that you can define properties for a shortcut and then create it wherver you like, but my question is can these properties be retrieved from an existing shortcut?

What I really want to do (in case there's an easier way round it), is to find out what icon file a given shortcut is using?

Any ideas?
Any help much appreciated.

Cheers,
Dan.
 
Hello Beard36,

Vbscript documentation has CreateShortCut method, whereas the delete, copy and move are managed by fso. Related to your question in particular, there lacks singularly "GetShortCut" method.

With the above introduction in mind, the inexistent "GetShortCut" is actually realized by CreateShortCut of an _existing_ shortcut, and the properties are then automatically made available to the object (read-write).

Code:
Set Shell = CreateObject("WScript.Shell")
DesktopPath = Shell.SpecialFolders("Desktop")
Set link = Shell.CreateShortcut(DesktopPath & "\winipcfg.lnk")
link.Arguments = ""
link.Description = "winipcfg shortcut"
link.HotKey = "CTRL+ALT+SHIFT+X"
link.IconLocation = ",0"
link.TargetPath = "c:\windows\winipcfg.exe"
link.WindowStyle = 1
link.WorkingDirectory = "d:\test"
link.Save
'[green]Above modelling the documentation, the link is then created already.[/green]
'[red]This is an undocumented feature.
'Re-create an existing link again to get to the preperties.[/red]
Set link = Shell.CreateShortcut(DesktopPath & "\winipcfg.lnk")
wscript.echo link.Description
wscript.echo link.IconLocation
wscript.echo link.Hotkey
wscript.echo link.WindowStyle
wscript.echo link.WorkingDirectory
'etc
set link=nothing

regards - tsuji
 
That's excellent, it really is!

Actually, now I look back under the "CreateShortcut Method" page on MSDN, it does state "Creates a new shortcut, or opens an existing shortcut" which I hadn't noticed before, especially as it makes no further mention of this retrieval ability anywhere else in the documentation.

Anyway, though, it works like a charm.

It seems every other thread I look at round here seems to have a solution posted by you - well done, you must be very wise! ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top