Jump to content

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

AHK-WMI-Snippets


  • Please log in to reply
17 replies to this topic
jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
AHK-WMI-Snippets

!!! Support hier abgelaufen !!!
Neue Version bitte hier einsehen --> AHK - WMI - Snippets <--

Edited by jNizM, 13 May 2014 - 06:39 AM.

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
[Arbeitsspeicher auslesen]

objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
colItems := objWMIService.ExecQuery("Select * from Win32_OperatingSystem")._NewEnum
while colItems[objItem]
{
    MsgBox, % "Total Memory:`t" . Round((objItem.TotalVisibleMemorySize / 1024), 2) . " MB`n"
            . "Free Memory:`t" . Round((objItem.FreePhysicalMemory / 1024), 2) . " MB`n"
            . "Used Memory:`t" . Round(((objItem.TotalVisibleMemorySize - objItem.FreePhysicalMemory) / 1024), 2) . " MB"
}

[Function] WMI_MEMORY()
MsgBox, % "Total Memory:`t" . Round( WMI_MEMORY( 1 ), 2) . " MB`n"
        . "Free Memory:`t" . Round( WMI_MEMORY( 2 ), 2) . " MB`n"
        . "Used Memory:`t" . Round( WMI_MEMORY( 3 ), 2) . " MB`n"

WMI_MEMORY( mem = 1 )
{
    objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    colItems := objWMIService.ExecQuery("Select * from Win32_OperatingSystem")._NewEnum
    while colItems[objItem]
    {
        if ( mem = "1" )
            return, objItem.TotalVisibleMemorySize / 1024
        if ( mem = "2" )
            return, objItem.FreePhysicalMemory / 1024
        if ( mem = "3" )
            return, (objItem.TotalVisibleMemorySize - objItem.FreePhysicalMemory) / 1024
    }
}

/* Gekürzte Funktion
WMI_MEMORY(m=1){
    objWMIService:=ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    colItems:=objWMIService.ExecQuery("Select * from Win32_OperatingSystem")._NewEnum
    while colItems[objItem]
        return, % m=1?objItem.TotalVisibleMemorySize/1024:m=2?objItem.FreePhysicalMemory/1024:m=3?(objItem.TotalVisibleMemorySize-objItem.FreePhysicalMemory)/1024:
}
*/

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
[MAC-Adresse auslesen]

objWMIService := ComObjGet("winmgmts:\\.\root\cimv2")
colItems := objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")._NewEnum
while colItems[objItem]
{
    MsgBox, % "MAC-Adresse:`t" . objItem.MACAddress
}

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
[HDD Temperatur auslesen]

objWMIService := ComObjGet("winmgmts:\\.\root\WMI")
colItems := objWMIService.ExecQuery("SELECT * FROM MSStorageDriver_ATAPISmartData")._NewEnum
while colItems[objItem]
{
    Loop, 361
    {
        i := A_Index - 1
        if (objItem.VendorSpecific[i] = "194")
        {
            j := i + 5
            MsgBox, % "HDD-Temp:`t" . objItem.VendorSpecific[j] . " °C"
        }
    }
}

[Function] WMI_HDD_TEMP()
MsgBox, % "HDD-Temp:   " . WMI_HDD_TEMP() . " °C"

WMI_HDD_TEMP()
{
    objWMIService := ComObjGet("winmgmts:\\.\root\WMI")
    colItems := objWMIService.ExecQuery("SELECT * FROM MSStorageDriver_ATAPISmartData")._NewEnum
    while colItems[objItem]
    {
        loop, 361
        {
            i := A_Index - 1
            if (objItem.VendorSpecific[i] = "194")
            {
                j := i + 5
                return, objItem.VendorSpecific[j]
            }
        }
    }
}

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
[Akku Restladung]

objWMIService := ComObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
colItems := objWMIService.ExecQuery("SELECT * FROM Win32_Battery")._NewEnum
while colItems[objItem]
{
    MsgBox, % "Geschätzte Restladung:`t" . objItem.EstimatedChargeRemaining . " %"
}

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
[Prozessorarchitektur auslesen]

