Jump to content
Sign in to follow this  
ghoomp

BgInfo WMI classes in query

Recommended Posts

ghoomp

Hi all,

 
Can someone help me with the BgInfo? I am deploying an image for users but I would like to add a BgInfo in the image.
 
I already fixed for the IP address and MAC address but I have a problem with the Network Type and Free Space.
 
For the network type it shows me 3 types -> Ethernet, Ethernet 2 and Local Area Connection. I would like that it shows me only one active connection with. Like connected with wifi or network cable.
 
This is the query that I have -> 
SELECT NetConnectionID FROM Win32_NetworkAdapter where NETEnabled = 'True'
 
For the free space it shows me the local drives and the network drives. I want a query only for the C: drive in Gigabyte.
 
SELECT FreeMegabytes FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk WHERE Name='C:'
 
It shows me for example 3000, there is no description in Mb.
 
If someone can sort it out for me I would be really thankfull.
 
Thanks for your help guys. Smile

Share this post


Link to post
Share on other sites
spudw2k
UEZ

Does this work for you?

 

Global Const $oErrorHandler = ObjEvent("AutoIt.Error", "ObjErrorHandler")

Global $aNetInfo = _WMI_GetInfoFromActiveNetworkCard()
Global $fCDriveFreeSpace = _WMI_GetCDriveFreeSpace()

MsgBox(0, "Test", "Adapter:" & @TAB & $aNetInfo[0] & @CRLF & _
                  "MAC:" & @TAB & $aNetInfo[1] & @CRLF & _
                  "IP:" & @TAB & $aNetInfo[2] & @CRLF & _
                  "Subnet:" & @TAB & $aNetInfo[3] & @CRLF & _
                  "Gateway:" & @TAB & $aNetInfo[4] & @CRLF & @CRLF & _
                  "Free space on C drive: " & $fCDriveFreeSpace & " GB")

Func _WMI_GetInfoFromActiveNetworkCard($sHost = @ComputerName)
    Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sHost & "\root\cimv2")
    If @error Then Return SetError(1, 0, 0)
    Local $iInterfaceIndex, $objItem, $colItems2, $objItem2
    Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_IP4RouteTable WHERE Destination='0.0.0.0'", "WQL", 0x30)
    If IsObj($colItems) Then
        Local $aActiveNetworkAdapter[5]
        For $objItem in $colItems
            $colItems2 = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE InterfaceIndex = " & $objItem.InterfaceIndex, "WQL", 0x30)
            For $objItem2 in $colItems2
                $aActiveNetworkAdapter[0] = $objItem2.Description
                $aActiveNetworkAdapter[1] = $objItem2.MACAddress
                $aActiveNetworkAdapter[2] = $objItem2.IPAddress[0]
                $aActiveNetworkAdapter[3] = $objItem2.IPSubnet[0]
                $aActiveNetworkAdapter[4] = $objItem2.DefaultIPGateway[0]
                Return $aActiveNetworkAdapter
            Next
        Next
    Else
        Return SetError(2, 0, 0)
    EndIf
EndFunc


Func _WMI_GetCDriveFreeSpace($sHost = @ComputerName)
    Local $objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $sHost & "\root\cimv2")
    If @error Then Return SetError(1, 0, 0)
    Local $colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_PerfFormattedData_PerfDisk_LogicalDisk WHERE Name = 'C:'", "WQL", 0x30), $objItem
    If IsObj($colItems) Then
        For $objItem in $colItems
            Return Round($objItem.FreeMegabytes / 1024, 2)
        Next
    Else
        Return SetError(2, 0, 0)
    EndIf
EndFunc

Func ObjErrorHandler()
    ConsoleWrite(   "A COM Error has occured!" & @CRLF  & @CRLF & _
                                "err.description is: "    & @TAB & $oErrorHandler.description    & @CRLF & _
                                "err.windescription:"     & @TAB & $oErrorHandler & @CRLF & _
                                "err.number is: "         & @TAB & Hex($oErrorHandler.number, 8)  & @CRLF & _
                                "err.lastdllerror is: "   & @TAB & $oErrorHandler.lastdllerror   & @CRLF & _
                                "err.scriptline is: "     & @TAB & $oErrorHandler.scriptline     & @CRLF & _
                                "err.source is: "         & @TAB & $oErrorHandler.source         & @CRLF & _
                                "err.helpfile is: "       & @TAB & $oErrorHandler.helpfile       & @CRLF & _
                                "err.helpcontext is: "    & @TAB & $oErrorHandler.helpcontext & @CRLF _
                            )
EndFunc

 

Edited by UEZ
Changed function name

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
ghoomp

Hi UEZ, thanks for your feedback but when I am running the script it says Line 1 and char 8 gives a syntax error. Code 800A03EA

I am also not so familiar with VB script :-(

Share this post


Link to post
Share on other sites
UEZ

Which operating system are you using? It works properly on my Win 8.1 notebook.

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
UEZ

Anybody else with a problem running the code from above?

@ghoomp: this is not a VB Script! You have to run it either in SciTE or compile and run it.

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×