Solved

How do I locate and "re-target" a shortcut (.lnk)

Posted on 2003-12-03
1
377 Views
Last Modified: 2013-11-18
I need to write a C# method that will find and "re-target" all shortcuts (eg  .lnk files) that point to a specific target.  I've found some WSH (windows scripting host) examples of creating shortcuts, but I can't seem to find anything that will locate all shortcuts that point to a specific target.

0
Comment
Question by:wile_e_coyote
1 Comment
 
LVL 22

Accepted Solution

by:
_TAD_ earned 250 total points
ID: 9870936


Here is a quick utility to get all of the file pathways with an *.lnk extension.



            private void button1_Click(object sender, System.EventArgs e)
            {
                  ArrayList mylist = GetFiles(@"C:\Documents and Settings","*.lnk",new ArrayList());
                  FileInfo f;

                  for(int i=0;i<mylist.Count;i++)
                        Console.WriteLine(mylist[i].ToString());

            }



            private ArrayList GetFiles(string path, string fileType, ArrayList fileList)
            {
                  string[] childDirectories;
                  string[] files;
                        
                  // find all dlls in the parent and child directories
                  files = Directory.GetFileSystemEntries(path, fileType);
                  
                  for(int i=0;i<files.Length;i++)
                        fileList.Add(files[i]);
                              

                  // load an array list with all of the valid plug-ins
                  childDirectories = Directory.GetDirectories(path);
                  for(int i=0;i<childDirectories.Length;i++)
                        fileList = GetFiles(childDirectories[i], fileType, fileList);

                  return fileList;
            }



But as far as changing the contents of those files... I think you'll need to use WIN API for that.   As far as I know, .NET cannot change the properties of shortcut links.  .Net only manipulates actual files... not the links to files.

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question