objWMIService := ComObjGet("winmgmts:\\.\root\cimv2")
colItems := objWMIService.ExecQuery("SELECT * FROM Win32_Processor")._NewEnum
while colItems[objItem]
{
    if objItem.Architecture = 0
        MsgBox, % "Prozessorarchitektur:`t x86"
    else if objItem.Architecture = 1
        MsgBox, % "Prozessorarchitektur:`t MIPS"
    else if objItem.Architecture = 2
        MsgBox, % "Prozessorarchitektur:`t Alpha"
    else if objItem.Architecture = 3
        MsgBox, % "Prozessorarchitektur:`t PowerPC"
    else if objItem.Architecture = 6
        MsgBox, % "Prozessorarchitektur:`t Itanium"
    else if objItem.Architecture = 9
        MsgBox, % "Prozessorarchitektur:`t x64"
}

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
[Grafikkarte auslesen]

objWMIService := ComObjGet("winmgmts:\\.\root\cimv2")
colItems := objWMIService.ExecQuery("SELECT * FROM Win32_VideoController")._NewEnum
while colItems[objItem]
{
    MsgBox, % "Grafikkarte: `t" . objItem.Name . "`n"
            . "Video RAM:`t" . Round((objItem.AdapterRAM / (1024 ** 2)), 2) . " MB`n"
            . "Treiber Version:`t" . objItem.DriverVersion . "`n"
}

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
[Soundkarte auslesen]

objWMIService := ComObjGet("winmgmts:\\.\root\cimv2")
colItems := objWMIService.ExecQuery("SELECT * FROM Win32_SoundDevice")._NewEnum
while colItems[objItem]
{
    MsgBox, % "Soundkarte: `t" . objItem.Name . "`n"
            . "Hersteller: `t" . objItem.Manufacturer
}

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
[Laufwerke auslesen]

objWMIService := ComObjGet("winmgmts:\\.\root\cimv2")
colItems := objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDisk")._NewEnum
while colItems[objItem]
{
    MsgBox, % "Laufwerke: `t" . objItem.Caption . "`n"
            . "Dateisystem: `t" . objItem.FileSystem  . "`n"
            . "Laufwerk Größe: `t" . Round((objItem.Size / (1024 ** 3)), 2)  . " GB`n"
            . "Freier Speicher: `t" . Round((objItem.FreeSpace / (1024 ** 3)), 2)  . " GB`n"
            . "Freier Speicher: `t" . Round((100 * (objItem.FreeSpace / objItem.Size)), 2)  . " %"
}

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

Lucky Joe
  • Members
  • 5 posts
  • Last active: Mar 24 2014 09:37 AM
  • Joined: 06 Nov 2012

Hallo jNizM,

 

danke für die tollen WMI-Snippets. Hierzu findet man ergänzend Anregungen unter

http://msdn.microsof...5(v=vs.85).aspx

 

VG - LJ



SAPlayer
  • Members
  • 403 posts
  • Last active: Apr 11 2014 04:45 PM
  • Joined: 06 Nov 2012

Danke, sehr hilfreich ;) Für den RAM benutze ich auch diesen Code, für den Akkustand reicht ein simples DllCall (finde ich persönlich schöner, wenn die Option gegeben ist).

 

Nur eine Frage musst du beantworten:

Was soll

strComputer := "."

bringen? Könnte man nicht einfach

objWMIService := ComObjGet("winmgmts:\\.\root\cimv2")

nutzen?



jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
kann man, ja
ich hab das aber so übernommen weil das in vbs so gebräuchlich ist

