查找当前用户名. [英] Finding the current Username.

查看:87
本文介绍了查找当前用户名.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Windows Vista下使用C#几年了,但是目前开始双重引导Ubuntu 11.10.我了解在Windows中查找当前用户的概念,即

I have used C# for a few years now under Windows Vista but currently started dual-booting Ubuntu 11.10. I Understand the concept of finding the current User in Windows which is

string user = System.Environment.UserName


我目前使用的是Mono Develop,我一直尝试使用Google,直到比起初开始更困惑为止.如果有人有什么想法或建议可以进一步帮助我.我当前使用的代码如下所示,但是我确定必须有一个更好的解决方案.


I am currently using Mono Develop, I have tried Google until I was more confused than when I originally started. If someone has any idea''s or suggestions that could help me out further. The code that I currently Use looks like this but I''m sure there has to be a better solution.

  private static class Users     	
  {	
      public static string Current()
      {				
       string[] PathParts = Application.StartupPath.Split('/');					
       if(PathParts.Length <= 2 || !Environment.OS.IsUnix())
       {						
	  return null;
       }	
	  return PathParts[2];
       }
    }
<pre lang="c#">

推荐答案

我认为使用
获取用户名的正确方法
I think correct way to get the User Name using
System.Security.Principal.WindowsIdentity.GetCurrent().Name



它提供了以用户身份运行的用户名应用程序.



It gives, user name application running as user.


这篇关于查找当前用户名.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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