Created
April 20, 2021 02:03
-
-
Save clalancette/43d79a7357da355e33b0c4f2bb012e22 to your computer and use it in GitHub Desktop.
Get CD information from Windows WMI without wmi library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import win32com.client | |
def get_raw_windows_device_size(): | |
obj = win32com.client.GetObject("winmgmts:") | |
typecomp = obj._oleobj_.GetTypeInfo().GetContainingTypeLib()[0].GetTypeComp() | |
result = typecomp.Bind('wbemFlagReturnImmediately') | |
if not result[0]: | |
raise AttributeError(name) | |
wbemFlagReturnImmediately = result[1].value | |
result = typecomp.Bind('wbemFlagForwardOnly') | |
if not result[0]: | |
raise AttributeError(name) | |
wbemFlagForwardOnly = result[1].value | |
query = "SELECT * FROM Win32_CDROMDrive WHERE Drive = 'D:'" | |
wql = query.replace("\\", "\\\\") | |
flags = wbemFlagReturnImmediately | wbemFlagForwardOnly | |
ole_obj = obj.ExecQuery(strQuery=wql, iFlags=flags) | |
size = None | |
for o in ole_obj: | |
if size is not None: | |
raise ValueError('Only expected one size') | |
size = o.Properties_('size').Value | |
return size | |
print(get_raw_windows_device_size()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment