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
[Netzwerkkarte]

Liest Netzwerkkarte, IP-Adresse, Subnetzmaske, Standardgateway, DNS-Server, MAC-Adresse und DHCP aus
objWMIService := ComObjGet("winmgmts:{impersonationLevel = impersonate}!\\.\root\cimv2")
colItems := objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")._NewEnum
while colItems[objItem]
{
    if objItem.IPAddress[0] = A_IPAddress1
    {
        MsgBox, % "Beschreibung:`t`t" objItem.Description[0] "`n"
                . "IPv4-Adresse:`t`t" objItem.IPAddress[0] "`n"
                . "IPv4-Subnetzmaske:`t`t" objItem.IPSubnet[0] "`n"
                . "IPv4-Standardgateway:`t" objItem.DefaultIPGateway[0] "`n"
                . "IPv4-DNS-Server:`t`t" objItem.DNSServerSearchOrder[0] "`n"
                . "Physikalische Adresse:`t" objItem.MACAddress "`n"
                . "DHCP-aktiviert:`t`t" (objItem.DHCPEnabled[0] ? "Nein" : "Ja") "`n"
    }
}
[Function] _IPAddress(IPA)
MsgBox, % "Beschreibung:`t`t" _IPAddress(1) "`n"
        . "IPv4-Adresse:`t`t" _IPAddress(2) "`n"
        . "IPv4-Subnetzmaske:`t`t" _IPAddress(3) "`n"
        . "IPv4-Standardgateway:`t" _IPAddress(4) "`n"
        . "IPv4-DNS-Server:`t`t" _IPAddress(5) "`n"
        . "Physikalische Adresse:`t" _IPAddress(6) "`n"
        . "DHCP-aktiviert:`t`t" _IPAddress(7) "`n" 

_IPAddress(IPA = 1)
{
    objWMIService := ComObjGet("winmgmts:{impersonationLevel = impersonate}!\\.\root\cimv2")
    colItems := objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")._NewEnum
    while colItems[objItem]
    {
        if objItem.IPAddress[0] = A_IPAddress1
        {
            return, % (IPA = "1") ? objItem.Description[0]
                    : (IPA = "2") ? objItem.IPAddress[0]
                    : (IPA = "3") ? objItem.IPSubnet[0]
                    : (IPA = "4") ? objItem.DefaultIPGateway[0]
                    : (IPA = "5") ? objItem.DNSServerSearchOrder[0]
                    : (IPA = "6") ? objItem.MACAddress
                    : (IPA = "7") ? objItem.DHCPEnabled[0] ? "Nein" : "Ja"
                    : "FAIL"
        }
    }
}

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

Kibo
  • Members
  • 36 posts
  • Last active: Aug 09 2015 07:56 PM
  • Joined: 14 Mar 2012

Vielen Dank dafür!



jNizM
  • Members
  • 928 posts
  • Last active: Jan 12 2018 09:23 AM
  • Joined: 01 Aug 2012
Gern =)
Übringends findest du hier eine überarbeitete Version von den WMI-Snippets

Für das eine oder andere gibt es auch DllCall's, die wesentlich schneller/effizienter laufen als WMI-Abfragen:
WinApi, DllCalls & AHK
[AHK] 1.1.27.04 x64 Unicode | [WIN] 10 Pro (Version 1709)
My GitHub Profile | Donations are appreciated if I could help you