我想,有没有办法在C#作为一个程序,找出用户的系统中可用列表I,E在我的电脑和路径的目录。我的意思是说假设有2个用户C#程序列表中的用户和他们各自的路径,以他们的目录
“用户A” 和 “用户B”
而且他们的路径我指的是用户A的所有文件将在d:\的Documents and Settings \用户A 同样地,对于用户B
有没有在C#中的任何方法来找出用户的列表和路径各自的目录中。
我想,有没有办法在C#作为一个程序,找出用户的系统中可用列表I,E在我的电脑和路径的目录。我的意思是说假设有2个用户C#程序列表中的用户和他们各自的路径,以他们的目录
“用户A” 和 “用户B”
而且他们的路径我指的是用户A的所有文件将在d:\的Documents and Settings \用户A 同样地,对于用户B
有没有在C#中的任何方法来找出用户的列表和路径各自的目录中。
你可以做到这一点
string users_reg_key=
@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\DocFolderPaths";
public string[] ListWinUsersList()
{
//The registry key for reading user list.
RegistryKey key =
Registry.LocalMachine.OpenSubKey(users_reg_key, true);
string[] winusers = " ".Split(' ');//this resolve problem with assigned variable
if (key != null && key.ValueCount > 0)
{
winusers = key.GetValueNames();
}
return winusers;
}
编辑
取得目录尝试这样的事情
string path = Directory.GetParent(Environment.GetFolderPath(Environment.
SpecialFolder.ApplicationData)).FullName;
if (Environment.OSVersion.Version.Major >= 6) {
path = Directory.GetParent(path);
}
mp3duck,在问题和[标签示例路径:窗口]标签......这很明显,不是吗? – Joey 2012-04-27 07:00:01
太早..没有发现窗户标签! :( – mp3duck 2012-04-27 07:00:26
也许这有助于http://stackoverflow.com/questions/5247798/get-list-of-local-computer-usernames-in-windows – dknaack 2012-04-27 07:01:23