title: Find Product Id and Vendor Id of USB_FlashDrive using Java
body: <p>I need help to find the product and vendor ID of USB_Flash-drive, I used the following code but it won't work, </p>
  
  <pre><code>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();
      }
  </code></pre>
  
  <p>In this above code i use this line <code>(\"Select * from Win32_USBHub\") \n"</code> instead of <code>(\"Select * from Win32_USBHub WHERE\"\\\\.\\PHYSICALDRIVE0\"\") \n"</code>, which give the Product and Vendor id of my Dvd_Drive. Here what should i do for the correct result.</p>