简体   繁体   English

如何获取环境变量名称

[英]How to get environment variable Name

I have user call 'amsd' which path is 'C:\\Users\\amsd'.我有用户调用“amsd”,路径是“C:\\Users\\amsd”。 After that I changed the user name to 'other'.之后,我将用户名更改为“其他”。 But the path is not changed, its name is same as before.但是路径没有改变,它的名字和以前一样。 But now what I am trying to do is, I need to access that path from my current user.但是现在我要做的是,我需要从当前用户访问该路径。 Lets assume that I know only the user name (other) not the path variable name (c:\\users\\amsd).假设我只知道用户名(其他)而不知道路径变量名(c:\\users\\amsd)。 But I need to access that path.但我需要访问该路径。 How can I do that.我怎样才能做到这一点。 I tried System.Environment.GetEnvironmentVariable("other");我试过System.Environment.GetEnvironmentVariable("other"); But its reutrning null value但它的返回空值

I have username.我有用户名。 So what i did is passing my username as parameter to NTAccount constructor and getting sid of user.所以我所做的是将我的用户名作为参数传递给 NTAccount 构造函数并获取用户的 sid。 below is the code.下面是代码。

NTAccount f = new NTAccount(username);
SecurityIdentifier s  = (SecurityIdentifier)f.Translate(typeof(SecurityIdentifier));
string sid = s.ToString();

after that using that sid i am getting profile folder by reading the value from registry using below path.之后使用该 sid 我通过使用以下路径从注册表中读取值来获取配置文件文件夹。

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

under that path there is key call profileimagepath there i can get the user profile pat在该路径下有关键调用 profileimagepath 在那里我可以获得用户配置文件 pat

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM