简体   繁体   English

如何访问开始菜单路径?

[英]How can I access to Start Menu path?

I need to get files from C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs and its subfolders. 我需要从C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs及其子文件夹中获取文件。

I'm trying to get them like this: 我正在努力让他们像这样:

string path = @"C:\ProgramData\Microsoft\Windows\Start Menu\";
string[] lnks = Directory.GetFiles(path, "*.lnk", SearchOption.AllDirectories);`

But it giving me an error: 但这给了我一个错误:

An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll Access denied to the path : 'C:\ProgramData\Microsoft\Windows\Start Menu\Programs'

And those are what I tried to get access to that path; 这些就是我试图访问该路径的方法。

<requestedExecutionLevel  level="highestAvailable" uiAccess="false" /> to the app.manifest

File.GetAccessControl(path); in codes 在代码中

Starting Visual Studio as Admin 以管理员身份启动Visual Studio

None of them worked. 他们都没有工作。 So how can I get those files from that path? 那么如何从该路径获取那些文件?

The problem with that folder is the presence of a ReparsePoint folder with a name localized for your culture (for example in my machine I have folder named "Programmi" (the reparse point) and the real folder named "Programs") 该文件夹的问题是存在一个ReparsePoint文件夹,该文件夹的名称已针对您的区域性进行了本地化(例如,在我的计算机中,我有一个名为“ Programmi”(重新解析点)的文件夹和一个名为“ Programs”的真实文件夹)

Directory.GetFiles seems to fail when trying to read a ReparsePoint folder but you can avoid it with code like this 尝试读取ReparsePoint文件夹时,Directory.GetFiles似乎失败,但是您可以使用如下代码避免它

string path = @"C:\ProgramData\Microsoft\Windows\Start Menu\";
string[] dirs = Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly);
foreach (string s in dirs)
{
    DirectoryInfo di = new DirectoryInfo(s);
    if (!di.Attributes.HasFlag(FileAttributes.ReparsePoint)) 
    {
        string[] lnks = Directory.GetFiles(s, "*.lnk", SearchOption.AllDirectories);
    }
}

You can try this 你可以试试这个

string allUsers=Environment.GetEnvironmentVariable("ALLUSERSPROFILE")+ "\\Start Menu\\Programs"; 字符串allUsers = Environment.GetEnvironmentVariable(“ ALLUSERSPROFILE”)+“ \\开始菜单\\程序”;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM