Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

WMI Tasks COM with AHK_L


  • Please log in to reply
18 replies to this topic
shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006
WMI Tasks COM with AHK_L

Some examples from MSDN http://msdn.microsof...5(v=VS.85).aspx.

New users can convert all the MSDN examples given to Native AHK code, I am just giving some examples


CD-ROM drives details:
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

Ping without ping.exe :
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.
}

Computer system details:
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

Operating system details and free physical memory:
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

Properties of the mouse used on computer:
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

List Desktop settings:
strComputer := "."
objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2")

colItems := objWMIService.ExecQuery("Select * from Win32_Desktop")._NewEnum
While colItems[objItem] 
    MsgBox % "Border Width: " . objItem.BorderWidth 
    . "`nCaption: " . objItem.Caption 
    . "`nCool Switch: " . objItem.CoolSwitch 
    . "`nCursor Blink Rate: " . objItem.CursorBlinkRate 
    . "`nDescription: " . objItem.Description 
    . "`nDrag Full Windows: " . objItem.DragFullWindows 
    . "`nGrid Granularity: " . objItem.GridGranularity 
    . "`nIcon Spacing: " . objItem.IconSpacing 
    . "`nIcon Title Face Name: " . objItem.IconTitleFaceName 
    . "`nIcon Title Size: " . objItem.IconTitleSize 
    . "`nIcon Title Wrap: " . objItem.IconTitleWrap 
    . "`nName: " . objItem.Name 
    . "`nPattern: " . objItem.Pattern 
    . "`nScreen Saver Active: " . objItem.ScreenSaverActive 
    . "`nScreen Saver Executable: " . objItem.ScreenSaverExecutable 
    . "`nScreen Saver Secure: " . objItem.ScreenSaverSecure 
    . "`nScreen Saver Timeout: " . objItem.ScreenSaverTimeout 
    . "`nSetting ID: " . objItem.SettingID 
    . "`nWallpaper: " . objItem.Wallpaper 
    . "`nWallpaper Stretched: " . objItem.WallpaperStretched 
    . "`nWallpaper Tiled: " . objItem.WallpaperTiled

List BIOS details
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 
}


tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: Oct 13 2016 01:04 AM
  • Joined: 21 Dec 2007
excelent example of how AHK_L trumps basic
Never lose.
WIN or LEARN.

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006

excelent example of how AHK_L trumps basic


No doubt about it, 'cause now even noobs can tap the potential of WMI and COM in general! 8)

sbc
  • Members
  • 321 posts
  • Last active: Jun 07 2011 10:24 AM
  • Joined: 25 Aug 2009
Should I have posted WMI examples here rather than there? The following examples retrieve various system information.

