我目前正在使用此:
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
访问登录用户的AppData文件夹。结果是这样的路径:
"C:\\Documents and Settings\\Michael\\Application Data"
但是:要在另一个用户上运行该程序,我将启动一个新的进程,如下所示:
try {
var processInfo = new ProcessStartInfo() {
FileName = System.Reflection.Assembly.GetExecutingAssembly().Location,
UserName = txtWinLoginUsername.Text,
Password = txtWinLoginPassword.SecurePassword,
Domain = this.domain,
UseShellExecute = false, //kein Plan
};
//start program
Process.Start(processInfo); //execute
Application.Current.MainWindow.Close(); //close current Window if it worked
} catch {
//Windows login failed //reset PasswordBox etc.
}
并杀死当前的。
所以我想要的是新的AppData文件夹,但AppData调用会产生默认的文件夹:
"C:\\Documents and Settings\\Default\\Application Data"
我需要的是我的程序正在使用的线程用户的ApplicationData。而且我不喜欢使用Substring之类的东西(仅在必须使用时:)
您需要设置LoadUserProfile = true
您ProcessStartInfo
的用户个人资料不可用:
var processInfo = new ProcessStartInfo
{
FileName = System.Reflection.Assembly.GetExecutingAssembly().Location,
UserName = txtWinLoginUsername.Text,
Password = txtWinLoginPassword.SecurePassword,
Domain = this.domain,
UseShellExecute = false, //kein Plan
LoadUserProfile = true
//^^^^^^^^^^^^^^^^^^^^
//Add this line
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句