[英]Find Product Id and Vendor Id of USB_FlashDrive using Java
I need help to find the product and vendor ID of USB_Flash-drive, I used the following code but it won't work, 我需要帮助来找到USB_Flash驱动器的产品和供应商ID,我使用了以下代码,但无法使用,
public static String getProductId() {
// TODO Auto-generated method stub
String result = "";
try {
File file = File.createTempFile("realhowto", ".vbs");
file.deleteOnExit();
FileWriter fw = new java.io.FileWriter(file);
String vbs = "Set objWMIService = GetObject(\"winmgmts:\\\\.\\root\\cimv2\")\n"
+ "Set colItems = objWMIService.ExecQuery _ \n"
+ " (\"Select * from Win32_USBHub WHERE\"\\\\.\\PHYSICALDRIVE0\"\") \n"
+ "For Each objItem in colItems \n"
+ " Wscript.Echo objItem.PNPDeviceID \n"
+ " exit for ' do the first cpu only! \n" + "Next \n";
fw.write(vbs);
fw.close();
Process p = Runtime.getRuntime().exec(
"cscript //NoLogo " + file.getPath());
BufferedReader input = new BufferedReader(new InputStreamReader(
p.getInputStream()));
String line;
while ((line = input.readLine()) != null) {
result += line;
}
input.close();
} catch (Exception e) {
e.printStackTrace();
}
return result.trim();
}
In this above code i use this line (\\"Select * from Win32_USBHub\\") \\n"
instead of (\\"Select * from Win32_USBHub WHERE\\"\\\\\\\\.\\\\PHYSICALDRIVE0\\"\\") \\n"
, which give the Product and Vendor id of my Dvd_Drive. 在上面的代码中,我使用以下行(\\"Select * from Win32_USBHub\\") \\n"
代替(\\"Select * from Win32_USBHub WHERE\\"\\\\\\\\.\\\\PHYSICALDRIVE0\\"\\") \\n"
,给出我的Dvd_Drive的产品和供应商ID。 Here what should i do for the correct result. 在这里我应该怎么做才能得到正确的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.