使用Java,如何在Windows机器上获取所有本地用户的列表 [英] Using Java, How can I get a list of all local users on a windows machine

查看:115
本文介绍了使用Java,如何在Windows机器上获取所有本地用户的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用java列出在Windows机器(Win2000 +)上配置的所有本地用户。

我更喜欢使用任何java 2 com桥接器或任何其他第三方库来执行此操作可能。

优先使用Java的一些本机方法。

How can I list all the local users configured on a windows machine (Win2000+) using java.
I would prefer doing this with ought using any java 2 com bridges, or any other third party library if possible.
Preferable some native method to Java.

推荐答案

使用Java-COM Bridge,如雅各布。然后,您可以选择适当的COM库,例如 WMI的COM API 列出本地用户,或任何其他Windows管理信息。

Using a Java-COM Bridge , like Jacob. You then select an appropriate COM library, e.g. COM API for WMI to list local users, or any other Windows management information.

Win32_SystemUsers 关联WMI类涉及该系统上的计算机系统和用户帐户。

The Win32_SystemUsers association WMI class relates a computer system and a user account on that system.

Win32_Account 抽象WMI类包含有关已知用户帐户和组帐户的信息到运行Windows的计算机系统。 Windows NT域识别的用户名或组名是此类的后代(或成员)。

The Win32_Account abstract WMI class contains information about user accounts and group accounts known to the computer system running Windows. User or group names recognized by a Windows NT domain are descendants (or members) of this class.

工作示例(jacob 1.17-M2,javaSE-1.6):

Working Example (jacob 1.17-M2, javaSE-1.6):

import java.util.Enumeration;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.EnumVariant;
import com.jacob.com.Variant;

public class ComTst {
public static void main(String[] args) {
    ComThread.InitMTA();
    try {
        ActiveXComponent wmi = new ActiveXComponent("winmgmts:\\\\.");
        Variant instances = wmi.invoke("InstancesOf", "Win32_SystemUsers");
        Enumeration<Variant> en = new EnumVariant(instances.getDispatch());
        while (en.hasMoreElements())
        {
            ActiveXComponent bb = new ActiveXComponent(en.nextElement().getDispatch());
            System.out.println(bb.getPropertyAsString("PartComponent"));
        }
    } finally {
        ComThread.Release();
    }
}
}

这篇关于使用Java,如何在Windows机器上获取所有本地用户的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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