Solved

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

Posted on 2003-12-03
1
376 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

930 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now