Memory:
;http://msdn.microsoft.com/en-us/library/aa394347%28v=vs.85%29.aspx
PropertyList := [color=#666666]"BankLabel,Capacity,Caption,CreationClassName,DataWidth,Description,DeviceLocator,FormFactor,"[/color]
    . [color=#666666]"HotSwappable,InstallDate,InterleaveDataDepth,InterleavePosition,Manufacturer,MemoryType,Model,Name,"[/color]
    . [color=#666666]"OtherIdentifyingInfo,PartNumber,PositionInRow,PoweredOn,Removable,Replaceable,SerialNumber,SKU,Speed,"[/color]
    . [color=#666666]"Status,Tag,TotalWidth,TypeDetail,Version"[/color]

objWMIService := [color=#107095]ComObjGet[/color]([color=#666666]"winmgmts:{impersonationLevel=impersonate}!\\"[/color] . A_ComputerName . [color=#666666]"\root\cimv2"[/color])
WQLQuery = Select * From Win32_PhysicalMemory
colMemInfo := objWMIService.ExecQuery(WQLQuery)._NewEnum
[color=#107095]While[/color] colMemInfo[objMemInfo]
    [color=#107095]Loop[/color], Parse, PropertyList, `,
        MemInfo .= A_index = 1 ? objMemInfo[A_LoopField] . [color=#666666]"`n"[/color] : [color=#666666]"`t"[/color] . A_LoopField . [color=#666666]":`t"[/color] . objMemInfo[A_LoopField] . [color=#666666]"`n"[/color]
logfile = %A_ScriptDir%\MemoryInfoList.txt
[color=#107095]FileDelete[/color], %logfile%
[color=#107095]FileAppend[/color], %MemInfo%, %logfile%
[color=#107095]Run[/color], Notepad [color=#666666]"%logfile%"[/color]

Onboard Devices:
;http://msdn.microsoft.com/en-us/library/aa394238%28VS.85%29.aspx
PropertyList := [color=#666666]"Caption,CreationClassName,Description,DeviceType,Enabled,"[/color]
	. [color=#666666]"HotSwappable,InstallDate,Manufacturer,Model,Name,OtherIdentifyingInfo,"[/color]
	. [color=#666666]"PartNumber,PoweredOn,Removable,Replaceable,SerialNumber,SKU,Status,Tag,Version"[/color]
	
objWMIService := [color=#107095]ComObjGet[/color]([color=#666666]"winmgmts:{impersonationLevel=impersonate}!\\"[/color] . A_ComputerName . [color=#666666]"\root\cimv2"[/color])
WQLQuery = Select * From Win32_OnBoardDevice
colOnboard := objWMIService.ExecQuery(WQLQuery)._NewEnum
[color=#107095]While[/color] colOnboard[objOnboard]
	[color=#107095]Loop[/color], Parse, PropertyList, `,
		OnboardDeviceList .= A_index = 1 ? objOnboard[A_LoopField] . [color=#666666]"`n"[/color] : [color=#666666]"`t"[/color] . A_LoopField . [color=#666666]":`t"[/color] . objOnboard[A_LoopField] . [color=#666666]"`n"[/color]

logfile = %A_ScriptDir%\OnboardDeviceList.txt
[color=#107095]FileDelete[/color], %logfile%
[color=#107095]FileAppend[/color], %OnboardDeviceList%, %logfile%
[color=#107095]Run[/color], Notepad [color=#666666]"%logfile%"[/color]

Hard Drives:
;http://msdn.microsoft.com/en-us/library/aa394132%28v=vs.85%29.aspx
PropertyList := [color=#666666]"Caption,Availability,BytesPerSector,CompressionMethod,ConfigManagerErrorCode,"[/color]
	. [color=#666666]"ConfigManagerUserConfig,CreationClassName,DefaultBlockSize,Description,DeviceID,ErrorCleared,"[/color]
	. [color=#666666]"ErrorDescription,ErrorMethodology,FirmwareRevision,Index,InstallDate,InterfaceType,LastErrorCode,"[/color]
	. [color=#666666]"Manufacturer,MaxBlockSize,MaxMediaSize,MediaLoaded,MediaType,MinBlockSize,Model,Name,NeedsCleaning,"[/color]
	. [color=#666666]"NumberOfMediaSupported,Partitions,PNPDeviceID,PowerManagementSupported,SCSIBus,SCSILogicalUnit,"[/color]
	. [color=#666666]"SCSIPort,SCSITargetId,SectorsPerTrack,SerialNumber,Signature,Size,Status,StatusInfo,"[/color]
	. [color=#666666]"SystemCreationClassName,SystemName,TotalCylinders,TotalHeads,TotalSectors,TotalTracks,TracksPerCylinder"[/color]
	
objWMIService := [color=#107095]ComObjGet[/color]([color=#666666]"winmgmts:{impersonationLevel=impersonate}!\\"[/color] . A_ComputerName . [color=#666666]"\root\cimv2"[/color])
WQLQuery = Select * From Win32_DiskDrive 
colDiskDrive := objWMIService.ExecQuery(WQLQuery)._NewEnum
[color=#107095]While[/color] colDiskDrive[objDiskDrive] 
	[color=#107095]Loop[/color], Parse, PropertyList, `,
		DiskDriveInfo  .= A_index = 1 ? objDiskDrive[A_LoopField] . [color=#666666]"`n"[/color] : [color=#666666]"`t"[/color] . A_LoopField . [color=#666666]":`t"[/color] . objDiskDrive[A_LoopField] . [color=#666666]"`n"[/color]
			
logfile = %A_ScriptDir%\DiskDriveInfo.txt
[color=#107095]FileDelete[/color], %logfile%
[color=#107095]FileAppend[/color], %DiskDriveInfo%, %logfile%
[color=#107095]Run[/color], Notepad [color=#666666]"%logfile%"[/color]

Motherboard:
;http://msdn.microsoft.com/en-us/library/aa394072%28v=vs.85%29.aspx
PropertyList := [color=#666666]"Caption,CreationClassName,Depth,Description,Height,HostingBoard,HotSwappable,InstallDate,"[/color]
	. [color=#666666]"Manufacturer,Model,Name,OtherIdentifyingInfo,PartNumber,PoweredOn,Product,Removable,Replaceable,"[/color]
	. [color=#666666]"RequirementsDescription,RequiresDaughterBoard,SerialNumber,SKU,SlotLayout,SpecialRequirements,"[/color]
	. [color=#666666]"Status,Tag,Version,Weight,Width"[/color]
objWMIService := [color=#107095]ComObjGet[/color]([color=#666666]"winmgmts:{impersonationLevel=impersonate}!\\"[/color] . A_ComputerName . [color=#666666]"\root\cimv2"[/color])
WQLQuery = Select * From Win32_BaseBoard
colMBInfo := objWMIService.ExecQuery(WQLQuery)._NewEnum
[color=#107095]While[/color] colMBInfo[objMBInfo]   
	[color=#107095]Loop[/color], Parse, PropertyList, `,
		MatherBoardInfo .= A_LoopField . [color=#666666]":`t"[/color] . objMBInfo[A_LoopField] . [color=#666666]"`n"[/color]
[color=#107095]MsgBox[/color] % MatherBoardInfo

CPU:
;http://msdn.microsoft.com/en-us/library/aa394373%28v=vs.85%29.aspx
PropertyList := [color=#666666]"AddressWidth,Architecture,Availability,Caption,ConfigManagerErrorCode,"[/color]
	. [color=#666666]"ConfigManagerUserConfig,CpuStatus,CreationClassName,CurrentClockSpeed,CurrentVoltage,"[/color]
	. [color=#666666]"DataWidth,Description,DeviceID,ErrorCleared,ErrorDescription,ExtClock,Family,InstallDate,"[/color]
	. [color=#666666]"L2CacheSize,L2CacheSpeed,L3CacheSize,L3CacheSpeed,LastErrorCode,Level,LoadPercentage,"[/color]
	. [color=#666666]"Manufacturer,MaxClockSpeed,Name,NumberOfCores,NumberOfLogicalProcessors,OtherFamilyDescription,"[/color]
	. [color=#666666]"PNPDeviceID,PowerManagementSupported,ProcessorId,ProcessorType,Revision,Role,SocketDesignation,"[/color]
	. [color=#666666]"Status,StatusInfo,Stepping,SystemCreationClassName,SystemName,UniqueId,UpgradeMethod,Version,VoltageCaps"[/color]
	
objWMIService := [color=#107095]ComObjGet[/color]([color=#666666]"winmgmts:{impersonationLevel=impersonate}!\\"[/color] . A_ComputerName . [color=#666666]"\root\cimv2"[/color])
WQLQuery = Select * From Win32_Processor
colCPU := objWMIService.ExecQuery(WQLQuery)._NewEnum
[color=#107095]While[/color] colCPU[objCPU]
	[color=#107095]Loop[/color], Parse, PropertyList, `,
		CPUInfo .= A_LoopField . [color=#666666]":`t"[/color] . objCPU[A_LoopField] . [color=#666666]"`n"[/color]

logfile = %A_ScriptDir%\CPUInfo.txt
[color=#107095]FileDelete[/color], %logfile%
[color=#107095]FileAppend[/color], %CPUInfo%, %logfile%
[color=#107095]Run[/color], Notepad [color=#666666]"%logfile%"[/color]

Product:
;http://msdn.microsoft.com/en-us/library/aa394105%28v=vs.85%29.aspx
PropertyList := [color=#666666]"Caption,Description,IdentifyingNumber,Name,SKUNumber,UUID,Vendor,Version"[/color]
objWMIService := [color=#107095]ComObjGet[/color]([color=#666666]"winmgmts:{impersonationLevel=impersonate}!\\"[/color] . A_ComputerName . [color=#666666]"\root\cimv2"[/color])
WQLQuery = Select * From Win32_ComputerSystemProduct
colSysProduct := objWMIService.ExecQuery(WQLQuery)._NewEnum
[color=#107095]While[/color] colSysProduct[objSysProduct] 
	[color=#107095]Loop[/color], Parse, PropertyList, `,
		ProductInfo .= A_LoopField . [color=#666666]":`t"[/color] . objSysProduct[A_LoopField] . [color=#666666]"`n"[/color]
[color=#107095]MsgBox[/color] % ProductInfo

Edit: Shortened codes

shajul
  • Members
  • 571 posts
  • Last active: Aug 01 2015 03:45 PM
  • Joined: 15 Sep 2006

Should I have posted WMI examples here rather than there? The following examples retrieve various system information.


Both places, or link one to another :)
Basic goal is if somebody wants it, it should be easy to find.

Good examples.

tank
  • Administrators
  • 4345 posts
  • AutoHotkey Foundation
  • Last active: Oct 13 2016 01:04 AM
  • Joined: 21 Dec 2007
I have to confess my WMI is a bit weak. but this is an awesome set of very usefull real world examples
Never lose.
WIN or LEARN.

sbc
  • Members
  • 321 posts
  • Last active: Jun 07 2011 10:24 AM
  • Joined: 25 Aug 2009
Thanks guys, I appreciate your appreciation.

List of Installed Applications
;http://msdn.microsoft.com/en-us/library/aa394068(VS.85).aspx
PropertyList := [color=#666666]"ProductName,Accesses,Attributes,Caption,Description,IdentifyingNumber,"[/color]
    . [color=#666666]"InstallDate,InstallState,LastUse,Name,Status,Vendor,Version"[/color]
WMIClass := [color=#666666]"Win32_SoftwareFeature"[/color]
objWMIService := [color=#107095]ComObjGet[/color]([color=#666666]"winmgmts:{impersonationLevel=impersonate}!\\"[/color] . A_ComputerName . [color=#666666]"\root\cimv2"[/color])
WQLQuery := [color=#666666]"Select * From "[/color] . WMIClass
colProperties := objWMIService.ExecQuery(WQLQuery)._NewEnum
[color=#107095]While[/color] colProperties[objProperty]
    [color=#107095]Loop[/color], Parse, PropertyList, `,
        Result .= A_index = 1 ? objProperty[A_LoopField] . [color=#666666]"`n"[/color] : [color=#666666]"`t"[/color] . A_LoopField . [color=#666666]":`t"[/color] . objProperty[A_LoopField] . [color=#666666]"`n"[/color]
logfile = %A_ScriptDir%\%WMIClass%.txt
[color=#107095]FileDelete[/color], %logfile%
[color=#107095]FileAppend[/color], %Result%, %logfile%
[color=#107095]Run[/color], Notepad [color=#666666]"%logfile%"[/color]

List of Installed Audio and Video Codecs
;http://msdn.microsoft.com/en-us/library/aa394091%28VS.85%29.aspx
PropertyList := [color=#666666]"Caption,AccessMask,Archive,Compressed,CompressionMethod,"[/color]
    . [color=#666666]"CreationClassName,CreationDate,CSCreationClassName,CSName,Description,"[/color]
    . [color=#666666]"Drive,EightDotThreeFileName,Encrypted,EncryptionMethod,Extension,"[/color]
    . [color=#666666]"FileName,FileSize,FileType,FSCreationClassName,FSName,Group,Hidden,"[/color]
    . [color=#666666]"InstallDate,InUseCount,LastAccessed,LastModified,Manufacturer,Name,"[/color]
    . [color=#666666]"Path,Readable,Status,System,Version,Writeable"[/color]
WMIClass := [color=#666666]"Win32_CodecFile"[/color]
objWMIService := [color=#107095]ComObjGet[/color]([color=#666666]"winmgmts:{impersonationLevel=impersonate}!\\"[/color] . A_ComputerName . [color=#666666]"\root\cimv2"[/color])
WQLQuery := [color=#666666]"Select * From "[/color] . WMIClass
colProperties := objWMIService.ExecQuery(WQLQuery)._NewEnum
[color=#107095]While[/color] colProperties[objProperty]
    [color=#107095]Loop[/color], Parse, PropertyList, `,
        Result .= A_index = 1 ? objProperty[A_LoopField] . [color=#666666]"`n"[/color] : [color=#666666]"`t"[/color] . A_LoopField . [color=#666666]":`t"[/color] . objProperty[A_LoopField] . [color=#666666]"`n"[/color]
logfile = %A_ScriptDir%\%WMIClass%.txt
[color=#107095]FileDelete[/color], %logfile%
[color=#107095]FileAppend[/color], %Result%, %logfile%
[color=#107095]Run[/color], Notepad [color=#666666]"%logfile%"[/color]

List of Fonts installed with Applications
;http://msdn.microsoft.com/en-us/library/aa394150%28VS.85%29.aspx
PropertyList := [color=#666666]"ActionID,Caption,Description,Direction,File,FontTitle,"[/color]
    . [color=#666666]"Name,SoftwareElementID,SoftwareElementState,TargetOperatingSystem,Version"[/color]
WMIClass := [color=#666666]"Win32_FontInfoAction"[/color]
objWMIService := [color=#107095]ComObjGet[/color]([color=#666666]"winmgmts:{impersonationLevel=impersonate}!\\"[/color] . A_ComputerName . [color=#666666]"\root\cimv2"[/color])
WQLQuery := [color=#666666]"Select * From "[/color] . WMIClass
colProperties := objWMIService.ExecQuery(WQLQuery)._NewEnum
[color=#107095]While[/color] colProperties[objProperty]
    [color=#107095]Loop[/color], Parse, PropertyList, `,
        Result .= A_Index = 1 ? objProperty[A_LoopField] . [color=#666666]"`n"[/color] : [color=#666666]"`t"[/color] . A_LoopField . [color=#666666]":`t"[/color] . objProperty[A_LoopField] . [color=#666666]"`n"[/color]
logfile = %A_ScriptDir%\%WMIClass%.txt
[color=#107095]FileDelete[/color], %logfile%
[color=#107095]FileAppend[/color], %Result%, %logfile%
[color=#107095]Run[/color], Notepad [color=#666666]"%logfile%"[/color]

List of User Accounts
;http://msdn.microsoft.com/en-us/library/aa394507%28v=vs.85%29.aspx
PropertyList := [color=#666666]"Caption,AccountType,Description,Disabled,Domain,FullName,InstallDate,LocalAccount,"[/color]
    . [color=#666666]"Lockout,Name,PasswordChangeable,PasswordExpires,PasswordRequired,SID,SIDType,Status"[/color]
WMIClass := [color=#666666]"Win32_UserAccount"[/color]
objWMIService := [color=#107095]ComObjGet[/color]([color=#666666]"winmgmts:{impersonationLevel=impersonate}!\\"[/color] . A_ComputerName . [color=#666666]"\root\cimv2"[/color])
WQLQuery := [color=#666666]"Select * From "[/color] . WMIClass
colProperties := objWMIService.ExecQuery(WQLQuery)._NewEnum
[color=#107095]While[/color] colProperties[objProperty]
    [color=#107095]Loop[/color], Parse, PropertyList, `,
        Result .= A_Index = 1 ? objProperty[A_LoopField] . [color=#666666]"`n"[/color] : [color=#666666]"`t"[/color] . A_LoopField . [color=#666666]":`t"[/color] . objProperty[A_LoopField] . [color=#666666]"`n"[/color]
logfile = %A_ScriptDir%\%WMIClass%.txt
[color=#107095]FileDelete[/color], %logfile%
[color=#107095]FileAppend[/color], %Result%, %logfile%
[color=#107095]Run[/color], Notepad [color=#666666]"%logfile%"[/color]

List of System Accounts
;http://msdn.microsoft.com/en-us/library/aa394507%28v=vs.85%29.aspx
PropertyList := [color=#666666]"Name,Caption,Description,Domain,InstallDate,LocalAccount,SID,SIDType,Status"[/color]
WMIClass := [color=#666666]"Win32_SystemAccount"[/color]
objWMIService := [color=#107095]ComObjGet[/color]([color=#666666]"winmgmts:{impersonationLevel=impersonate}!\\"[/color] . A_ComputerName . [color=#666666]"\root\cimv2"[/color])
WQLQuery := [color=#666666]"Select * From "[/color] . WMIClass
colProperties := objWMIService.ExecQuery(WQLQuery)._NewEnum
[color=#107095]While[/color] colProperties[objProperty]
    [color=#107095]Loop[/color], Parse, PropertyList, `,
        Result .= A_Index = 1 ? objProperty[A_LoopField] . [color=#666666]"`n"[/color] : [color=#666666]"`t"[/color] . A_LoopField . [color=#666666]":`t"[/color] . objProperty[A_LoopField] . [color=#666666]"`n"[/color]
logfile = %A_ScriptDir%\%WMIClass%.txt
[color=#107095]FileDelete[/color], %logfile%
[color=#107095]FileAppend[/color], %Result%, %logfile%
[color=#107095]Run[/color], Notepad [color=#666666]"%logfile%"[/color]

List of Shared Folders and Printes
;http://msdn.microsoft.com/en-us/library/aa394507%28v=vs.85%29.aspx
PropertyList := [color=#666666]"Name,AccessMask,AllowMaximum,Caption,Description,InstallDate,"[/color]
    . [color=#666666]"MaximumAllowed,Path,Status,Type"[/color]
WMIClass := [color=#666666]"Win32_Share"[/color]
objWMIService := [color=#107095]ComObjGet[/color]([color=#666666]"winmgmts:{impersonationLevel=impersonate}!\\"[/color] . A_ComputerName . [color=#666666]"\root\cimv2"[/color])
WQLQuery := [color=#666666]"Select * From "[/color] . WMIClass
colProperties := objWMIService.ExecQuery(WQLQuery)._NewEnum
[color=#107095]While[/color] colProperties[objProperty]
    [color=#107095]Loop[/color], Parse, PropertyList, `,
        Result .= A_Index = 1 ? objProperty[A_LoopField] . [color=#666666]"`n"[/color] : [color=#666666]"`t"[/color] . A_LoopField . [color=#666666]":`t"[/color] . objProperty[A_LoopField] . [color=#666666]"`n"[/color]
logfile = %A_ScriptDir%\%WMIClass%.txt
[color=#107095]FileDelete[/color], %logfile%
[color=#107095]FileAppend[/color], %Result%, %logfile%
[color=#107095]Run[/color], Notepad [color=#666666]"%logfile%"[/color]


LNick
  • Members
  • 13 posts
  • Last active: Mar 22 2012 12:34 PM
  • Joined: 31 Mar 2011
This thread is awesome! All the WMI power I need in handy AHK_L form!

However I'm having a small issue that I hope the forum can help me with.

When I attempt to connect via WMI to a computer that is offline I get an error that the RPC server is unavailable. Is there a way to handle this gracefully or check if it is online before I connect?

For the thread

Display current logged in user
strComputer := "."
strNamespace := "\root\cimv2"

objWMI := ComObjGet("winmgmts:\\"  strComputer  strNamespace)
colCS := objWMI.ExecQuery("SELECT * FROM Win32_ComputerSystem")

For objSession in colCS
{
	MsgBox, % "User: " objSession.UserName
}


Yook
  • Members
  • 76 posts
  • Last active: Sep 23 2011 01:49 PM
  • Joined: 20 Nov 2008
Wow. WMI power. My contribution :

List of running processes (narrowed down to those which path can be retrieved)
strComputer := "."
objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2")
colItems := objWMIService.ExecQuery("SELECT Caption,ExecutablePath,ProcessID FROM Win32_Process where ExecutablePath is not null")._NewEnum
While colItems[objItem]
MsgBox % "Caption: " . objItem.Caption
. "`nProcessID: " . objItem.ProcessID
. "`nExecutablePath: " . objItem.ExecutablePath


oskar21
  • Members
  • 5 posts
  • Last active: Nov 27 2012 02:31 PM
  • Joined: 07 Oct 2012
Thank You very much for Your examples, sbc! Posted Image

Dummies like me Posted Image however should be told, that they have to remove all the
"(\[/color]|\[color=#\d*])"
-stuff to run the examples. At least if they want to run them in Scite4AHK!

But it is, as mother said: you always grows with your tasks! ...

sinkfaze
  • Moderators
  • 6367 posts
  • Last active:
  • Joined: 18 Mar 2008
@oskar21

The color tags presenting in the code is is a problem that has come up due to the recent forum upgrade; hopefully it will be addressed soon.

fooztr
  • Members
  • 10 posts
  • Last active: Sep 23 2015 02:09 PM
  • Joined: 28 Aug 2012
Is there any way to use this on remote clients? Having some issues with it, if you want to , please have a look here: http://www.autohotke...h-wmi-function/

fooztr
  • Members
  • 10 posts
  • Last active: Sep 23 2015 02:09 PM
  • Joined: 28 Aug 2012
In order to get shajul's code to work in my script I had to send the output to a msgbox instead of using Gui.

I share them if someone wants to use it, for some reason.

/*
  Autohotkey_L WMI (Operating system details and free physical memory)
*/
strComputer := "."
objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2")
colSettings := objWMIService.ExecQuery("Select * from Win32_OperatingSystem")._NewEnum
While colSettings[objOSItem]
{
MsgBox % "Build Number: " . objOSItem.BuildNumber
. "`nBuild Type: " . objOSItem.BuildType
. "`nCaption: " . objOSItem.Caption
. "`nCountryCode: " . objOSItem.CountryCode
. "`nCreationClassName: " . objOSItem.CreationClassName
. "`nCSDVersion: " . objOSItem.CSDVersion
. "`nCSName: " . objOSItem.CSName
. "`nCurrentTimeZone: " . objOSItem.CurrentTimeZone
. "`nDistributed: " . objOSItem.Distributed
. "`nEncryptionLevel: " . objOSItem.EncryptionLevel
. "`nFreePhysicalMemory: " . objOSItem.FreePhysicalMemory
. "`nFreeSpaceInPagingFiles: " . objOSItem.FreeSpaceInPagingFiles
. "`nFreeVirtualMemory: " . objOSItem.FreeVirtualMemory
. "`nInstallDate: " . objOSItem.InstallDate
. "`nLargeSystemCache: " . objOSItem.LargeSystemCache
. "`nLastBootUpTime: " . objOSItem.LastBootUpTime
. "`nLocalDateTime: " . objOSItem.LocalDateTime
. "`nLocale: " . objOSItem.Locale
. "`nManufacturer: " . objOSItem.Manufacturer
. "`nMaxNumberOfProcesses: " . objOSItem.MaxNumberOfProcesses
. "`nMaxProcessMemorySize: " . objOSItem.MaxProcessMemorySize
. "`nName: " . objOSItem.Name
. "`nNumberOfLicensedUsers: " . objOSItem.NumberOfLicensedUsers
. "`nNumberOfProcesses: " . objOSItem.NumberOfProcesses
. "`nNumberOfUsers: " . objOSItem.NumberOfUsers
. "`nOrganization: " . objOSItem.Organization
. "`nOSLanguage: " . objOSItem.OSLanguage
. "`nOSType: " . objOSItem.OSType
. "`nPrimary: " . objOSItem.Primary
. "`nProductType: " . objOSItem.ProductType
. "`nRegisteredUser: " . objOSItem.RegisteredUser
. "`nSerialNumber: " . objOSItem.SerialNumber
. "`nServicePackMajorVersion: " . objOSItem.ServicePackMajorVersion
. "`nServicePackMinorVersion: " . objOSItem.ServicePackMinorVersion
. "`nSizeStoredInPagingFiles: " . objOSItem.SizeStoredInPagingFiles
. "`nStatus: " . objOSItem.Status
. "`nSuiteMask: " . objOSItem.SuiteMask
. "`nSystemDevice: " . objOSItem.SystemDevice
. "`nSystemDirectory: " . objOSItem.SystemDirectory
. "`nSystemDrive: " . objOSItem.SystemDrive
. "`nTotalSwapSpaceSize: " . objOSItem.TotalSwapSpaceSize
. "`nTotalVirtualMemorySize: " . objOSItem.TotalVirtualMemorySize
. "`nTotalVisibleMemorySize: " . objOSItem.TotalVisibleMemorySize
. "`nVersion: " . objOSItem.Version
. "`nWindowsDirectory: " . objOSItem.WindowsDirectory
}

/*
  Autohotkey_L WMI (Computer system details)
*/
strComputer := "."
objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . strComputer . "\root\cimv2")
colSettings := objWMIService.ExecQuery("Select * from Win32_ComputerSystem")._NewEnum
While colSettings[strCSItem]
{
MsgBox % "AdminPasswordStatus: " . strCSItem.AdminPasswordStatus
  . "`nAutomaticResetBootOption: " . strCSItem.AutomaticResetBootOption
  . "`nAutomaticResetCapability: " . strCSItem.AutomaticResetCapability
  . "`nBootROMSupported: " . strCSItem.BootROMSupported
  . "`nBootupState: " . strCSItem.BootupState
  . "`nCaption: " . strCSItem.Caption
  . "`nChassisBootupState: " . strCSItem.ChassisBootupState
  . "`nCurrentTimeZone: " . strCSItem.CurrentTimeZone
  . "`nDaylightInEffect: " . strCSItem.DaylightInEffect
  . "`nDescription: " . strCSItem.Description
  . "`nDomain: " . strCSItem.Domain
  . "`nDomainRole: " . strCSItem.DomainRole
  . "`nEnableDaylightSavingsTime: " . strCSItem.EnableDaylightSavingsTime
  . "`nFrontPanelResetStatus: " . strCSItem.FrontPanelResetStatus
  . "`nInfraredSupported: " . strCSItem.InfraredSupported
  . "`nKeyboardPasswordStatus: " . strCSItem.KeyboardPasswordStatus
  . "`nManufacturer: " . strCSItem.Manufacturer
  . "`nModel: " . strCSItem.Model
  . "`nName: " . strCSItem.Name
  . "`nNetworkServerModeEnabled: " . strCSItem.NetworkServerModeEnabled
  . "`nNumberOfLogicalProcessors: " . strCSItem.NumberOfLogicalProcessors
  . "`nNumberOfProcessors: " . strCSItem.NumberOfProcessors
  . "`nOEMStringArray: " . strCSItem.OEMStringArray
  . "`nPartOfDomain: " . strCSItem.PartOfDomain
  . "`nPauseAfterReset: " . strCSItem.PauseAfterReset
  . "`nPowerOnPasswordStatus: " . strCSItem.PowerOnPasswordStatus
  . "`nPowerState: " . strCSItem.PowerState
  . "`nPowerSupplyState: " . strCSItem.PowerSupplyState
  . "`nPrimaryOwnerContact: " . strCSItem.PrimaryOwnerContact
  . "`nPrimaryOwnerName: " . strCSItem.PrimaryOwnerName
  . "`nResetCapability: " . strCSItem.ResetCapability
  . "`nResetCount: " . strCSItem.ResetCount
  . "`nResetLimit: " . strCSItem.ResetLimit
  . "`nRoles: " . strCSItem.Roles
  . "`nStatus: " . strCSItem.Status
  . "`nSupportContactDescription: " . strCSItem.SupportContactDescription
  . "`nSystemStartupDelay: " . strCSItem.SystemStartupDelay
  . "`nSystemStartupOptions: " . strCSItem.SystemStartupOptions
  . "`nSystemStartupSetting: " . strCSItem.SystemStartupSetting
  . "`nSystemType: " . strCSItem.SystemType
  . "`nThermalState: " . strCSItem.ThermalState
  . "`nUserName: " . strCSItem.UserName
  . "`nWakeUpType: " . strCSItem.WakeUpType
  . "`nWorkgroup: " . strCSItem.Workgroup
} 


jNizM
  • Members
  • 928 posts
  • Last active: Jul 26 2017 09:19 AM
  • Joined: 01 Aug 2012
more wmi ex(s)ampels: http://www.activexpe...in/scripts/wmi/
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703)
My GitHub Profile | Donations are appreciated if I could help you

V1P3R
  • Members
  • 28 posts
  • Last active: Oct 17 2014 07:43 AM
  • Joined: 26 Sep 2006

Just a suggestion/idea for frequent WMI users:

 

Wouldn't the whole process be a whole lot more easier to read, understand and get into by just defining a simple function like:

WMI(WQLQuery)
{
    global colItems
    colItems:=ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\" . A_ComputerName . "\root\cimv2").ExecQuery(WQLQuery)._NewEnum
}

beforehand?

Afterwards, all you have to do is go:

WMI("Select * from Win32_ComputerSystem")
while,colItems[item]
{
    Manufacturer:=item.Manufacturer
    Model:=item.Model
    UserName:=item.UserName
}