`
lishumingwm163.com
  • 浏览: 337742 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

请您先登录,才能继续操作

java调用windows的wmi

    博客分类:
  • java
 
阅读更多

100%纯java调用windows的wmi获取监控数据

纯java主要体现在可以跨平台调用com。所用的是j-Interop,它是100%纯java实现的com的调用

 

1、环境准备

a、windows要开启Remote Registry与Windows Management Instrumentation服务

b、修改安全策略

我系统是英文的,如果是中文系统,翻译为中文,相对应的查找并修改。

Administrative Tools>Local Security Policy>Local Policy>Security Policy>Network access: Sharing and security model for local accounts

修改为Classic(经典)

c、禁用放火墙

d、window2008系统注册表越狱(高版本的win)

需要修改regedit中HKEY_CLASSES_ROOT\CLSID\{76A64158-CB41-11D1-8B02-00600806D9B6}的权限,windows2008不再给Administrators完全控制权。

下载SetACL.exe,下载地址:http://files.helgeklein.com/downloads/SetACL/current/SetACL%20(executable%20version).zip

set_wmi_reg_acl.cmd

 

1 SetACL.exe -on "HKEY_CLASSES_ROOT\CLSID\{76A64158-CB41-11D1-8B02-00600806D9B6}" -ot reg -actn setowner -ownr "n:Administrators"
2 SetACL.exe -on "HKEY_CLASSES_ROOT\CLSID\{76A64158-CB41-11D1-8B02-00600806D9B6}" -ot reg -actn ace -ace "n:Administrators;p:full"

 

 

以超级管理员身份执行这个cms,就会把owner与完全控制权限授予Administrators组

 

2、程序代码

java类
001 package org.noah.wmitest;
002  
003 import org.jinterop.dcom.common.JIException;
004 import org.jinterop.dcom.common.JISystem;
005 import org.jinterop.dcom.core.*;
006 import org.jinterop.dcom.impls.JIObjectFactory;
007 import org.jinterop.dcom.impls.automation.IJIDispatch;
008 import org.jinterop.dcom.impls.automation.IJIEnumVariant;
009 import org.slf4j.Logger;
010 import org.slf4j.LoggerFactory;
011  
012 import java.net.UnknownHostException;
013 import java.util.logging.Level;
014  
015 /**
016  * Created with IntelliJ IDEA.
017  * User: noah
018  * Date: 8/16/12
019  * Time: 8:00 AM
020  * To change this template use File | Settings | File Templates.
021  */
022 public class WmiService {
023  
024     private JIComServer m_ComStub = null;
025     private IJIComObject m_ComObject = null;
026     private IJIDispatch m_Dispatch = null;
027     private String m_Address = null;
028     private JISession m_Session = null;
029     private IJIDispatch m_WbemServices = null;
030  
031     private static final String WMI_CLSID = "76A6415B-CB41-11d1-8B02-00600806D9B6";
032     private static final String WMI_PROGID = "WbemScripting.SWbemLocator";
033  
034     private Logger logger = LoggerFactory.getLogger(this.getClass());
035  
036  
037     public WmiService(String address) {
038         JISystem.setAutoRegisteration(true);
039         JISystem.getLogger().setLevel(Level.WARNING);
040         m_Address = address;
041     }
042  
043     public void query(String strQuery) {
044  
045         System.out.println("query:" + strQuery);
046  
047         JIVariant results[] = new JIVariant[0];
048         try {
049             results = m_WbemServices.callMethodA("ExecQuery"new Object[]{new JIString(strQuery), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM(), JIVariant.OPTIONAL_PARAM()});
050             IJIDispatch wOSd = (IJIDispatch) JIObjectFactory.narrowObject((results[0]).getObjectAsComObject());
051  
052             int count = wOSd.get("Count").getObjectAsInt();
053  
054             IJIComObject enumComObject = wOSd.get("_NewEnum").getObjectAsComObject();
055             IJIEnumVariant enumVariant = (IJIEnumVariant) JIObjectFactory.narrowObject(enumComObject.queryInterface(IJIEnumVariant.IID));
056  
057             IJIDispatch wbemObject_dispatch = null;
058  
059             for (int c = 0; c < count; c++) {
060  
061                 Object[] values = enumVariant.next(1);
062                 JIArray array = (JIArray) values[0];
063                 Object[] arrayObj = (Object[]) array.getArrayInstance();
064                 for (int j = 0; j < arrayObj.length; j++) {
065                     wbemObject_dispatch = (IJIDispatch) JIObjectFactory.narrowObject(((JIVariant) arrayObj[j]).getObjectAsComObject());
066                 }
067  
068                 String str = (wbemObject_dispatch.callMethodA("GetObjectText_"new Object[]{1}))[0].getObjectAsString2();
069                 System.out.println("(" + c + "):");
070                 System.out.println(str);
071                 System.out.println();
072             }
073  
074  
075         catch (JIException e) {
076             e.printStackTrace();
077         }
078     }
079  
080     public void connect(final String domain, final String username, final String password) {
081         try {
082  
083             m_Session = JISession.createSession(domain, username, password);
084             m_Session.useSessionSecurity(true);
085             m_Session.setGlobalSocketTimeout(5000);
086  
087             m_ComStub = new JIComServer(JIProgId.valueOf(WMI_PROGID), m_Address, m_Session);
088  
089             IJIComObject unknown = m_ComStub.createInstance();
090             m_ComObject = unknown.queryInterface(WMI_CLSID);
091  
092             m_Dispatch = (IJIDispatch) JIObjectFactory.narrowObject(m_ComObject.queryInterface(IJIDispatch.IID));
093             JIVariant results[] = m_Dispatch.callMethodA(
094                     "ConnectServer",
095                     new Object[]{
096                             new JIString(m_Address),
097                             JIVariant.OPTIONAL_PARAM(),
098                             JIVariant.OPTIONAL_PARAM(),
099                             JIVariant.OPTIONAL_PARAM(),
100                             JIVariant.OPTIONAL_PARAM(),
101                             JIVariant.OPTIONAL_PARAM(),
102                             0,
103                             JIVariant.OPTIONAL_PARAM()
104                     }
105             );
106  
107             m_WbemServices = (IJIDispatch) JIObjectFactory.narrowObject((results[0]).getObjectAsComObject());
108  
109         catch (JIException e) {
110             e.printStackTrace();
111             if (m_Session != null) {
112                 try {
113                     JISession.destroySession(m_Session);
114                 catch (JIException e1) {
115                     logger.error(e.getMessage(), e);
116                 }
117             }
118         catch (UnknownHostException e) {
119             if (m_Session != null) {
120                 try {
121                     JISession.destroySession(m_Session);
122                 catch (JIException e1) {
123                     logger.error(e.getMessage(), e);
124                 }
125             }
126         }
127     }
128  
129     public void disconnect() {
130         try {
131             JISession.destroySession(m_Session);
132         catch (JIException e) {
133             logger.error(e.getMessage(), e);
134         }
135     }
136  
137  
138     public static void main(String[] args) {
139  
140         WmiService wmiService = new WmiService("172.16.158.129");
141  
142         //域(一般为空字符),用户名,密码
143         wmiService.connect("""username""password");
144  
145         //系统信息
146         wmiService.query("SELECT * FROM Win32_ComputerSystem");
147  
148         //CPU信息
149         wmiService.query("SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name != '_Total'");
150  
151         //内存信息
152         wmiService.query("SELECT * FROM Win32_PerfFormattedData_PerfOS_Memory");
153  
154         //磁盘信息
155         wmiService.query("SELECT * FROM Win32_PerfRawData_PerfDisk_PhysicalDisk Where Name != '_Total'");
156  
157         wmiService.disconnect();
158     }
159 }

 

mavne配置(pom.xml)
01 <?xml version="1.0" encoding="UTF-8"?>
02 <project xmlns="http://maven.apache.org/POM/4.0.0"
03          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
04          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
05     <modelVersion>4.0.0</modelVersion>
06  
07     <groupId>org.noahx</groupId>
08     <artifactId>wmi-test</artifactId>
09     <version>1.0</version>
10  
11  
12     <dependencies>
13  
14         <dependency>
15             <groupId>org.kohsuke.jinterop</groupId>
16             <artifactId>j-interop</artifactId>
17             <version>2.0.8-kohsuke-1</version>
18         </dependency>
19  
20         <dependency>
21             <groupId>org.slf4j</groupId>
22             <artifactId>slf4j-log4j12</artifactId>
23             <version>1.6.4</version>
24         </dependency>
25  
26     </dependencies>
27      
28 </project>

 

运行结果
001 query:SELECT * FROM Win32_ComputerSystem
002 (0):
003  
004 instance of Win32_ComputerSystem
005 {
006     AdminPasswordStatus = 1;
007     AutomaticResetBootOption = FALSE;
008     AutomaticResetCapability = TRUE;
009     BootOptionOnLimit = 3;
010     BootOptionOnWatchDog = 3;
011     BootROMSupported = TRUE;
012     BootupState = "Normal boot";
013     Caption = "NAK-E1A7C21EA3C";
014     ChassisBootupState = 3;
015     CreationClassName = "Win32_ComputerSystem";
016     CurrentTimeZone = 480;
017     Description = "AT/AT COMPATIBLE";
018     Domain = "WORKGROUP";
019     DomainRole = 0;
020     EnableDaylightSavingsTime = TRUE;
021     FrontPanelResetStatus = 3;
022     InfraredSupported = FALSE;
023     KeyboardPasswordStatus = 3;
024     Manufacturer = "VMware, Inc.";
025     Model = "VMware Virtual Platform";
026     Name = "NAK-E1A7C21EA3C";
027     NetworkServerModeEnabled = TRUE;
028     NumberOfLogicalProcessors = 2;
029     NumberOfProcessors = 1;
030     OEMStringArray = {"[MS_VM_CERT/SHA1/27d66596a61c48dd3dc7216fd715126e33f59ae7]""Welcome to the Virtual Machine"};
031     PartOfDomain = FALSE;
032     PauseAfterReset = "3932100000";
033     PowerOnPasswordStatus = 0;
034     PowerState = 0;
035     PowerSupplyState = 3;
036     PrimaryOwnerName = "nak";
037     ResetCapability = 1;
038     ResetCount = -1;
039     ResetLimit = -1;
040     Roles = {"LM_Workstation""LM_Server""NT""Potential_Browser""Master_Browser"};
041     Status = "OK";
042     SystemStartupDelay = 0;
043     SystemStartupOptions = {"\"Microsoft Windows XP Professional\" /noexecute=optin /fastdetect"};
044     SystemStartupSetting = 0;
045     SystemType = "X86-based PC";
046     ThermalState = 3;
047     TotalPhysicalMemory = "1610063872";
048     UserName = "NAK-E1A7C21EA3C\\a";
049     WakeUpType = 6;
050 };
051  
052  
053 query:SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor WHERE Name != '_Total'
054 (0):
055  
056 instance of Win32_PerfFormattedData_PerfOS_Processor
057 {
058     C1TransitionsPersec = "77";
059     C2TransitionsPersec = "0";
060     C3TransitionsPersec = "0";
061     DPCRate = 0;
062     DPCsQueuedPersec = 4;
063     InterruptsPersec = 71;
064     Name = "0";
065     PercentC1Time = "96";
066     PercentC2Time = "0";
067     PercentC3Time = "0";
068     PercentDPCTime = "0";
069     PercentIdleTime = "100";
070     PercentInterruptTime = "0";
071     PercentPrivilegedTime = "0";
072     PercentProcessorTime = "0";
073     PercentUserTime = "0";
074 };
075  
076  
077 (1):
078  
079 instance of Win32_PerfFormattedData_PerfOS_Processor
080 {
081     C1TransitionsPersec = "83";
082     C2TransitionsPersec = "0";
083     C3TransitionsPersec = "0";
084     DPCRate = 0;
085     DPCsQueuedPersec = 10;
086     InterruptsPersec = 67;
087     Name = "1";
088     PercentC1Time = "96";
089     PercentC2Time = "0";
090     PercentC3Time = "0";
091     PercentDPCTime = "0";
092     PercentIdleTime = "100";
093     PercentInterruptTime = "0";
094     PercentPrivilegedTime = "0";
095     PercentProcessorTime = "0";
096     PercentUserTime = "0";
097 };
098  
099  
100 query:SELECT * FROM Win32_PerfFormattedData_PerfOS_Memory
101 (0):
102  
103 instance of Win32_PerfFormattedData_PerfOS_Memory
104 {
105     AvailableBytes = "1142099968";
106     AvailableKBytes = "1115332";
107     AvailableMBytes = "1089";
108     CacheBytes = "70725632";
109     CacheBytesPeak = "72904704";
110     CacheFaultsPersec = 634;
111     CommitLimit = "3063078912";
112     CommittedBytes = "326488064";
113     DemandZeroFaultsPersec = 13965;
114     FreeSystemPageTableEntries = 159743;
115     PageFaultsPersec = 13965;
116     PageReadsPersec = 0;
117     PagesInputPersec = 0;
118     PagesOutputPersec = 0;
119     PagesPersec = 0;
120     PageWritesPersec = 0;
121     PercentCommittedBytesInUse = 10;
122     PoolNonpagedAllocs = 38040;
123     PoolNonpagedBytes = "7585792";
124     PoolPagedAllocs = 57820;
125     PoolPagedBytes = "29380608";
126     PoolPagedResidentBytes = "28622848";
127     SystemCacheResidentBytes = "40235008";
128     SystemCodeResidentBytes = "1867776";
129     SystemCodeTotalBytes = "1167360";
130     SystemDriverResidentBytes = "0";
131     SystemDriverTotalBytes = "4071424";
132     TransitionFaultsPersec = 0;
133     WriteCopiesPersec = 0;
134 };
135  
136  
137 query:SELECT * FROM Win32_PerfRawData_PerfDisk_PhysicalDisk Where Name != '_Total'
138 (0):
139  
140 instance of Win32_PerfRawData_PerfDisk_PhysicalDisk
141 {
142     AvgDiskBytesPerRead = "138920448";
143     AvgDiskBytesPerRead_Base = 8000;
144     AvgDiskBytesPerTransfer = "208285696";
145     AvgDiskBytesPerTransfer_Base = 13701;
146     AvgDiskBytesPerWrite = "69365248";
147     AvgDiskBytesPerWrite_Base = 5701;
148     AvgDiskQueueLength = "581460650";
149     AvgDiskReadQueueLength = "405581626";
150     AvgDisksecPerRead = 2794786622;
151     AvgDisksecPerRead_Base = 8000;
152     AvgDisksecPerTransfer = 322083534;
153     AvgDisksecPerTransfer_Base = 13701;
154     AvgDisksecPerWrite = 1822264208;
155     AvgDisksecPerWrite_Base = 5701;
156     AvgDiskWriteQueueLength = "175879024";
157     CurrentDiskQueueLength = 0;
158     DiskBytesPersec = "208285696";
159     DiskReadBytesPersec = "138920448";
160     DiskReadsPersec = 8000;
161     DiskTransfersPersec = 13701;
162     DiskWriteBytesPersec = "69365248";
163     DiskWritesPersec = 5701;
164     Frequency_Object = "0";
165     Frequency_PerfTime = "3034010000";
166     Frequency_Sys100NS = "10000000";
167     Name = "0 C:";
168     PercentDiskReadTime = "405581626";
169     PercentDiskReadTime_Base = "129895856572522792";
170     PercentDiskTime = "581460650";
171     PercentDiskTime_Base = "129895856572522792";
172     PercentDiskWriteTime = "175879024";
173     PercentDiskWriteTime_Base = "129895856572522792";
174     PercentIdleTime = "18446744072967667781";
175     PercentIdleTime_Base = "129895856572522792";
176     SplitIOPerSec = 1074;
177     Timestamp_Object = "0";
178     Timestamp_PerfTime = "3635534093651";
179     Timestamp_Sys100NS = "129895856572522792";
180 };<span style="font-family:'sans serif, tahoma, verdana, helvetica';font-size:x-small;"><span style="line-height:18.18181800842285px;white-space:normal;"> </span></span>

 

 

3、有可能出现的问题

报错a
01 org.jinterop.dcom.common.JIException: Message not found for errorCode: 0xC0000034
02     at org.jinterop.winreg.smb.JIWinRegStub.winreg_OpenHKLM(JIWinRegStub.java:115)
03     at org.jinterop.dcom.core.JIProgId.getIdFromWinReg(JIProgId.java:130)
04     at org.jinterop.dcom.core.JIProgId.getCorrespondingCLSID(JIProgId.java:162)
05     at org.jinterop.dcom.core.JIComServer.<init>(JIComServer.java:413)
06     at org.noah.wmitest.WmiService.connect(WmiService.java:122)
07     at org.noah.wmitest.WmiService.main(WmiService.java:177)
08     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
09     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
10     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
11     at java.lang.reflect.Method.invoke(Method.java:597)
12     at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
13 Caused by: jcifs.smb.SmbException: The system cannot find the file specified.
14     at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:522)
15     at jcifs.smb.SmbTransport.send(SmbTransport.java:622)
16     at jcifs.smb.SmbSession.send(SmbSession.java:239)
17     at jcifs.smb.SmbTree.send(SmbTree.java:109)
18     at jcifs.smb.SmbFile.send(SmbFile.java:718)
19     at jcifs.smb.SmbFile.open0(SmbFile.java:923)
20     at jcifs.smb.SmbFile.open(SmbFile.java:940)
21     at jcifs.smb.SmbFileOutputStream.<init>(SmbFileOutputStream.java:142)
22     at jcifs.smb.TransactNamedPipeOutputStream.<init>(TransactNamedPipeOutputStream.java:32)
23     at jcifs.smb.SmbNamedPipe.getNamedPipeOutputStream(SmbNamedPipe.java:187)
24     at rpc.ncacn_np.RpcTransport.attach(RpcTransport.java:92)
25     at rpc.Stub.attach(Stub.java:105)
26     at rpc.Stub.call(Stub.java:110)
27     at org.jinterop.winreg.smb.JIWinRegStub.winreg_OpenHKLM(JIWinRegStub.java:113)
28     ... 10 more

 

需要开启Remote Registry服务
 
报错b
01 org.jinterop.dcom.common.JIException: Message not found for errorCode: 0xC0000001
02     at org.jinterop.winreg.smb.JIWinRegStub.winreg_OpenHKLM(JIWinRegStub.java:115)
03     at org.jinterop.dcom.core.JIProgId.getIdFromWinReg(JIProgId.java:130)
04     at org.jinterop.dcom.core.JIProgId.getCorrespondingCLSID(JIProgId.java:162)
05     at org.jinterop.dcom.core.JIComServer.<init>(JIComServer.java:413)
06     at org.noah.wmitest.WmiService.connect(WmiService.java:87)
07     at org.noah.wmitest.WmiService.main(WmiService.java:142)
08     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
09     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
10     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
11     at java.lang.reflect.Method.invoke(Method.java:597)
12     at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
13 Caused by: jcifs.smb.SmbException: Connection timeout
14 jcifs.util.transport.TransportException: Connection timeout
15  
16
17  
18 org.jinterop.dcom.common.JIException: Message not found for errorCode: 0x8001FFFF
19     at org.jinterop.dcom.core.JIComServer.init(JIComServer.java:576)
20     at org.jinterop.dcom.core.JIComServer.initialise(JIComServer.java:481)
21     at org.jinterop.dcom.core.JIComServer.<init>(JIComServer.java:414)
22     at org.noah.wmitest.WmiService.connect(WmiService.java:87)
23     at org.noah.wmitest.WmiService.main(WmiService.java:142)
24     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
25     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
26     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
27     at java.lang.reflect.Method.invoke(Method.java:597)
28     at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
29 Caused by: java.net.ConnectException: Connection timed out

 

需要禁用放火墙
 

4、总结

j-Interop纯java跨平台,我就是linux系统。
用j-Interop就可以很方便的调用windows系统com,虽然这里只演示了WMI。
如果关心WMI与监控的话,建议去opennms-wmi看一看,他们有更好api封装(底层也是j-Interop)。
分享到:
评论

相关推荐

    wmi纯java调用所需jar包.zip

    这个压缩包"**wmi纯java调用所需jar包.zip**"很可能包含了j-Interop库的JAR文件,使得开发者能够用纯Java代码来访问和操作WMI对象。 使用j-Interop进行WMI调用的主要步骤如下: 1. **导入j-Interop库**:将压缩包...

    使用j-Interop实现java连接wmi获取windows系统信息的例子

    而Java开发者有时需要在Java程序中获取Windows系统的详细信息,这时就可以借助于j-Interop库来实现与WMI的交互。本文将深入探讨如何使用j-Interop来连接WMI并获取Windows系统信息。 首先,j-Interop是一个开源项目...

    wmi.zip_java wmi_wmi

    本文将深入探讨如何使用Java与WMI进行交互,以及如何通过WMI.js这个工具来读取设备信息。 首先,我们需要了解Java中的WMI接口。Java中没有内置对WMI的直接支持,但可以通过JMI(Java Management Extensions)或第三...

    使用java调用windows WIN脚本

    这篇博客文章"使用Java调用Windows WIN脚本"探讨了如何利用Java的接口来与Windows环境进行交互,实现这种跨平台语言与操作系统功能的融合。 首先,Java中可以通过`Runtime`或`ProcessBuilder`类来执行外部命令,...

    java开发的一个windows的远程监控软件

    标题中的“java开发的一个windows的远程监控软件”表明这是一个使用Java编程语言开发的应用程序,其主要功能是针对Windows操作系统进行远程监控。Java是一种跨平台的编程语言,这意味着编写好的Java程序可以在任何...

    使用wmi条件查询系统服务

    在Windows操作系统中,WMI(Windows Management Instrumentation)是一个核心组件,它提供了对系统硬件、软件和服务等资源的管理接口。通过WMI,开发者可以获取系统信息、监控系统状态、执行配置更改等操作。本篇将...

    wmi4j 远程执行cmd命令获取命令执行的结果

    使用wmi4j 连接远程主机获取进程列表,创建文件夹、共享文件夹、执行netstat -ano输出到aa.txt文件,读取文件、撤销文件夹共享、删除文件夹及aa.txt文件;即实现远程执行cmd命令获取命令执行的结果的效果。

    java获取硬盘序列号的两种方法

    ### 方法一:使用`Win32_DiskDrive` WMI(Windows Management Instrumentation)查询 在Windows操作系统中,可以利用WMI接口来获取硬件信息,包括硬盘序列号。以下是如何使用Java通过WMI获取硬盘序列号的步骤: 1....

    WMI获取远程服务器CPU,内存使用率函数源代码

    在IT领域,Windows Management Instrumentation(WMI)是一种强大的系统管理工具,允许开发者通过脚本或编程语言查询和控制Windows操作系统中的各种管理信息。本文将深入探讨如何利用C#编程语言,通过WMI来获取远程...

    基于Java的Windows服务器负载采集系统的设计和实现.pdf

    本文档基于Java的Windows服务器负载采集系统的设计和实现,通过使用Java编程语言和Windows Management Instrumentation(WMI)技术,实现了对Windows服务器的负载采集和监控。 知识点1:Java和WMI技术 * Java是一...

    java读取服务器硬件信息(windowx+linux+Mac OS)

    在Windows环境下,Java可以通过Java Native Interface (JNI) 来调用本地API,如Kernel32.dll中的函数,获取硬件信息,例如CPU型号、内存大小等。例如,可以使用WMI(Windows Management Instrumentation)接口来查询...

    用JAVA读取硬盘序列号

    Java程序通常会通过JNI调用本地方法,比如Windows的` ManagementObjectSearcher`类,查询WMI(Windows Management Instrumentation)来获取硬盘信息。对于跨平台的应用,可能需要针对不同操作系统编写特定的本地代码...

    Java获取CPU&主板&硬盘序列号

    对于Windows,可以使用WMI,而对于Linux系统,可能需要读取`/dev/sda`等设备文件或者使用`smartctl`命令行工具。例如,使用JNI在Windows上获取硬盘序列号: ```java import com.sun.jna.platform.win32.Wmi; ...

    java_use_dll.rar_JAVA 调用DLL_java_use_dll.rar_系统日志

    在Windows系统中,可以使用WMI(Windows Management Instrumentation)来查询系统事件日志。在Java中,可以使用Jacob或者其他提供WMI访问的库,比如Jinterop。以下是一个基本的WMI查询示例: ```java import ...

    java获得CPU使用率.doc

    - 对于Windows系统,可以通过读取系统性能计数器或使用`WMI (Windows Management Instrumentation)`来获取CPU使用率。 5. **计算内存使用率**: - 内存使用率通常是通过计算已使用的内存占总内存的比例来得出。 ...

    基于WMI的客户端信息采集工具

    【基于WMI的客户端信息采集工具】是一种利用Windows Management Instrumentation(WMI)技术来获取客户端计算机硬件信息的实用程序。WMI是微软提供的一种管理框架,它允许开发者通过标准的接口来访问和操作Windows...

    Java获取CPU主板硬盘序列号.doc

    该方法通过使用 Java 的 Runtime 类和 Process 类来执行 Windows 脚本(VBScript),从而获取 CPU 主板和硬盘的序列号。 一、获取主板序列号 在获取主板序列号时,需要使用 Windows 的 WMI 服务(Windows ...

    java监控开发示例

    总结来说,“java监控开发示例”涵盖了如何使用Java语言来实现跨平台的系统监控,包括Windows和Linux。这涉及到JVM管理、MXBean、JMX、远程调用、操作系统API的使用、数据收集与存储,以及安全性策略等多个方面。...

    Get the hard disk serial number or Motherboard serial number in java

    以下是利用Java调用VBScript获取主板序列号的步骤: 1. 创建一个临时的VBScript文件,编写VBScript代码来执行WMI查询。这段VBScript代码如下: ```vbscript Set objWMIService = GetObject("winmgmts:\\\\.\\root\\...

Global site tag (gtag.js) - Google Analytics