Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using this code for getting Target of shortcut file. It generates the exception Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)). It is work fine on windows XP. But giving above exception on Windows vista and 7.
Please help me how to resolve this.
C#
public static string GetShortcutTargetFile(string shortcutFilename)
     {
         string pathOnly = System.IO.Path.GetDirectoryName(shortcutFilename);
         string filenameOnly = System.IO.Path.GetFileName(shortcutFilename);

         Shell shell = new Shell();
         Folder folder = shell.NameSpace(pathOnly);
         FolderItem folderItem = folder.ParseName(filenameOnly);
         if (folderItem != null)
         {
                 Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
                 return link.Path;
         }
         return string.Empty;
     }

[edit(zorgoz): code block]
Posted
Updated 30-Aug-12 0:42am
v4
Comments
Zoltán Zörgő 30-Aug-12 6:44am    
Ok, but what is in shortcutFilename? Which row is throwing the exception? Is it throwing the exception also if you run your code as administrator (elevated rights)?

1 solution

The fact that it works under XP does not mean that it works without modification on Vista or Win7. Have you considered the idea that the user might not have permission to write on that particular path in the newer versions of Windows?

Did you try MSDN? It has some very good documentation :)

Use another path, or request the permission.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900