WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WMI
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Get Win32_DiskDrive Data with DeviceID


Question:

I encountered an issue using the WMI Scripter when querying Win32_DiskDrive. It appears to execute correct when the query is written as query = "SELECT * FROM Win32_DiskDrive". However when changed to query = "SELECT * FROM Win32_DiskDrive WHERE DeviceID = '\\.\PHYSICALDRIVE0'", it no longer yields any results. Any suggestions to what the problem might be?

Answer:

I think you need to escape those backslashes. This seems to work for me:
sComputerName  = "."
sWmiMoniker = StrCat("winmgmts:{impersonationLevel=Impersonate}!//", sComputerName)
objServices = GetObject(sWmiMoniker)
; Get physical disk drive.
objDiskDrives =  objServices.ExecQuery ('SELECT * FROM Win32_DiskDrive WHERE DeviceID="\\\\.\\PHYSICALDRIVE0"')
ForEach objDiskDrive In objDiskDrives
   caption = objDiskDrive.Caption
   serialnum =  objDiskDrive.SerialNumber
   deviceid = objDiskDrive.DeviceID
   sDriveInfo = StrCat( "Disk drive Caption: ", caption , @CRLF)
   sDriveInfo = StrCat(sDriveInfo, "SerialNumber: ", serialnum, @CRLF)
   sDriveInfo = StrCat(sDriveInfo, "DeviceID: ", " (", deviceid, ")")
   Message("Disk Drive Info", sDriveInfo)
Next
objDiskDrives = 0
objServices = 0
Exit

Article ID:   W17318
File Created: 2013:05:28:10:28:56
Last Updated: 2013:05:28:10:28:56