为什么通过SHELL32广大读者的快捷方式,当我得到E_ACCESSDENIED? [英] Why do i get E_ACCESSDENIED when reading public shortcuts through Shell32?

查看:191
本文介绍了为什么通过SHELL32广大读者的快捷方式,当我得到E_ACCESSDENIED?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读的所有桌面快捷方式的目标,在C#4的应用程序。在Windows桌面上的快捷方式可能来自一个以上的位置,这取决于所有用户或只是当前用户的快捷方式是否被创建。在这个特定的情况下,我试图读取从公共桌面上的快捷方式,例如:从C:\用户\公用\桌面\ shortcut.lnk

I'm trying to read the targets of all desktop shortcuts in a C# 4 application. The shortcuts on a windows desktop can come from more that one location, depending on whether the shortcut is created for all users or just the current user. In this specific case I'm trying to read a shortcut from the public desktop, e.g. from C:\Users\Public\Desktop\shortcut.lnk.

在code是这样的(路径是一个字符串contaning的路径LNK文件):

The code is like this (path is a string contaning the path to the lnk file):

var shell = new Shell32.ShellClass();
var folder = shell.NameSpace(Path.GetDirectoryName(path));
var folderItem = folder.ParseName(Path.GetFileName(path));
if (folderItem != null)
{
    var link = (Shell32.ShellLinkObject)folderItem.GetLink;

最后一行抛出System.UnauthorizedAccessException的,这表明它不能读取快捷方式文件的内容。我曾尝试在快捷方式文件的用户的私人桌面(C:\用户\用户名\桌面)上,并能正常工作

The last line throws an System.UnauthorizedAccessException, indicating that it's not allowed to read the shortcut file's contents. I have tried on shortcut files on the user's private desktop (c:\Users\username\Desktop) and that works fine.

所以,我的问题是:

(1)为什么我的应用程序不允许/读/从code快捷键,当我可以清楚地读取其中的内容为用户?

(1) why is my application not allowed to /read/ the shortcut from code, when I can clearly read the contents as a user?

(2)有没有办法来解决这个问题?也许使用一个特殊的清单文件的应用程序?

(2) is there a way to get around this? Maybe using a special manifest file for the application?

和,顺便说一句,我的操作系统是Windows 7,64位。

And, by the way, my OS is Windows 7, 64-bit.

很好

-h -

推荐答案

是的,你不能默认访问.lnk文件的文件夹中。您正在创建一个COM对象,它允许你修改的.lnk属性。而这需要与UAC的管理员级别的帐户被关闭。

Yes, you cannot get access to the .lnk file in that folder by default. You are creating a COM object that allows you to modify the .lnk properties. And that requires an administrator level account with UAC turned off.

是的,您可以修复<一href="http://stackoverflow.com/questions/2818179/how-to-force-my-c-program-to-run-as-administrator-on-windows-7/2818776#2818776">with清单。

这篇关于为什么通过SHELL32广大读者的快捷方式,当我得到E_ACCESSDENIED?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