WMI (Windows Management Instrumentation) - Home
Introduction to WMIWho will benefit from learning about WMI (Windows Management Instrumentation) commands? Here are the people who I had in mind as I wrote this section. Network managers who want to collect specific data from one (or more) server. IT professionals who what to know precisely what's happening in their Microsoft operating system. Those techies who love remote control without hassle. . . . . . . . . . . . . . . . . . . . . . . . . . .
------------------------------------------------
WMI Scripting can be used to retrieve many useful information related to running machine in a very easy way.
Tutorial Learning Points
1) Sometimes simple phrases have a beauty all of their own. Yet, often simple phrases hide all the hard work, what you do not see is all the experiments that did not work and all the extra code that you don't need. Perhaps the best way to re-enforce this theme is to point what NOT to put in the WQL clause.
2) ("Select * from Win32_LogicalDisk where objItem.FreeSpace > 10000"). No need for objItem, just the pure property name. As with all scripting learn to apply the punctuation correctly.
Example 2 - Select only File Systems that are NTFS.
The key WQL clause is where FileSystem = 'NTFS'")
("Select * from Win32_LogicalDisk where FileSystem = 'NTFS'")
Tutorial Learning Points
1) In truth, text filters are harder than numeric filters. The greatest problems are with the speech marks.
("Select * from Win32_LogicalDisk where FileSystem = 'NTFS'"). Again looks easy, but here are some mistakes. Where FileSystem = ' NTFS '". It is outrageous that blank spaces should cause problems - but they do.
2) Here is another error, note the wrong type of speech marks. where FileSystem = "NTFS"". The spacing is correct but NTFS should be bracketed by a pair of single speech marks, the double quotes draws an error message.
. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .. . . . . .
2 comments:
One of the example taken from link
[http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WinBatch/WMI+Get~Win32_DiskDrive~Data~with~DeviceID.txt] is as below
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
sDriveInfo = StrCat( "Disk drive Caption: ", caption , @CRLF)
sDriveInfo = StrCat(sDriveInfo, "DeviceID: ", " (", objDiskDrive.DeviceID, ")")
Message("Disk Drive Info", sDriveInfo)
Next
objDiskDrives = 0
objServices = 0
Exit
Another Link
http://bytes.com/groups/net-c/276247-get-drive-letter-win32_diskdrive
Post a Comment