»
S
I
D
E
B
A
R
«
Reading and Creating Shortcuts Information
January 8th, 2009 by admin

Yesterday, I just came accross how to create new and read shorcuts information when my colleague asked for helps on how to read back the information from created shorcuts.

Create new shortcut

// Create a new instance of WshShellClass
WshShell = new WshShellClass();

// Create the shortcut
IWshRuntimeLibrary.IWshShortcut MyShortcut;

// Choose the path for the shortcut
MyShortcut = (IWshRuntimeLibrary.IWshShortcut)WshShell.CreateShortcut(@"C:\MyShortcut.lnk");

// Where the shortcut should point to
MyShortcut.TargetPath = Application.ExecutablePath;

// Description for the shortcut
MyShortcut.Description = "Launch My Application";

// Location for the shortcut's icon
MyShortcut.IconLocation = Application.StartupPath + @"\App.ico";

// Create the shortcut at the given path
MyShortcut.Save();

Read shortcut information

// Create a new instance of WshShellClass
WshShell = new WshShellClass();

// Create the shortcut
WshShortcut MyShortcut;

// Assign the shortcut path
MyShortcut = (WshShortcut)WshShell.CreateShortcut(@"C:\MyShortcut.lnk");

// Get TargetPath of the shortcut
string tragetPath = MyShortcut.TargetPath;

// Get description of the shortcut
string description = MyShortcut.Description;

// Get Location of the shortcut's icon
string IconLocation = MyShortcut.IconLocation;

You must add Interop.IWshRuntimeLibrary.dll as references before you can use the above code.

Download Interop.IWshRuntimeLibrary.dll or install Microsoft Interop Forms Toolkit 2.0.

Hope it helps you.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists
  • blinkbits
  • BlinkList
  • Bumpzee
  • Technorati

One Response  
Brent Gardner writes:
February 20th, 2009 at 10:16 pm

Does your reading of IconLocation return dependable data?

I’m writing a vbscript that reads shortcut info, tweaks it, then creates new shortcuts elsewhere. For some shortcuts, reading IconLocation returns “,0″

If you’ve seen this, have you found a way to work around it?

Brent Gardner

Leave a Reply

»  Substance: WordPress   »  Style: Ahren Ahimsa
© Copyright 2007, www.wengkien.com