已经系统用户名,获得该用户所对应的C:\Users\ABC\AppData\Roaming路径
已经系统用户名,取得该用户所对应的C:\Users\ABC\AppData\Roaming路径
请问,我已经windows用户名,想取得windows用户名所对应的C:\Users\ABC\AppData\Roaming这个路径。
例如:windows用户现在为ABC,所对应的路径是C:\Users\ABC\AppData\Roaming。
如果windows用户ABC改名为AB,所对应的路径也是C:\Users\ABC\AppData\Roaming。
应该怎么做哪?请指教。谢谢。
------解决方案--------------------
我已经windows用户名
->
能说中文么,这是中文语法么.
你现在是已经获取到用户名,还是什么意思
已经获取到用户名,不就是把字符串拼接一下就完了
string path=@"C:\Users\"+用户名+@"\AppData\Roaming";
------解决方案--------------------
Environment.GetFolderPath
------解决方案--------------------
查windows注册表即可。
------解决方案--------------------
取得用户名可以用
System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(
@"\\" + System.Environment.MachineName + @"\root\cimv2",
"Select * from Win32_Account Where LocalAccount = True AND SIDType = 1");
foreach (System.Management.ManagementObject obj in searcher.Get())
{
System.Console.WriteLine(obj.Properties["Name"].Value);
}
------解决方案--------------------
这样来做吧
static void Main(string[] args)
{
System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(
@"\\" + System.Environment.MachineName + @"\root\cimv2",
"SELECT * FROM Win32_Account WHERE LocalAccount = True AND SIDType = 1");
foreach (System.Management.ManagementObject obj in searcher.Get())
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(string.Format(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\{0}", obj.Properties["SID"].Value));
if (key != null)
System.Console.WriteLine(string.Format("{0}\t\t{1}", obj.Properties["Name"].Value, key.GetValue("ProfileImagePath")));
}
System.Console.ReadKey();
}
请问,我已经windows用户名,想取得windows用户名所对应的C:\Users\ABC\AppData\Roaming这个路径。
例如:windows用户现在为ABC,所对应的路径是C:\Users\ABC\AppData\Roaming。
如果windows用户ABC改名为AB,所对应的路径也是C:\Users\ABC\AppData\Roaming。
应该怎么做哪?请指教。谢谢。
------解决方案--------------------
我已经windows用户名
->
能说中文么,这是中文语法么.
你现在是已经获取到用户名,还是什么意思
已经获取到用户名,不就是把字符串拼接一下就完了
string path=@"C:\Users\"+用户名+@"\AppData\Roaming";
------解决方案--------------------
Environment.GetFolderPath
------解决方案--------------------
查windows注册表即可。
------解决方案--------------------
取得用户名可以用
System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(
@"\\" + System.Environment.MachineName + @"\root\cimv2",
"Select * from Win32_Account Where LocalAccount = True AND SIDType = 1");
foreach (System.Management.ManagementObject obj in searcher.Get())
{
System.Console.WriteLine(obj.Properties["Name"].Value);
}
------解决方案--------------------
这样来做吧
static void Main(string[] args)
{
System.Management.ManagementObjectSearcher searcher = new System.Management.ManagementObjectSearcher(
@"\\" + System.Environment.MachineName + @"\root\cimv2",
"SELECT * FROM Win32_Account WHERE LocalAccount = True AND SIDType = 1");
foreach (System.Management.ManagementObject obj in searcher.Get())
{
RegistryKey key = Registry.LocalMachine.OpenSubKey(string.Format(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\{0}", obj.Properties["SID"].Value));
if (key != null)
System.Console.WriteLine(string.Format("{0}\t\t{1}", obj.Properties["Name"].Value, key.GetValue("ProfileImagePath")));
}
System.Console.ReadKey();
}