AHK - WMI - Snippets

Post your working scripts, libraries and tools
User avatar
jNizM
Posts: 2290
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

AHK - WMI - Snippets

01 Oct 2013, 04:51

AHK - WMI - Snippets

> Memory (Total, Free & Used)
> MAC-Address
> HDD Temperature (°C)
> HDD Health (O.K. / Critical)
> Processor Architecture (x86 / x64)
> Drives
> Network Card (Network Card, IPAddress, IPSubnet, DefaultIPGateway, DNS-Server, MAC-Address and DHCP)
> AntiVirus Status (Requirement: Windows Vista+)
> AntiSpyware Status (Requirement: Windows Vista+)
> Firewall Status (Requirement: Windows Vista+)
> ...tba

Useful Links
> Microsoft WMI Code Creator
> WMI Übersicht und Beispiele
Last edited by jNizM on 06 Feb 2014, 02:11, edited 4 times in total.
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2290
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: AHK - WMI - Snippets

01 Oct 2013, 04:52

[Memory]

Code: [Select all] [Download] GeSHi © Codebox Plus

for objItem in ComObjGet("winmgmts:\\.\root\CIMV2").ExecQuery("SELECT * FROM Win32_OperatingSystem")
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()

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by jNizM on 06 Feb 2014, 02:17, edited 7 times in total.
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2290
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: AHK - WMI - Snippets

01 Oct 2013, 04:54

[MAC-Address]

Code: [Select all] [Download] GeSHi © Codebox Plus

for objItem in ComObjGet("winmgmts:\\.\root\CIMV2").ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE")
MsgBox, % "MAC-Address:`t" objItem.MACAddress
Last edited by jNizM on 06 Feb 2014, 02:17, edited 4 times in total.
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2290
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: AHK - WMI - Snippets

01 Oct 2013, 04:56

[HDD Temperature]

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



[Function] WMI_HDD_TEMP()

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by jNizM on 06 Feb 2014, 02:21, edited 3 times in total.
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2290
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: AHK - WMI - Snippets

01 Oct 2013, 04:57

[HDD Health]

Code: [Select all] [Download] GeSHi © Codebox Plus

for objItem in ComObjGet("winmgmts:\\.\root\WMI").ExecQuery("SELECT * FROM MSStorageDriver_FailurePredictStatus")
MsgBox, % (objItem.PredictFailure = "0") ? "HDD-Health is:`tO.K."
: (objItem.PredictFailure = "1") ? "HDD-Health is:`tCritical"
: "FAIL"


[Function] WMI_HDD_HEALTH()

Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox, % "HDD-Health is:`t" WMI_HDD_HEALTH()

WMI_HDD_HEALTH()
{
for objItem in ComObjGet("winmgmts:\\.\root\WMI").ExecQuery("SELECT * FROM MSStorageDriver_FailurePredictStatus")
return, % (objItem.PredictFailure = "0") ? "O.K." : (objItem.PredictFailure = "1") ? "Critical" : "FAIL"
}
Last edited by jNizM on 06 Feb 2014, 02:43, edited 2 times in total.
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2290
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: AHK - WMI - Snippets

01 Oct 2013, 05:01

[Processor Architecture]

Code: [Select all] [Download] GeSHi © Codebox Plus

for objItem in ComObjGet("winmgmts:\\.\root\CIMV2").ExecQuery("SELECT * FROM Win32_Processor")
MsgBox, % (objItem.Architecture = "0") ? "x86"
: (objItem.Architecture = "9") ? "x64"
: "other Architecture"


[Function] Architecture()

Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox, % "Architecture is: " . Architecture()

Architecture()
{
for objItem in ComObjGet("winmgmts:\\.\root\CIMV2").ExecQuery("SELECT * FROM Win32_Processor")
return, % (objItem.Architecture = "0") ? "x86" : (objItem.Architecture = "9") ? "x64" : "other Architecture"
}
Last edited by jNizM on 06 Feb 2014, 03:00, edited 2 times in total.
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2290
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: AHK - WMI - Snippets

