Jump to content

wmic to GUICtrlCreateInput


Doxie
 Share

Recommended Posts

Hi,

I'm going crazy... I have not worked with AutoIT for many many years, and my brain is about to explode.
I'm trying to get the result from a wmic displayed in GUICtrlCreateInput, but i dont understand how to do it.

All my commands works fine in bat file, but i fail to understand how i can get the result in my GUI window.

For example:

wmic cpu loadpercentage
wmic ComputerSystem get TotalPhysicalMemory
wmic OS get FreePhysicalMemory
wmic OS get LastBootUpTime

All ideas are welcome, i'm not requesting anyone to write the code for me, just point me in the right direction.

Thanks in advance

Were ever i lay my script is my home...

Link to comment
Share on other sites

Hello. You can use Run+StderrRead or use ObjGet. Do a forum search you'll find a lot of examples.

 

Saludos

Link to comment
Share on other sites

For FreePhysicalMemory : 

#include <Constants.au3>

Opt ("MustDeclareVars", 1)

_example ()

Func _example ()
Local $List, $Rep

    Local $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
    Local $colItems = $objWMIService.ExecQuery('SELECT FreePhysicalMemory FROM Win32_OperatingSystem')
    If not IsObj($colItems) Then Exit MsgBox (0,"","Not an object")
    If not $colItems.count then Exit MsgBox (0,"","Not found")
    For $sItem In $colItems
        $List = ""
        For $sProperty In $sItem.Properties_
            $List &= $sProperty.Name & ": " & $sProperty.Value & @CRLF
        Next
        $Rep = MsgBox ($MB_OKCANCEL,"",$List)
        if $Rep = $IDCANCEL then ExitLoop
    Next

EndFunc

 

Link to comment
Share on other sites

Thanks a lot for all examples and feedback.

However, i decided to go for a different solution, that its working "ok" :)

;$Text = systeminfo
$Text = FileRead("testar2.txt")
$ReportArrayDATA = StringRegExp($Text,"(?i)(?s)OS Name: (.*?)"&@CRLF&".*?Original Install Date: (.*?)"&@CRLF&".*?System Boot Time: (.*?)"&@CRLF&".*?System Model: (.*?)"&@CRLF&".*?BIOS Version: (.*?)"&@CRLF&".*?Total Physical Memory: (.*?)"&@CRLF&".*?Available Physical Memory: (.*?)"&@CRLF,1)

Not working
&@CRLF&".*?Hotfix(s): (.*?)"

As you can see i have a file called testar2.txt that is the output of the command systeminfo, but now i have some questions. :)

  1. Is there a maximum of Array's i can use, if i add anymore then in the example above, i get an error message.
  2. Could the error message be because in the last array i'm trying to get Hotfix(s): (maybe its the (s) that is messing it up.
  3. The output is GUICtrlCreateInput("" & $ReportArrayDATA[0] etc, but the output is not forced to the left in the Input box, a lot of empty spaces. (but not for all results)
  4. Last but not least, is it possible to use the systeminfo command directly, instead of using it from a file, somehow load it into memory as long as the script is running.

Thanks in advance

Were ever i lay my script is my home...

Link to comment
Share on other sites

3 hours ago, Doxie said:

However, i decided to go for a different solution, that its working "ok" 

I dont understand how a FileRead (...) solve your problem followed by regexp but I must be lost !  :bike:

Link to comment
Share on other sites

38 minutes ago, FrancescoDiMuro said:

@Nine

He's probably redirecting the output of the wmic query to a file, and he extracts what he needs with a RegEx :)

I'm redirecting the output of the command systeminfo to a file, and then use readfile in combonation with ReportArray.

But i would love to skip the file part, and just load systeminfo into the memory, if that is even possible.

Were ever i lay my script is my home...

Link to comment
Share on other sites

3 minutes ago, FrancescoDiMuro said:

@Doxie
You have been answered here, here, and here :)

Ok, so based on the answer you recommend me to continue with wmic and skip "systeminfo"?

Pro's with systeminfo is that i got most of the information in correct format, ex time and size.
Con's is that i dont see CPU load, which force me to use wmic at some point anyway.
I also need to output it to a file first, and use fileRead, which is one extra step.

Pro's with wmic is that i can get everything needed
Con's its more complicated :) and i need to adjust a lot of the result.
 

I can read, and got some sence of idea how things work, but when it gets to complicated (not nessesary complicated for you guys) 
i find it hard to get a good end result. I dont enjoy to ask to most simple questions all the time, why i said point me in the right direction.

With that in my mind, would you still recommend me to dive deeper into wmic and continue that path? :)

 

Were ever i lay my script is my home...

Link to comment
Share on other sites

@Doxie
You use wmic from Command Prompt; you have been suggested to use WMI Object which you can use from AutoIt, without going through Command Prompt.
From there, you can query the WMI Object to obtain what you're looking for.
In this way, you don't need to use output files, but directly manage the result of your query in the script.

Now, it's your choice :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

4 hours ago, Doxie said:

I can read, and got some sence of idea how things work, but when it gets to complicated (not nessesary complicated for you guys) 
i find it hard to get a good end result. I dont enjoy to ask to most simple questions all the time, why i said point me in the right direction.

It is really not that complicated.  My script is a bit too much because it is a generic tool I made for reading any class of object.  It can be simplified like :

Local $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2")
Local $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_OperatingSystem')
If not IsObj($colItems) Then Exit MsgBox (0,"","Not an object")
For $sItem In $colItems
  Local $FreePhysicalMemory = $sItem.FreePhysicalMemory
  Local $LastBootUpTime = $sItem.LastBootUpTime
Next

TotalPhysicalMemory comes from Win32_PhysicalMemory and loadpercentage comes from Win32_Processor class.  You can get the list of all the properties in msdn :

https://docs.microsoft.com/en-us/windows/desktop/cimwin32prov/win32-processor

I believe you will get a sense of satisfaction by using the right tool for your need. If you take a moment to read this documentation, I think you will agree with us.

But if you persist in using wmic, you can get the information into your script by reading directly from StdoutRead ()

Happy scripting.

ps. don't worry about asking question, most ppl here enjoy helping out :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...