当前位置: 首页 > news >正文

湖北省建设厅网站上岗证查询怎么运营小程序

湖北省建设厅网站上岗证查询,怎么运营小程序,网站备案信息的核查方式,电商网站在 Windows 系统中,获取设备唯一性标识及定位信息对设备管理、安全监控等场景意义重大。本文介绍 Java 中几种实现方法,如 JNA 库、WMI4Java 库及通过 JNI 结合 Windows API。 1. 使用 JNA 库读取 DEVPKEY_Device_ContainerId 在 Windows 系统中&…

在 Windows 系统中,获取设备唯一性标识及定位信息对设备管理、安全监控等场景意义重大。本文介绍 Java 中几种实现方法,如 JNA 库、WMI4Java 库及通过 JNI 结合 Windows API。
在这里插入图片描述

1. 使用 JNA 库读取 DEVPKEY_Device_ContainerId

在 Windows 系统中,DEVPKEY_Device_ContainerId是获取设备容器唯一标识符的属性键。设备容器含多个相关设备,此标识符可区分不同设备集合。Java 无直接获取该属性的方法,可借助 JNA (Java Native Access)库访问 Windows 底层接口实现读取。

  1. 引入 JNA 库

若用 Maven 管理项目,在pom.xml添加如下依赖。

     <dependency><groupId>net.java.dev.jna</groupId><artifactId>jna</artifactId><version>5.13.0</version></dependency>
  1. 代码示例

以下是读取DEVPKEY_Device_ContainerId的示例代码。代码中的{设备容器路径}要换成实际在注册表中的路径(类似{数字和字母组合},可查看 Windows 注册表确定)。此代码用Advapi32Util类的registryGetStringValue方法从注册表读取指定键值对应的字符串值,访问HKEY_LOCAL_MACHINE下特定路径获取DEVPKEY_Device_ContainerId对应的设备容器唯一标识符。

     import com.sun.jna.platform.win32.Advapi32Util;import com.sun.jna.platform.win32.WinReg;public class WindowsDeviceIdReader {public static void main(String[] args) {String containerId = Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE,"SYSTEM\\CurrentControlSet\\Control\\DeviceContainers\\{设备容器路径}\\Properties","{DEVPKEY_Device_ContainerId}");System.out.println("设备容器ID: " + containerId);}}

2. 使用 WMI4Java 库通过 WMI 读取设备信息

Windows Management Instrumentation(WMI)是微软管理技术,可供管理员和开发者统一查询与管理 Windows 系统资源,包括硬件设备、软件组件等。WMI4Java 库为 Java 程序访问 WMI 提供便捷途径。

  1. 添加依赖

若用 Maven 管理项目,在pom.xml添加如下依赖。

     <dependency><groupId>org.boris.winrun4j</groupId><artifactId>wmi4java</artifactId><version>1.5.0</version></dependency>
  1. 代码示例

