【问题标题】:C# program to list the users and their respective paths to their directoriesC# 程序列出用户及其各自目录的路径
【发布时间】:2012-04-27 15:23:10
【问题描述】:

我希望在 C# 中有什么方法可以作为程序来查找系统中可用的用户列表,即在我的计算机中以及他们目录的路径。我的意思是假设有 2 个用户

“用户 A”和“用户 B”

他们的路径我的意思是用户 A 的所有文档都在 D:\Documents and Settings\User A 对于用户 B 也是如此。

在 C# 中有什么方法可以找出用户列表及其各自目录的路径。

【问题讨论】:

标签: c# windows


【解决方案1】:

你可以这样做

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);
}

【讨论】:

  • 我的意思是对于 windows 7 和 windows xp 会是通用的吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-14
相关资源
最近更新 更多