从 Java 应用程序获取用户名(windows) [英] Fetching user name (windows) from a java application

查看:39
本文介绍了从 Java 应用程序获取用户名(windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:

我正在使用以下凭据登录虚拟机 (RDC):

I am logging into a virtual machine(RDC) using the below credentials:

该用户是名为 teldept 的域组的一部分

The user is part of a domain group called as teldept

user:147852 pass:helloworld

user:147852 pass:helloworld

当我尝试从 Java 应用程序获取用户详细信息时,它给了我:147852

when i try to get the user details from java application it gives me : 147852

但是当我点击顶部的开始菜单时,我可以看到我的名字显示出来.

but when i click on start menu at the top i can see my Name displayed.

这是怎么做到的?我想从 java 应用程序访问这个名字

How is this done? i want to access this name from java application

我使用以下代码段:

System.getProperty("user.name");

System.getProperty("user.name");

以上代码片段给我的任何内容都是正确的 aper oracle 文档.我使用 ID 登录:147852 及以上代码段给了我 14852但是在 Windows 中这个 ID:147852 是如何映射到我的名字的,所以只有在 XP 的开始菜单中,我才会显示我的名字而不是 147852.我们需要知道这个映射是如何在 ID 和姓名 .我猜它与域或某些我不擅长的网络逻辑有关.

推荐答案

XP 开始菜单上显示的名称不是登录名.它是与登录名对应的全名.不确定您的登录名是本地登录名还是域登录名.如果是本地登录,请转到管理工具 -> 计算机管理 -> 用户和组 -> 此处针对您的用户名 (147852),您将找到一个全名.如果您的登录名是域登录名,您可以类似地在 Active Directory 中查找您的姓名 - 或在其他地方搜索.

The name shown on XP's start menu is not the logon name. It's Full Name Corresponding to the Logon Name. Not sure if your login is a local login or a domain login. If it's a local login, go to Admin Tools -> Computer Management -> Users and Groups -> Here against your username (147852), you will find a full name. If your login is a domain login, you can similarly lookup your name in Active Directory - or search for it at other places.

这是非常特定于操作系统的,Java 无法找到.您需要使用 JNI 和 Windows API 执行此操作 - 根据用户类型调用 GetUserNameExNetUserGetInfo.

This is very OS Specific and cannot be found by Java. You will need to do this using JNI and Windows API - Calling GetUserNameEx or NetUserGetInfo depending on type of user.

如果您只想获取登录名 (147852),调用 com.sun.security.auth.module.NTSystem().getName 比使用 System.getName 更好.getProperty("user.name")

If you just want to get your logon name (147852), calling com.sun.security.auth.module.NTSystem().getName is a better way than using System.getProperty("user.name")

这篇关于从 Java 应用程序获取用户名(windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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