先创建“WMI”对象,获取“Win32_PhysicalMedia”类实例,该类含物理设备(如硬盘)信息,遍历可获设备序列号这一唯一性标识。不同设备类(如“Win32_NetworkAdapter”用于网络适配器)能提供不同设备标识信息。

     import org.boris.winrun4j.wmi.WMI;import org.boris.winrun4j.wmi.WMIException;import org.boris.winrun4j.wmi.WMIClass;import org.boris.winrun4j.wmi.WMIObject;public class WMIDeviceIdReader {public static void main(String[] args) {try {WMI wmi = new WMI();// 查询Win32_PhysicalMedia类获取设备信息WMIClass c = wmi.getWMIClass("Win32_PhysicalMedia");for (WMIObject o : c.instances()) {String serialNumber = o.get("SerialNumber").toString();System.out.println("设备序列号(唯一性标识之一): " + serialNumber);}} catch (WMIException e) {e.printStackTrace();}}}

3. 使用 Java 本地接口(JNI)结合 Windows API

JNI 允许 Java 代码与其他语言(如 C/C++)编写的代码交互。Windows 提供了一系列 API 用于获取设备信息,例如SetupDiGetDeviceInstanceId函数可获取设备实例 ID,这是设备的一种唯一性标识。

  1. 编写 C/C++代码

C++获取设备实例 ID 示例。代码先通过SetupDiGetClassDevs获取设备信息集,再用SetupDiEnumDeviceInfoSetupDiGetDeviceInstanceId获取首个设备实例 ID 存于传入缓冲区。

     #include <windows.h>#include <setupapi.h>#include <stdio.h>extern "C" {__declspec(dllexport) void getDeviceInstanceId(char* buffer, DWORD bufferSize) {HDEVINFO deviceInfoSet = SetupDiGetClassDevs(NULL, NULL, NULL, DIGCF_PRESENT);if (deviceInfoSet == INVALID_HANDLE_VALUE) {return;}SP_DEVINFO_DATA deviceInfoData;deviceInfoData.cbSize = sizeof(SP_DEVINFO_DATA);if (SetupDiEnumDeviceInfo(deviceInfoSet, 0, &deviceInfoData)) {DWORD requiredSize;SetupDiGetDeviceInstanceId(deviceInfoSet, &deviceInfoData, buffer, bufferSize, &requiredSize);}SetupDiDestroyDeviceInfoList(deviceInfoSet);}}
  1. 编译为动态链接库(DLL)

使用 Visual C++编译器时,可在命令行执行cl /LD getDeviceInstanceId.cpp(代码存于该文件)进行编译,编译步骤因编译器而异。

  1. 在 Java 中调用 DLL

Java 示例代码:用System.loadLibrary加载编译好的 DLL,定义本地方法getDeviceInstanceId,在main方法中调用该方法获取设备实例 ID,注意替换yourDLLName为实际 DLL 名称。

     class DeviceIdJNI {static {System.loadLibrary("yourDLLName"); // 替换为实际的DLL名称}public native void getDeviceInstanceId(byte[] buffer, int bufferSize);public static void main(String[] args) {DeviceIdJNI deviceIdJNI = new DeviceIdJNI();byte[] buffer = new byte[1024];deviceIdJNI.getDeviceInstanceId(buffer, buffer.length);String deviceInstanceId = new String(buffer).trim();System.out.println("设备实例ID: " + deviceInstanceId);}}

4. 总结

  • JNA 库便捷但受限特定属性读取。
  • WMI4Java 库简单但受 WMI 限制且性能可能不足。
  • JNI 结合 Windows API 能灵活获取底层设备信息,但编写维护复杂且要求开发者了解 Windows API 和 C/C++编程。

What is Java technology and why do I need it?
Java is a programming language and computing platform first released by Sun Microsystems in 1995. It has evolved from humble beginnings to power a large share of today’s digital world, by providing the reliable platform upon which many services and applications are built. New, innovative products and digital services designed for the future continue to rely on Java, as well.

While most modern Java applications combine the Java runtime and application together, there are still many applications and even some websites that will not function unless you have a desktop Java installed. Java.com, this website, is intended for consumers who may still require Java for their desktop applications – specifically applications targeting Java 8. Developers as well as users that would like to learn Java programming should visit the dev.java website instead and business users should visit oracle.com/java for more information.

Is Java free to download?
Yes, Java is free to download for personal use.
Java is also free for development: developers can find all the development kits and other useful tools at https://www.oracle.com/javadownload/.

Why should I upgrade to the latest Java patch each quarter when prompted?
The latest Java patches contain important enhancements to improve performance, stability and security of the Java applications that run on your machine. Installing these updates will ensure that your Java applications continue to run with the most up-to-date version.

http://www.yayakq.cn/news/128922/

相关文章:

  • 猪八戒做网站排名做网站数据库怎么做
  • 织梦网站后台管理系统免费空间说说点赞
  • asp 网站信箱模板免费网站建设加盟
  • wordpress上传主题超时网站免费seo
  • 网站自适应屏幕亚马逊推广
  • 做京挑客的网站有哪些网站备案拍照背景幕布
  • 甘肃省建设厅执业注册中心网站自建网站阿里云备案通过后怎么做
  • wordpress 视频网站健康码哪家公司开发的
  • 中山建设公司网站株洲能建网站的有哪些
  • 寺庙建设网站的意义商城免费建站系统
  • 做app推广上哪些网站网页制作心得2000字
  • 郑州东区做网站电话平板室内装修设计软件
  • 机电工程东莞网站建设技术支持做电路方案设计的网站
  • 小榄做网站龙岩网站设计理念
  • 做一个购物网站广州网站搭建哪家好
  • 网站建设方案网站安全网站建设企业宣传
  • 网站规划与建设心得网站架设标准
  • 自助网站建设工具手机网站开发 .net
  • 成都双流兴城建设投资有限公司网站wordpress 执行流程
  • 口碑好网站建设公司wordpress博客做seo
  • 北京网站制作公司飞沐徐州英才网最新招聘信息
  • 国内网站速度慢cpu占用超出网站空间的分配值
  • 专业系统网站好查看网站被百度收录
  • 网站的规划建设如何布局o2o网站建设公司
  • 免费网站空间怎么做室内装修培训
  • 深圳福田网站建设做的王者荣耀钓鱼网站
  • dede网站怎么做单页面如何看一个网站的备案在哪里做的
  • 无锡网站建设推荐智勇仿站酷网站模板
  • 网站开发人员职位描述哪个专业学习网站建设
  • 分类目录网站程序网络广告创意