简体   繁体   English

从列表框中删除未知值

[英]Removing from listbox an unknown value

I've listed all directories from C:\\Users\\ to a listbox. 我列出了所有目录,从C:\\ Users \\到列表框。

listBox1.Items.AddRange(Directory.GetDirectories("C:\\Users\\", "*" , SearchOption.TopDirectoryOnly));

All Users in Windows have the folder \\\\AppData\\\\ but I don't want to mess with these folders because they have important files for windows, assuming a computer's guy using my software have 2 or more windows accounts, all these have \\\\AppData\\\\ folder, with first user I used to do: Windows中的所有用户都有\\\\ AppData \\\\文件夹,但是我不想弄乱这些文件夹,因为它们具有Windows的重要文件,假设使用我的软件的计算机的家伙有2个或更多Windows帐户,所有这些都有\\\\ AppData \\\\文件夹,我曾经做过第一个用户:

listbox1.items.remove("C:\\Users\\" + Environment.UserName + "\\AppData\\")

but I don't know the others users name, there is any way to remove all AppData folders in listbox without knowing the username? 但我不知道其他用户名,有什么方法可以在不知道用户名的情况下删除列表框中的所有AppData文件夹?

you can get the user names using this code 您可以使用此代码获取用户名

class Program
{
    static void Main(string[] args)
    {

        SelectQuery query = new SelectQuery("Win32_UserAccount");
        ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
        foreach (ManagementObject envVar in searcher.Get())
        {
            Console.WriteLine("Username : {0}", envVar["Name"]);
        }

        Console.ReadLine();

    }
    // end of class
}

you might need to add reference for System.Management 您可能需要为System.Management添加参考

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

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