简体   繁体   中英

How can I access to Start Menu path?

I need to get files from C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs and its subfolders.

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

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")

Directory.GetFiles seems to fail when trying to read a ReparsePoint folder but you can avoid it with code like this

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";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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