- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在研究如何使用 JACOB 在计算机上拉取本地组的成员。
我能做什么:使用单独的 WMI 查询从计算机中提取本地组列表。我不能做的:拉取这些组的成员。
我使用下面的文章给出了程序的框架:Using Java, How can I get a list of all local users on a windows machine
问题:我相信我的问题要么出在我正在使用的 WMI 查询中,要么出在程序如何使用查询的输出中。
下面是我正在使用的代码。我包含了在代码示例中使用的两个查询。这是“实例”变体。
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 WMITest {
public static void main(String[] args) {
ComThread.InitMTA();
try {
ActiveXComponent wmi = new ActiveXComponent("winmgmts:\\\\.");
//Variant instances = wmi.invoke("InstancesOf", "Win32_Group Where LocalAccount=True");
Variant instances = wmi.invoke("InstancesOf", "Win32_GroupUser WHERE GroupComponent=\"Win32_Group.Domain='.',Name='Administrators'\"");
Enumeration<Variant> en = new EnumVariant(instances.getDispatch());
while (en.hasMoreElements())
{
ActiveXComponent bb = new ActiveXComponent(en.nextElement().getDispatch());
System.out.println(bb.getPropertyAsString("Name"));
}
} finally {
ComThread.Release();
System.exit(1);
}
}
}
最佳答案
请小心查询,因为动词(where)之前必须有一个空格,请注意我的代码
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.ComThread;
import com.jacob.com.EnumVariant;
import com.jacob.com.Variant;
import com.jacob.com.Dispatch;
// you have to add Jacob library into your project
// you have to copy jacob.xx.xx.dll from Jacob Library (both x64 and x86) and paste in c:/...java/jdk/bin (both x64 and x86)
// you can call any class in WMI by checking class and prop by using WMI Explorer.
public class GET_COM_PROPERTIES_CLASS {
// Step 1: Set exported value , you call them from another class.
public static String COMNAME; //Get Computer Name from Win32_Computersystem-
public static String SERIAL_NUMBER; //Get Serial Number from Win32_BIOS-
public static String BIOS_VERSION; //Get Bios Version from Win32_BIOS-
public static String NOTEBOOK_BRAND; //Get Notebook Brand from Win32_Computersystem-
public static String DOMAIN; // Get domain from Win32_Computersystem-
public static String SYSTEM_FAMILY; //Get Laptop model from Win32_Computersystem-
public static String SYSTEM_TYPE; //Get x64 or x86 from Win32_Computersystem-
public static String WORKGROUP; //Get Workgroup name from Win32_Computersystem-
public static String MOTHER_BOARD_PN; //Get ther board partnumber from Win32_MotherboardDevice-
public static String GRAPHIC_CARD_NAME; //Get graphic car name(Prop: name)Win32_VideoController-
public static String GRAPHIC_CARD_VER; //Get graphic card version from Win32_VideoController-
public static String GRAPHIC_SOLUTION; //Get solution of card from Win32_VideoController-
public static String DISK_SIZE; //Get disk size from Win32_DiskDrive-
public static String DISK_INTERFACE_TYPE; //Get IDE or other type of interface from Win32_DiskDrive-
public static String WIN_VERSION; // Get Window version from Win32_OperatingSystem-
public static String WIN_SERIAL_NUMBER; // Get windows serial number from Win32_OperatingSystem
public static void main(String[] args) {
//Step 2: Set Var of ActiveXComponent
ActiveXComponent wmi_Computersystem, wmi_Win32_BIOS, wmi_Win32_MotherboardDevice, wmi_Win32_VideoController,
wmi_Win32_DiskDriver, wmi_Win32_OperatingSystem = null;
//Set SWbemLocator for specify server or your computer and it is used for connect WMI
wmi_Computersystem = new ActiveXComponent("WbemScripting.SWbemLocator");
wmi_Win32_BIOS = new ActiveXComponent("WbemScripting.SWbemLocator");
wmi_Win32_MotherboardDevice = new ActiveXComponent("WbemScripting.SWbemLocator");
wmi_Win32_VideoController = new ActiveXComponent("WbemScripting.SWbemLocator");
wmi_Win32_DiskDriver = new ActiveXComponent("WbemScripting.SWbemLocator");
wmi_Win32_OperatingSystem = new ActiveXComponent("WbemScripting.SWbemLocator");
//Step 3: Call method of SWbemLocator to connect server or your computer
Variant conRet_Computersystem = wmi_Computersystem.invoke("ConnectServer");
Variant conRet_Win32_BIOS = wmi_Win32_BIOS.invoke("ConnectServer");
Variant conRet_Win32_MotherboardDevice = wmi_Win32_MotherboardDevice.invoke("ConnectServer");
Variant conRet_Win32_VideoController = wmi_Win32_VideoController.invoke("ConnectServer");
Variant conRet_Win32_DiskDriver = wmi_Win32_DiskDriver.invoke("ConnectServer");
Variant conRet_Win32_OperatingSystem = wmi_Win32_OperatingSystem.invoke("ConnectServer");
//Step 4: Prepare object for query
ActiveXComponent wmiconnect_Computersystem = new ActiveXComponent(conRet_Computersystem.toDispatch());
ActiveXComponent wmiconnect_Win32_BIOS = new ActiveXComponent(conRet_Win32_BIOS.toDispatch());
ActiveXComponent wmiconnect_Win32_MotherboardDevice = new ActiveXComponent(conRet_Win32_MotherboardDevice.toDispatch());
ActiveXComponent wmiconnect_Win32_VideoController = new ActiveXComponent(conRet_Win32_VideoController.toDispatch());
ActiveXComponent wmiconnect_Win32_DiskDriver = new ActiveXComponent(conRet_Win32_DiskDriver.toDispatch());
ActiveXComponent wmiconnect_SYSTEM_TYPE = new ActiveXComponent(conRet_Win32_OperatingSystem.toDispatch());
//Step 5: Set query
String query_Computersystem = "select Name, Manufacturer, Domain, SystemFamily, SystemType, Workgroup " +
"from Win32_Computersystem";
String query_Win32_BIOS = "select SerialNumber, BIOSVersion " +
"from Win32_BIOS";
String query_Win32_MotherboardDevice = "select PNPDeviceID " +
"from Win32_MotherboardDevice";
String query_Win32_VideoController = "select Name, DriverVersion, VideoModeDescription " +
"from Win32_VideoController";
String query_Win32_DiskDrive = "select Size, InterfaceType " +
"from Win32_DiskDrive";
String query_Win32_OperatingSystem = "select Caption, SerialNumber " +
"from Win32_OperatingSystem";
//Step 6: Set object for enum
Variant vCollection_Computersystem = wmiconnect_Computersystem.invoke("ExecQuery", new Variant(query_Computersystem));
Variant vCollection_Win32_BIOS = wmiconnect_Computersystem.invoke("ExecQuery", new Variant(query_Win32_BIOS));
Variant vCollection_Win32_MotherboardDevice = wmiconnect_Computersystem.invoke("ExecQuery", new Variant(query_Win32_MotherboardDevice));
Variant vCollection_Win32_VideoController = wmiconnect_Computersystem.invoke("ExecQuery", new Variant(query_Win32_VideoController));
Variant vCollection_Win32_DiskDrive = wmiconnect_Computersystem.invoke("ExecQuery", new Variant(query_Win32_DiskDrive));
Variant vCollection_Win32_OperatingSystem = wmiconnect_Computersystem.invoke("ExecQuery", new Variant(query_Win32_OperatingSystem));
//Step 7: Set Enum and Dispatch object
EnumVariant enumVariant_Computersystem = new EnumVariant(vCollection_Computersystem.toDispatch());
EnumVariant enumVariant_Win32_BIOS = new EnumVariant(vCollection_Win32_BIOS.toDispatch());
EnumVariant enumVariant_Win32_MotherboardDevice = new EnumVariant(vCollection_Win32_MotherboardDevice.toDispatch());
EnumVariant enumVariant_Win32_VideoController = new EnumVariant(vCollection_Win32_VideoController.toDispatch());
EnumVariant enumVariant_Win32_DiskDrive = new EnumVariant(vCollection_Win32_DiskDrive.toDispatch());
EnumVariant enumVariant_Win32_OperatingSystem = new EnumVariant(vCollection_Win32_OperatingSystem.toDispatch());
Dispatch item_Computersystem, item_Win32_BIOS, item_Win32_MotherboardDevice, item_Win32_VideoController, item_Win32_DiskDrive,
item_Win32_OperatingSystem = null;
//Step 8: Set Conmtread for Try
ComThread.InitMTA();
//Step 9: Step Try anf Finally
try {
while (enumVariant_Computersystem.hasMoreElements()) {
//Step 10: Set Item
item_Computersystem = enumVariant_Computersystem.nextElement().toDispatch();
item_Win32_BIOS = enumVariant_Win32_BIOS.nextElement().toDispatch();
item_Win32_MotherboardDevice = enumVariant_Win32_MotherboardDevice.nextElement().toDispatch();
item_Win32_VideoController = enumVariant_Win32_VideoController.nextElement().toDispatch();
item_Win32_DiskDrive = enumVariant_Win32_DiskDrive.nextElement().toDispatch();
item_Win32_OperatingSystem = enumVariant_Win32_OperatingSystem.nextElement().toDispatch();
// call prop of Win32_ComputerSystem
COMNAME = Dispatch.call(item_Computersystem, "Name").toString();
NOTEBOOK_BRAND = Dispatch.call(item_Computersystem, "Manufacturer").toString();
DOMAIN = Dispatch.call(item_Computersystem, "Domain").toString();
SYSTEM_FAMILY = Dispatch.call(item_Computersystem, "SystemFamily").toString();
SYSTEM_TYPE = Dispatch.call(item_Computersystem, "SystemType").toString();
WORKGROUP = Dispatch.call(item_Computersystem, "Workgroup").toString();
// call prop of Win32_BIOS
SERIAL_NUMBER = Dispatch.call(item_Win32_BIOS, "SerialNumber").toString();
BIOS_VERSION = Dispatch.call(item_Win32_BIOS, "BIOSVersion").toString();
//call prop of Win32_MotherboardDevice
MOTHER_BOARD_PN = Dispatch.call(item_Win32_MotherboardDevice, "PNPDeviceID").toString();
//call prop of Win32_VideoController
GRAPHIC_CARD_NAME = Dispatch.call(item_Win32_VideoController, "Name").toString();
GRAPHIC_CARD_VER = Dispatch.call(item_Win32_VideoController, "DriverVersion").toString();
GRAPHIC_SOLUTION = Dispatch.call(item_Win32_VideoController, "VideoModeDescription").toString();
//call prop of Win32_DiskDrive
DISK_SIZE = Dispatch.call(item_Win32_DiskDrive, "Size").toString();
DISK_INTERFACE_TYPE = Dispatch.call(item_Win32_DiskDrive, "InterfaceType").toString();
//call prop of Win32_OperatingSystem
WIN_VERSION = Dispatch.call(item_Win32_OperatingSystem, "Caption").toString();
WIN_SERIAL_NUMBER = Dispatch.call(item_Win32_OperatingSystem, "SerialNumber").toString();
//output for Win32_Computersystem
System.out.println("Computer Name : " + COMNAME + "\n");
System.out.println("Notebook Brand : " + NOTEBOOK_BRAND + "\n");
System.out.println("Domain Name : " + DOMAIN + "\n");
System.out.println("System Family : " + SYSTEM_FAMILY + "\n");
System.out.println("System Type : " + SYSTEM_TYPE + "\n");
System.out.println("Workgroup Name : " + WORKGROUP + "\n");
//output for Win32_BIOS
System.out.println("Serial Number : " + SERIAL_NUMBER + "\n");
System.out.println("Bios Version : " + BIOS_VERSION + "\n");
//output for Win32_MotherboardDevice
System.out.println("MotherBoard Part Number : " + MOTHER_BOARD_PN + "\n");
//output for Win32_VideoController
System.out.println("Graphic Card Name : " + GRAPHIC_CARD_NAME + "\n");
System.out.println("Graphic Card Version : " + GRAPHIC_CARD_VER + "\n");
System.out.println("Graphic Version : " + GRAPHIC_SOLUTION + "\n");
//output for Win32_DiskDrive
System.out.println("Disk Size : " + DISK_SIZE + "\n");
System.out.println("Disk Interface Type : " + DISK_INTERFACE_TYPE + "\n");
//output for Win32_OperatingSystem
System.out.println("Windows Version : " + WIN_VERSION + "\n");
System.out.println("Windows Serial Number : " + WIN_SERIAL_NUMBER + "\n");
break;
}
} finally {
ComThread.Release();
}
}
}
关于Java JACOB WMI 查询本地组成员身份,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22337564/
我正在使用SQL Server 2008 R2,并且想创建一个触发器。 对于每个添加(仅添加),将像这样更新一列: ABC-CurrentYear-AutoIncrementCode 例子: ABC-
是否可以在显示最终一致性的数据存储中创建/存储用户帐户? 似乎不可能在没有一堆架构复杂性的情况下管理帐户创建,以避免可能发生具有相同 UID(例如电子邮件地址)的两个帐户的情况? 最终一致性存储的用户
您好, 我有一个带有 Identity 的 .NetCore MVC APP并使用 this指导我能够创建自定义用户验证器。 public class UserDomainValidator : IU
这与以下问题相同:HiLo or identity? 我们以本站的数据库为例。 假设该站点具有以下表格: 帖子。 投票。 注释。 使用它的最佳策略是什么: 身份 - 这是更常见的。 或者 HiLo -
我想将 Blazor Server 与 ASP.NET Identity 一起使用。但我需要使用 PostgreSQL 作为用户/角色存储,因为它在 AWS 中。 它不使用 EF,这是我需要的。 我创
我正在开发一个 .NET 应用程序,它可以使用 Graph API 代表用户发送电子邮件。 提示用户对应用程序进行授权;然后使用获取的访问 token 来调用 Graph API。刷新 token 用
我使用 ASP.NET 身份和 ClaimsIdentity 来验证我的用户。当用户通过身份验证时,属性 User.Identity 包含一个 ClaimsIdentity 实例。 但是,在登录请求期
所以我在两台机器上都安装了 CYGWIN。 如果我这样做,它会起作用: ssh -i desktop_rsa root@remoteserver 这需要我输入密码 ssh root@remoteser
我尝试在 mac osx 上的终端中通过 telnet 连接到 TOR 并请求新身份,但它不起作用,我总是收到此错误消息: Trying 127.0.0.1... telnet: connect to
我正在开发一个 .NET 应用程序,它可以使用 Graph API 代表用户发送电子邮件。 提示用户对应用程序进行授权;然后使用获取的访问 token 来调用 Graph API。刷新 token 用
我正在开发一项服务,客户可以在其中注册他们的 webhook URL,我将发送有关已注册 URL 的更新。为了安全起见,我想让客户端(接收方)识别是我(服务器)向他们发送请求。 Facebook和 G
在 Haskell 中,有没有办法测试两个 IORef 是否相同?我正在寻找这样的东西: IORef a -> IORef a -> IO Bool 例如,如果您想可视化由 IORef 组成的图形,这
我是 .NET、MVC 和身份框架的新手。我注意到身份框架允许通过注释保护单个 Controller 操作。 [Authorize] public ActionResult Edit(int? Id)
我有一列具有身份的列,其计数为19546542,我想在删除所有数据后将其重置。我需要类似ms sql中的'dbcc checkident'这样的内容,但在Oracle中 最佳答案 在Oracle 12
这是我用来创建 session 以发送电子邮件的代码: props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enabl
我想了解 [AllowAnonymous] 标签的工作原理。 我有以下方法 [HttpGet] public ActionResult Add() { return View(); } 当我没
在使用沙盒测试环境时,PayPal 身份 token 对某些人显示而不对其他人显示的原因是否有任何原因。 我在英国使用 API,终生无法生成或找到 token 。 我已经遵循协议(protocol)并
我对非常简单的事情有一些疑问:IDENTITY。我尝试在 phpMyAdmin 中创建表: CREATE TABLE IF NOT EXISTS typEventu ( typEventu
习语 #1 和 #5 是 FinnAPL Idiom Library两者具有相同的名称:“Progressive index of (without replacement)”: ((⍴X)⍴⍋⍋X⍳
当我第一次在 TFS 中设置时,我的公司拼错了我的用户名。此后他们将其更改为正确的拼写,但该更改显然未反射(reflect)在 TFS 中。当我尝试 checkin 更改时,出现此错误: 有没有一种方
我是一名优秀的程序员,十分优秀!