ebenfalls gibts ja auch noch zb
strComputer := "atl-dc-01"
usw
[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
Funktionen zu den WMI-Snipptes hinzugefügt (nach und nach)
siehe WMI_MEMORY()

edit: incl gekürzte Funktion
[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
[HDD Health auslesen]

objWMIService := ComObjGet("winmgmts:\\.\root\WMI")
colItems := objWMIService.ExecQuery("SELECT * FROM MSStorageDriver_FailurePredictStatus")._NewEnum
while colItems[objItem]
{
    MsgBox, % (objItem.PredictFailure = "0") ? "HDD-Health is O.K."
            : (objItem.PredictFailure = "1") ? "HDD-Health is Critical"
}

[Function] WMI_HDD_HEALTH()
MsgBox, % "HDD-Health:   " . WMI_HDD_HEALTH()

WMI_HDD_HEALTH()
{
    objWMIService := ComObjGet("winmgmts:\\.\root\WMI")
    colItems := objWMIService.ExecQuery("SELECT * FROM MSStorageDriver_FailurePredictStatus")._NewEnum
    while colItems[objItem]
		return, (objItem.PredictFailure = "0") ? "O.K." : (objItem.PredictFailure = "1") ? "Critical"
}

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you

jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
[AntiVirus Status auslesen]

Voraussetzung: Windows Vista+
objWMIService := ComObjGet("winmgmts:\\localhost\root\SecurityCenter2")
colItems := objWMIService.ExecQuery("Select * from AntiVirusProduct")._NewEnum
while colItems[objItem]
{
    MsgBox, % "AntiVirus:`t`t" . objItem.displayName . "`n"
            . "Guid:`t`t" . objItem.instanceGuid . "`n"
            . "ProductExe:`t" . objItem.pathToSignedProductExe . "`n"
            . "ReportingExe:`t" . objItem.pathToSignedReportingExe . "`n"
            . "RealTimeProtection:`t" . ((SubStr(DecTo(objItem.productState, 16), 3, 2) = 10) ? "Enabled" : "Disabled") "`n"
            . "VirusDefUpdate:`t" . ((SubStr(DecTo(objItem.productState, 16), 5, 2) = 00) ? "Up to Date" : "Out of Date")
}

DecTo( n, to ) {
    hex := "0123456789ABCDEF"
    while ( n > 0 ) {
        rem := mod( n, to )
        n /= to
        y := SubStr( hex, rem + 1, 1 )
        result = %y%%result%
    }
    return, "0" . result
}
==========================================================================
[AntiSpyware Status auslesen]

Voraussetzung: Windows Vista+
objWMIService := ComObjGet("winmgmts:\\localhost\root\SecurityCenter2")
colItems := objWMIService.ExecQuery("Select * from AntiSpywareProduct")._NewEnum
while colItems[objItem]
{
    MsgBox, % "AntiSpyware:`t" . objItem.displayName . "`n"
            . "Guid:`t`t" . objItem.instanceGuid . "`n"
            . "ProductExe:`t" . objItem.pathToSignedProductExe . "`n"
            . "ReportingExe:`t" . objItem.pathToSignedReportingExe . "`n"
            . "RealTimeProtection:`t" . ((SubStr(DecTo(objItem.productState, 16), 3, 2) = 10) ? "Enabled" : "Disabled") "`n"
            . "VirusDefUpdate:`t" . ((SubStr(DecTo(objItem.productState, 16), 5, 2) = 00) ? "Up to Date" : "Out of Date")
}

DecTo( n, to ) {
    hex := "0123456789ABCDEF"
    while ( n > 0 ) {
        rem := mod( n, to )
        n /= to
        y := SubStr( hex, rem + 1, 1 )
        result = %y%%result%
    }
    return, "0" . result
}
==========================================================================
[Firewall Status auslesen]

Voraussetzung: Windows Vista+
objWMIService := ComObjGet("winmgmts:\\localhost\root\SecurityCenter2")
colItems := objWMIService.ExecQuery("Select * from FirewallProduct")._NewEnum
while colItems[objItem]
{
    MsgBox, % "Firewall:`t`t" . objItem.displayName . "`n"
            . "Guid:`t`t" . objItem.instanceGuid . "`n"
            . "ProductExe:`t" . objItem.pathToSignedProductExe . "`n"
            . "ReportingExe:`t" . objItem.pathToSignedReportingExe . "`n"
            . "RealTimeProtection:`t" . ((SubStr(DecTo(objItem.productState, 16), 3, 2) = 10) ? "Enabled" : "Disabled") "`n"
            . "VirusDefUpdate:`t" . ((SubStr(DecTo(objItem.productState, 16), 5, 2) = 00) ? "Up to Date" : "Out of Date")
}

DecTo( n, to ) {
    hex := "0123456789ABCDEF"
    while ( n > 0 ) {
        rem := mod( n, to )
        n /= to
        y := SubStr( hex, rem + 1, 1 )
        result = %y%%result%
    }
    return, "0" . result
}

[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you