01 Oct 2013, 05:03

[Drives]

Code: [Select all] [Download] GeSHi © Codebox Plus

for objItem in ComObjGet("winmgmts:\\.\root\CIMV2").ExecQuery("SELECT * FROM Win32_LogicalDisk")
MsgBox, % "Drives:`t`t" . objItem.Caption . "`n"
. "File System:`t" . objItem.FileSystem . "`n"
. "Drive Size:`t`t" . Round((objItem.Size / (1024 ** 3)), 2) . " GB`n"
. "Free Space:`t" . Round((objItem.FreeSpace / (1024 ** 3)), 2) . " GB`n"
. "Free Space:`t" . Round((100 * (objItem.FreeSpace / objItem.Size)), 2) . " %"
Last edited by jNizM on 06 Feb 2014, 03:01, edited 2 times in total.
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2290
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: AHK - WMI - Snippets

01 Oct 2013, 05:05

[Network Card]

Gives info about: Network Card, IPAddress, IPSubnet, DefaultIPGateway, DNS-Server, MAC-Address and DHCP

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



[Function] IPAddress(IPA)

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by jNizM on 06 Feb 2014, 03:24, edited 5 times in total.
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2290
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: AHK - WMI - Snippets

01 Oct 2013, 05:09

[AntiVirus Status]

Requirement: Windows Vista+

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by jNizM on 06 Feb 2014, 03:28, edited 1 time in total.
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2290
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: AHK - WMI - Snippets

01 Oct 2013, 05:10

[AntiSpyware Status]

Requirement: Windows Vista+

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by jNizM on 06 Feb 2014, 03:28, edited 1 time in total.
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jNizM
Posts: 2290
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: AHK - WMI - Snippets

01 Oct 2013, 05:11

[Firewall Status]

Requirement: Windows Vista+

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
daorc
Posts: 8
Joined: 27 Mar 2015, 10:51

Re: AHK - WMI - Snippets

21 Sep 2016, 01:28

These are brilliant. Thank you!!
arcticir
Posts: 471
Joined: 17 Nov 2013, 11:32

Re: AHK - WMI - Snippets

26 Sep 2016, 07:30

Hi, there is a problem, how to get the amount of memory used by AHK itself? :)
User avatar
jNizM
Posts: 2290
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: AHK - WMI - Snippets

26 Sep 2016, 08:07

hey...
something like this (winapi - not wmi)

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
arcticir
Posts: 471
Joined: 17 Nov 2013, 11:32

Re: AHK - WMI - Snippets

26 Sep 2016, 08:40

Thank you. This is the V2 :D

Image

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
Tomer
Posts: 202
Joined: 21 Aug 2016, 05:11

Re: AHK - WMI - Snippets

26 Sep 2016, 14:41

Thanks!
Drugoy
Posts: 48
Joined: 11 Jun 2016, 07:37
GitHub: Drugoy

Re: AHK - WMI - Snippets

13 Oct 2016, 19:17

jNizM wrote:[Network Card]

Gives info about: Network Card, IPAddress, IPSubnet, DefaultIPGateway, DNS-Server, MAC-Address and DHCP

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


Poor usage of the first ternary operator results into bad output.
User avatar
jNizM
Posts: 2290
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: AHK - WMI - Snippets

14 Oct 2016, 00:42

Drugoy wrote:Poor usage of the first ternary operator results into bad output.

Haha I know :D (was one of my first wmi - never changed them)

For this I use the WinAPI directly to get the data...
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
Drugoy
Posts: 48
Joined: 11 Jun 2016, 07:37
GitHub: Drugoy

Re: AHK - WMI - Snippets

16 Oct 2016, 15:14

Could you show how you do that using WinAPI?
User avatar
jNizM
Posts: 2290
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: AHK - WMI - Snippets

17 Oct 2016, 01:24

Here are some examples: https://github.com/jNizM/AHK_Scripts/tr ... er/src/net
Will add more as soon as I cleanuped my code
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you

Return to “Scripts and Functions”

Who is online

Users browsing this forum: vsub and 16 guests