如何获取默认用户文件夹(例如c:\ users \ Default) [英] How do you get the Default Users folder (e.g. c:\users\Default)

查看:36
本文介绍了如何获取默认用户文件夹(例如c:\ users \ Default)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经查看了Environment.GetFolderPath方法和System.Environment.SpecialFolder枚举,但看不到任何返回Default Users文件夹路径的东西.

I've looked at the Environment.GetFolderPath method and the System.Environment.SpecialFolder enum but I couldn't see anything that returns the path of the Default Users folder.

有人可以告诉我如何以编程方式获取默认用户"文件夹(或更好的默认用户AppData本地"文件夹路径,例如c:\ users \ Default \ AppData \ Local),因为我需要将一些文件复制到该文件夹​​中?

Can someone please tell me how to get the Default Users folder (or even better the Default Users AppData Local folder path e.g. c:\users\Default\AppData\Local) programmatically as I need to copy some files into this folder?

谢谢

推荐答案

网络上有很多文章描述如何更改默认用户配置文件路径:

There are lots of articles on the web that describe how to change the Default User Profile path:

http://support.microsoft.com/kb/214636

http://www.nextofwindows.com/how-to-change-user-profile-default-location-in-windows-7/

他们都说当前的默认配置文件路径存储在以下注册表位置:

They all say the current Default Profile Path is stored in the following registry location:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList

例如%SystemDrive%\ Users \ Default

e.g. %SystemDrive%\Users\Default

我找到了此页来获取系统驱动器:如何获取当前Windows目录,例如C#中的C:\

And I found this page to get the System Drive: How to get current windows directory e.g. C:\ in C#

Path.GetPathRoot(Environment.SystemDirectory)

所以我将使用它.感谢您的帮助.

So I'm going to use that. Thanks for your help.

更新

我刚刚尝试了以下代码,它返回C:\ Users \ Default.因此,无需替换存储在注册表项中的%SystemDrive%文本.它会自动替换它.

I've just tried the following code and it returns C:\Users\Default. So there is no need to replace the %SystemDrive% text stored in the registry key. It replaces it automatically.

using (RegistryKey profileListKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"))
{
    string defaultPath = profileListKey.GetValue("Default").ToString();
}

这篇关于如何获取默认用户文件夹(例如c:\ users \ Default)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