WMI (Windows Management Instrumentation)
Originally by shajul: https://www.autohotkey.com/board/topic/60968-wmi-tasks-com-with-ahk-l/
WMI Tasks COM with AutoHotkey
Some examples from MSDN.
CD-ROM drives details
AutoHotkey v1
strComputer := "." objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2") colItems := objWMIService.ExecQuery("Select * from Win32_CDROMDrive")._NewEnum While colItems[objItem] MsgBox % "Device ID: " . objItem.DeviceID . "`nDescription: " . objItem.Description . "`nName: " . objItem.Name
AutoHotkey v2
strComputer := "." objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2") colItems := objWMIService.ExecQuery("Select * from Win32_CDROMDrive") for objItem in colItems { MsgBox ( "Device ID: " . objItem.DeviceID "`nDescription: " . objItem.Description "`nName: " . objItem.Name ) }
Ping without ping.exe
AutoHotkey v1
strComputer := "." objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2") colPings := objWMIService.ExecQuery("Select * From Win32_PingStatus where Address = 'www.google.com'")._NewEnum ;or ip address like 192.168.1.1 While colPings[objStatus] { If (objStatus.StatusCode="" or objStatus.StatusCode<>0) MsgBox Computer did not respond. Else MsgBox Computer responded. }
AutoHotkey v2
strComputer := "." objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2") colPings := objWMIService.ExecQuery("Select * From Win32_PingStatus where Address = 'www.google.com'") ;or ip address like 192.168.1.1 for objStatus in colPings { If (objStatus.StatusCode="" || objStatus.StatusCode != 0) MsgBox "Computer did not respond." Else MsgBox "Computer responded." }
Computer system details
AutoHotkey v1
strComputer := "." objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2") colSettings := objWMIService.ExecQuery("Select * from Win32_ComputerSystem")._NewEnum Gui, Add, ListView, x0 y0 r45 w400 h500 vMyLV, Attribute|Value GuiControl, -Redraw, MyLV While colSettings[strCSItem] { LV_Add("","AdminPasswordStatus",strCSItem.AdminPasswordStatus ) LV_Add("","AutomaticResetBootOption",strCSItem.AutomaticResetBootOption ) LV_Add("","AutomaticResetCapability",strCSItem.AutomaticResetCapability ) LV_Add("","BootROMSupported",strCSItem.BootROMSupported ) LV_Add("","BootupState",strCSItem.BootupState ) LV_Add("","Caption",strCSItem.Caption ) LV_Add("","ChassisBootupState",strCSItem.ChassisBootupState ) LV_Add("","CurrentTimeZone",strCSItem.CurrentTimeZone ) LV_Add("","DaylightInEffect",strCSItem.DaylightInEffect ) LV_Add("","Description",strCSItem.Description ) LV_Add("","Domain",strCSItem.Domain ) LV_Add("","DomainRole",strCSItem.DomainRole ) LV_Add("","EnableDaylightSavingsTime",strCSItem.EnableDaylightSavingsTime ) LV_Add("","FrontPanelResetStatus",strCSItem.FrontPanelResetStatus ) LV_Add("","InfraredSupported",strCSItem.InfraredSupported ) LV_Add("","KeyboardPasswordStatus",strCSItem.KeyboardPasswordStatus ) LV_Add("","Manufacturer",strCSItem.Manufacturer ) LV_Add("","Model",strCSItem.Model ) LV_Add("","Name",strCSItem.Name ) LV_Add("","NetworkServerModeEnabled",strCSItem.NetworkServerModeEnabled ) LV_Add("","NumberOfLogicalProcessors",strCSItem.NumberOfLogicalProcessors ) LV_Add("","NumberOfProcessors",strCSItem.NumberOfProcessors ) LV_Add("","OEMStringArray",strCSItem.OEMStringArray ) LV_Add("","PartOfDomain",strCSItem.PartOfDomain ) LV_Add("","PauseAfterReset",strCSItem.PauseAfterReset ) LV_Add("","PowerOnPasswordStatus",strCSItem.PowerOnPasswordStatus ) LV_Add("","PowerState",strCSItem.PowerState ) LV_Add("","PowerSupplyState",strCSItem.PowerSupplyState ) LV_Add("","PrimaryOwnerContact",strCSItem.PrimaryOwnerContact ) LV_Add("","PrimaryOwnerName",strCSItem.PrimaryOwnerName ) LV_Add("","ResetCapability",strCSItem.ResetCapability ) LV_Add("","ResetCount",strCSItem.ResetCount ) LV_Add("","ResetLimit",strCSItem.ResetLimit ) LV_Add("","Roles",strCSItem.Roles ) LV_Add("","Status",strCSItem.Status ) LV_Add("","SupportContactDescription",strCSItem.SupportContactDescription ) LV_Add("","SystemStartupDelay",strCSItem.SystemStartupDelay ) LV_Add("","SystemStartupOptions",strCSItem.SystemStartupOptions ) LV_Add("","SystemStartupSetting",strCSItem.SystemStartupSetting ) LV_Add("","SystemType",strCSItem.SystemType ) LV_Add("","ThermalState",strCSItem.ThermalState ) LV_Add("","TotalPhysicalMemory",Round(strCSItem.TotalPhysicalMemory/(1024*1024),0) . " MB") LV_Add("","UserName",strCSItem.UserName ) LV_Add("","WakeUpType",strCSItem.WakeUpType ) LV_Add("","Workgroup",strCSItem.Workgroup ) } GuiControl, +Redraw, MyLV LV_ModifyCol() Gui, Show, w400 h500, Computer Details Return GuiClose: ExitApp
AutoHotkey v2
strComputer := "." objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2") colSettings := objWMIService.ExecQuery("Select * from Win32_ComputerSystem") g := Gui("", "Computer Details") g.OnEvent("close", (*) => ExitApp()) lv := g.AddListView("x0 y0 r45 w400 h500", ["Attribute", "Value"]) lv.Opt("-Redraw") for strCSItem in colSettings { lv.Add("","AdminPasswordStatus",strCSItem.AdminPasswordStatus ) lv.Add("","AutomaticResetBootOption",strCSItem.AutomaticResetBootOption ) lv.Add("","AutomaticResetCapability",strCSItem.AutomaticResetCapability ) lv.Add("","BootROMSupported",strCSItem.BootROMSupported ) lv.Add("","BootupState",strCSItem.BootupState ) lv.Add("","Caption",strCSItem.Caption ) lv.Add("","ChassisBootupState",strCSItem.ChassisBootupState ) lv.Add("","CurrentTimeZone",strCSItem.CurrentTimeZone ) lv.Add("","DaylightInEffect",strCSItem.DaylightInEffect ) lv.Add("","Description",strCSItem.Description ) lv.Add("","Domain",strCSItem.Domain ) lv.Add("","DomainRole",strCSItem.DomainRole ) lv.Add("","EnableDaylightSavingsTime",strCSItem.EnableDaylightSavingsTime ) lv.Add("","FrontPanelResetStatus",strCSItem.FrontPanelResetStatus ) lv.Add("","InfraredSupported",strCSItem.InfraredSupported ) lv.Add("","KeyboardPasswordStatus",strCSItem.KeyboardPasswordStatus ) lv.Add("","Manufacturer",strCSItem.Manufacturer ) lv.Add("","Model",strCSItem.Model ) lv.Add("","Name",strCSItem.Name ) lv.Add("","NetworkServerModeEnabled",strCSItem.NetworkServerModeEnabled ) lv.Add("","NumberOfLogicalProcessors",strCSItem.NumberOfLogicalProcessors ) lv.Add("","NumberOfProcessors",strCSItem.NumberOfProcessors ) lv.Add("","OEMStringArray",strCSItem.OEMStringArray ) lv.Add("","PartOfDomain",strCSItem.PartOfDomain ) lv.Add("","PauseAfterReset",strCSItem.PauseAfterReset ) lv.Add("","PowerOnPasswordStatus",strCSItem.PowerOnPasswordStatus ) lv.Add("","PowerState",strCSItem.PowerState ) lv.Add("","PowerSupplyState",strCSItem.PowerSupplyState ) lv.Add("","PrimaryOwnerContact",strCSItem.PrimaryOwnerContact ) lv.Add("","PrimaryOwnerName",strCSItem.PrimaryOwnerName ) lv.Add("","ResetCapability",strCSItem.ResetCapability ) lv.Add("","ResetCount",strCSItem.ResetCount ) lv.Add("","ResetLimit",strCSItem.ResetLimit ) lv.Add("","Roles",strCSItem.Roles ) lv.Add("","Status",strCSItem.Status ) lv.Add("","SupportContactDescription",strCSItem.SupportContactDescription ) lv.Add("","SystemStartupDelay",strCSItem.SystemStartupDelay ) lv.Add("","SystemStartupOptions",strCSItem.SystemStartupOptions ) lv.Add("","SystemStartupSetting",strCSItem.SystemStartupSetting ) lv.Add("","SystemType",strCSItem.SystemType ) lv.Add("","ThermalState",strCSItem.ThermalState ) lv.Add("","TotalPhysicalMemory",Round(strCSItem.TotalPhysicalMemory/(1024*1024),0) . " MB") lv.Add("","UserName",strCSItem.UserName ) lv.Add("","WakeUpType",strCSItem.WakeUpType ) lv.Add("","Workgroup",strCSItem.Workgroup ) } lv.Opt("+Redraw") lv.ModifyCol() g.Show("w400 h500") return
Operating system details and free physical memory
AutoHotkey v1
strComputer := "." objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2") colSettings := objWMIService.ExecQuery("Select * from Win32_OperatingSystem")._NewEnum Gui, Add, ListView, x0 y0 r45 w400 h500 vMyLV, Attribute|Value GuiControl, -Redraw, MyLV While colSettings[objOSItem] { LV_Add("","Build Number" ,objOSItem.BuildNumber ) LV_Add("","Build Type" ,objOSItem.BuildType ) LV_Add("","Caption" ,objOSItem.Caption ) LV_Add("","CountryCode" ,objOSItem.CountryCode ) LV_Add("","CreationClassName" ,objOSItem.CreationClassName ) LV_Add("","CSDVersion" ,objOSItem.CSDVersion ) LV_Add("","CSName" ,objOSItem.CSName ) LV_Add("","CurrentTimeZone" ,objOSItem.CurrentTimeZone ) LV_Add("","Distributed" ,objOSItem.Distributed ) LV_Add("","EncryptionLevel" ,objOSItem.EncryptionLevel ) LV_Add("","FreePhysicalMemory" ,objOSItem.FreePhysicalMemory ) LV_Add("","FreeSpaceInPagingFiles" ,objOSItem.FreeSpaceInPagingFiles ) LV_Add("","FreeVirtualMemory" ,objOSItem.FreeVirtualMemory ) LV_Add("","InstallDate" ,objOSItem.InstallDate ) LV_Add("","LargeSystemCache" ,objOSItem.LargeSystemCache ) LV_Add("","LastBootUpTime" ,objOSItem.LastBootUpTime ) LV_Add("","LocalDateTime" ,objOSItem.LocalDateTime ) LV_Add("","Locale" ,objOSItem.Locale ) LV_Add("","Manufacturer" ,objOSItem.Manufacturer ) LV_Add("","MaxNumberOfProcesses" ,objOSItem.MaxNumberOfProcesses ) LV_Add("","MaxProcessMemorySize" ,objOSItem.MaxProcessMemorySize ) LV_Add("","Name" ,objOSItem.Name ) LV_Add("","NumberOfLicensedUsers" ,objOSItem.NumberOfLicensedUsers ) LV_Add("","NumberOfProcesses" ,objOSItem.NumberOfProcesses ) LV_Add("","NumberOfUsers" ,objOSItem.NumberOfUsers ) LV_Add("","Organization" ,objOSItem.Organization ) LV_Add("","OSLanguage" ,objOSItem.OSLanguage ) LV_Add("","OSType" ,objOSItem.OSType ) LV_Add("","Primary" ,objOSItem.Primary ) LV_Add("","ProductType" ,objOSItem.ProductType ) LV_Add("","RegisteredUser" ,objOSItem.RegisteredUser ) LV_Add("","SerialNumber" ,objOSItem.SerialNumber ) LV_Add("","ServicePackMajorVersion" ,objOSItem.ServicePackMajorVersion ) LV_Add("","ServicePackMinorVersion" ,objOSItem.ServicePackMinorVersion ) LV_Add("","SizeStoredInPagingFiles" ,objOSItem.SizeStoredInPagingFiles ) LV_Add("","Status" ,objOSItem.Status ) LV_Add("","SuiteMask" ,objOSItem.SuiteMask ) LV_Add("","SystemDevice" ,objOSItem.SystemDevice ) LV_Add("","SystemDirectory" ,objOSItem.SystemDirectory ) LV_Add("","SystemDrive" ,objOSItem.SystemDrive ) LV_Add("","TotalSwapSpaceSize" ,objOSItem.TotalSwapSpaceSize ) LV_Add("","TotalVirtualMemorySize" ,objOSItem.TotalVirtualMemorySize ) LV_Add("","TotalVisibleMemorySize" ,objOSItem.TotalVisibleMemorySize ) LV_Add("","Version" ,objOSItem.Version ) LV_Add("","WindowsDirectory" ,objOSItem.WindowsDirectory ) } GuiControl, +Redraw, MyLV LV_ModifyCol() Gui, Show, w400 h500, Operating System Details Return GuiClose: ExitApp
AutoHotkey v2
strComputer := "." objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2") colSettings := objWMIService.ExecQuery("Select * from Win32_OperatingSystem") g := Gui("", "Operating System Details") g.OnEvent("close", (*) => ExitApp()) lv := g.AddListView("x0 y0 r45 w400 h500", ["Attribute", "Value"]) lv.Opt("-Redraw") for objOSItem in colSettings { lv.Add("","Build Number" ,objOSItem.BuildNumber ) lv.Add("","Build Type" ,objOSItem.BuildType ) lv.Add("","Caption" ,objOSItem.Caption ) lv.Add("","CountryCode" ,objOSItem.CountryCode ) lv.Add("","CreationClassName" ,objOSItem.CreationClassName ) lv.Add("","CSDVersion" ,objOSItem.CSDVersion ) lv.Add("","CSName" ,objOSItem.CSName ) lv.Add("","CurrentTimeZone" ,objOSItem.CurrentTimeZone ) lv.Add("","Distributed" ,objOSItem.Distributed ) lv.Add("","EncryptionLevel" ,objOSItem.EncryptionLevel ) lv.Add("","FreePhysicalMemory" ,objOSItem.FreePhysicalMemory ) lv.Add("","FreeSpaceInPagingFiles" ,objOSItem.FreeSpaceInPagingFiles ) lv.Add("","FreeVirtualMemory" ,objOSItem.FreeVirtualMemory ) lv.Add("","InstallDate" ,objOSItem.InstallDate ) lv.Add("","LargeSystemCache" ,objOSItem.LargeSystemCache ) lv.Add("","LastBootUpTime" ,objOSItem.LastBootUpTime ) lv.Add("","LocalDateTime" ,objOSItem.LocalDateTime ) lv.Add("","Locale" ,objOSItem.Locale ) lv.Add("","Manufacturer" ,objOSItem.Manufacturer ) lv.Add("","MaxNumberOfProcesses" ,objOSItem.MaxNumberOfProcesses ) lv.Add("","MaxProcessMemorySize" ,objOSItem.MaxProcessMemorySize ) lv.Add("","Name" ,objOSItem.Name ) lv.Add("","NumberOfLicensedUsers" ,objOSItem.NumberOfLicensedUsers ) lv.Add("","NumberOfProcesses" ,objOSItem.NumberOfProcesses ) lv.Add("","NumberOfUsers" ,objOSItem.NumberOfUsers ) lv.Add("","Organization" ,objOSItem.Organization ) lv.Add("","OSLanguage" ,objOSItem.OSLanguage ) lv.Add("","OSType" ,objOSItem.OSType ) lv.Add("","Primary" ,objOSItem.Primary ) lv.Add("","ProductType" ,objOSItem.ProductType ) lv.Add("","RegisteredUser" ,objOSItem.RegisteredUser ) lv.Add("","SerialNumber" ,objOSItem.SerialNumber ) lv.Add("","ServicePackMajorVersion" ,objOSItem.ServicePackMajorVersion ) lv.Add("","ServicePackMinorVersion" ,objOSItem.ServicePackMinorVersion ) lv.Add("","SizeStoredInPagingFiles" ,objOSItem.SizeStoredInPagingFiles ) lv.Add("","Status" ,objOSItem.Status ) lv.Add("","SuiteMask" ,objOSItem.SuiteMask ) lv.Add("","SystemDevice" ,objOSItem.SystemDevice ) lv.Add("","SystemDirectory" ,objOSItem.SystemDirectory ) lv.Add("","SystemDrive" ,objOSItem.SystemDrive ) lv.Add("","TotalSwapSpaceSize" ,objOSItem.TotalSwapSpaceSize ) lv.Add("","TotalVirtualMemorySize" ,objOSItem.TotalVirtualMemorySize ) lv.Add("","TotalVisibleMemorySize" ,objOSItem.TotalVisibleMemorySize ) lv.Add("","Version" ,objOSItem.Version ) lv.Add("","WindowsDirectory" ,objOSItem.WindowsDirectory ) } lv.Opt("+Redraw") lv.ModifyCol() g.Show("w400 h500") return
Properties of the mouse used on computer
AutoHotkey v1
strComputer := "." objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2") colItems := objWMIService.ExecQuery("Select * from Win32_PointingDevice")._NewEnum While colItems[objItem] MsgBox % "Description: " . objItem.Description . "`nDevice ID: " . objItem.DeviceID . "`nDevice Interface: " . objItem.DeviceInterface . "`nDouble Speed Threshold: " . objItem.DoubleSpeedThreshold . "`nHandedness: " . objItem.Handedness . "`nHardware Type: " . objItem.HardwareType . "`nINF File Name: " . objItem.InfFileName . "`nINF Section: " . objItem.InfSection . "`nManufacturer: " . objItem.Manufacturer . "`nName: " . objItem.Name . "`nNumber Of Buttons: " . objItem.NumberOfButtons . "`nPNP Device ID: " . objItem.PNPDeviceID . "`nPointing Type: " . objItem.PointingType . "`nQuad Speed Threshold: " . objItem.QuadSpeedThreshold . "`nResolution: " . objItem.Resolution . "`nSample Rate: " . objItem.SampleRate . "`nSynch: " . objItem.Synch
AutoHotkey v2
strComputer := "." objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2") colItems := objWMIService.ExecQuery("Select * from Win32_PointingDevice") for objItem in colItems { MsgBox ( "Description: " . objItem.Description "`nDevice ID: " . objItem.DeviceID "`nDevice Interface: " . objItem.DeviceInterface "`nDouble Speed Threshold: " . objItem.DoubleSpeedThreshold "`nHandedness: " . objItem.Handedness "`nHardware Type: " . objItem.HardwareType "`nINF File Name: " . objItem.InfFileName "`nINF Section: " . objItem.InfSection "`nManufacturer: " . objItem.Manufacturer "`nName: " . objItem.Name "`nNumber Of Buttons: " . objItem.NumberOfButtons "`nPNP Device ID: " . objItem.PNPDeviceID "`nPointing Type: " . objItem.PointingType "`nQuad Speed Threshold: " . objItem.QuadSpeedThreshold "`nResolution: " . objItem.Resolution "`nSample Rate: " . objItem.SampleRate "`nSynch: " . objItem.Synch ) }
List BIOS details
AutoHotkey v1
strComputer := "." objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2") colSettings := objWMIService.ExecQuery("Select * from Win32_BIOS")._NewEnum While colSettings[objBiosItem] { MsgBox % "BIOSVersion : " . objBiosItem.BIOSVersion . "`nBuildNumber : " . objBiosItem.BuildNumber . "`nCaption : " . objBiosItem.Caption . "`nCurrentLanguage : " . objBiosItem.CurrentLanguage . "`nDescription : " . objBiosItem.Description . "`nInstallableLanguages : " . objBiosItem.InstallableLanguages . "`nInstallDate : " . objBiosItem.InstallDate . "`nListOfLanguages : " . objBiosItem.ListOfLanguages . "`nManufacturer : " . objBiosItem.Manufacturer . "`nName : " . objBiosItem.Name . "`nPrimaryBIOS : " . objBiosItem.PrimaryBIOS . "`nReleaseDate : " . objBiosItem.ReleaseDate . "`nSerialNumber2 : " . objBiosItem.SerialNumber . "`nSMBIOSBIOSVersion : " . objBiosItem.SMBIOSBIOSVersion . "`nSMBIOSMajorVersion : " . objBiosItem.SMBIOSMajorVersion . "`nSMBIOSMinorVersion : " . objBiosItem.SMBIOSMinorVersion . "`nSMBIOSPresent : " . objBiosItem.SMBIOSPresent . "`nSoftwareElementID : " . objBiosItem.SoftwareElementID . "`nSoftwareElementState : " . objBiosItem.SoftwareElementState . "`nStatus : " . objBiosItem.Status . "`nTargetOperatingSystem : " . objBiosItem.TargetOperatingSystem . "`nVersion : " . objBiosItem.Version }
AutoHotkey v2
strComputer := "." objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2") colSettings := objWMIService.ExecQuery("Select * from Win32_BIOS") for objBiosItem in colSettings { biosVersion := "" for v in objBiosItem.BIOSVersion biosVersion .= v "," languages := "" for v in objBiosItem.ListOfLanguages languages .= v "," MsgBox ( "BIOSVersion : " . biosVersion "`nBuildNumber : " . objBiosItem.BuildNumber "`nCaption : " . objBiosItem.Caption "`nCurrentLanguage : " . objBiosItem.CurrentLanguage "`nDescription : " . objBiosItem.Description "`nInstallableLanguages : " . objBiosItem.InstallableLanguages "`nInstallDate : " . objBiosItem.InstallDate "`nListOfLanguages : " . languages "`nManufacturer : " . objBiosItem.Manufacturer "`nName : " . objBiosItem.Name "`nPrimaryBIOS : " . objBiosItem.PrimaryBIOS "`nReleaseDate : " . objBiosItem.ReleaseDate "`nSerialNumber2 : " . objBiosItem.SerialNumber "`nSMBIOSBIOSVersion : " . objBiosItem.SMBIOSBIOSVersion "`nSMBIOSMajorVersion : " . objBiosItem.SMBIOSMajorVersion "`nSMBIOSMinorVersion : " . objBiosItem.SMBIOSMinorVersion "`nSMBIOSPresent : " . objBiosItem.SMBIOSPresent "`nSoftwareElementID : " . objBiosItem.SoftwareElementID "`nSoftwareElementState : " . objBiosItem.SoftwareElementState "`nStatus : " . objBiosItem.Status "`nTargetOperatingSystem : " . objBiosItem.TargetOperatingSystem "`nVersion : " . objBiosItem.Version ) }