Jump to content

Preventing delay on startup when calling for information.


Recommended Posts

I created this script to display information about the Windows machine it is ran on. Upon loading the program, there is a delay while it gathers the information delaying the GUI. Is there a way for the program to load the information separately showing the GUI while it is loading the information? It's not a huge deal, but I'd rather fix it if I can.

 

#RequireAdmin
#include <GUIConstantsEx.au3>
#include <AutoItConstants.au3>
#include <EditConstants.au3>

Example()

 Func ComputerInfo()
   ;Get Serial Number
   $wmiSN = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $wmiSN = (Get-WmiObject win32_bios).SerialNumber; $wmiSN", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
   ProcessWaitClose($wmiSN)
   Global $wmiSN2 = StdoutRead($wmiSN)
   ;Get Vendor
   $wmiVENDOR = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $wmiVENDOR = (Get-WMIObject Win32_ComputerSystemProduct).Vendor; $wmiVENDOR", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
   ProcessWaitClose($wmiVENDOR)
   Global $wmiVENDOR2 = StdoutRead($wmiVENDOR)
   ;Get Model
   $cimMODEL = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $cimMODEL = (Get-CimInstance Win32_ComputerSystem).Model; $cimMODEL", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
   ProcessWaitClose($cimMODEL)
   Global $cimMODEL2 = StdoutRead($cimMODEL)
   ;Get Caption
   $cimCAPTION = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $cimCAPTION = (Get-CimInstance Win32_OperatingSystem).Caption; $cimCAPTION", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
   ProcessWaitClose($cimCAPTION)
   Global $cimCAPTION2 = StdoutRead($cimCAPTION)
   ;Get Arch
   $cimARCH = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $cimARCH = (Get-CimInstance Win32_OperatingSystem).OSArchitecture; $cimARCH", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
   ProcessWaitClose($cimARCH)
   Global $cimARCH2 = StdoutRead($cimARCH)
   ;Get Version
   $cimVERSION = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $cimVERSION = (Get-CimInstance Win32_OperatingSystem).Version; $cimVERSION", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
   ProcessWaitClose($cimVERSION)
   Global $cimVERSION2 = StdoutRead($cimVERSION)
 EndFunc

Func Example()
    ; Create a GUI with various controls.
    Local $hGUI = GUICreate("Example")
    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)

    Call ("ComputerInfo")
    GUICtrlCreateGraphic(0,0,400,55, 0)
    GUICtrlSetBkColor(-1, 0x660000)
    GUICtrlCreateGraphic(0,2,400,2, 0)
    GUICtrlSetBkColor(-1, 0xF4AA00)
    GUICtrlCreateInput("OS Version: " & $cimCAPTION2 & " (" & $cimARCH2 & "), " & $cimVERSION2, 5, 5, 390, 15, BitOR($ES_READONLY, $ES_LEFT), 0)
    GUICtrlSetBkColor(-1, 0x660000)
    GUICtrlSetColor (-1, 0xFFFFFF)
    GUICtrlSetFont(-1, 8.5, 800, 0)
    Opt("GUICoordMode", 0)
    GUICtrlCreateInput("Model:      " & $cimMODEL2 & ", " & $wmiVENDOR2, 0, 15, 390, 15, BitOR($ES_READONLY, $ES_LEFT), 0)
    GUICtrlSetBkColor(-1, 0x660000)
    GUICtrlSetColor (-1, 0xFFFFFF)
    GUICtrlSetFont(-1, 8.5, 800, 0)
    GUICtrlCreateInput("Serial Number:  " & $wmiSN2, 0, 15, 390, 15, BitOR($ES_READONLY, $ES_LEFT), 0)
    GUICtrlSetBkColor(-1, 0x660000)
    GUICtrlSetColor (-1, 0xFFFFFF)
    GUICtrlSetFont(-1, 8.5, 800, 0)
    Opt("GUICoordMode", 1)
    GUICtrlCreateGraphic(0,51,400,2, 0)
    GUICtrlSetBkColor(-1, 0xF4AA00)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                ExitLoop

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

 

Edited by ReconX
Link to comment
Share on other sites

 

..or: 

#RequireAdmin
#include <GUIConstantsEx.au3>
#include <AutoItConstants.au3>
#include <EditConstants.au3>

Example()

 Func ComputerInfo()
   ;Get Serial Number
   $wmiSN = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $wmiSN = (Get-WmiObject win32_bios).SerialNumber; $wmiSN", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
   ;Get Vendor
   $wmiVENDOR = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $wmiVENDOR = (Get-WMIObject Win32_ComputerSystemProduct).Vendor; $wmiVENDOR", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
   ;Get Model
   $cimMODEL = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $cimMODEL = (Get-CimInstance Win32_ComputerSystem).Model; $cimMODEL", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
   ;Get Caption
   $cimCAPTION = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $cimCAPTION = (Get-CimInstance Win32_OperatingSystem).Caption; $cimCAPTION", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
   ;Get Arch
   $cimARCH = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $cimARCH = (Get-CimInstance Win32_OperatingSystem).OSArchitecture; $cimARCH", @ScriptDir, @SW_HIDE, $STDERR_MERGED)
   ;Get Version
   $cimVERSION = Run("C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command $cimVERSION = (Get-CimInstance Win32_OperatingSystem).Version; $cimVERSION", @ScriptDir, @SW_HIDE, $STDERR_MERGED)

;;; tha hack

   ProcessWaitClose($wmiSN)
   Global $wmiSN2 = StdoutRead($wmiSN)

   ProcessWaitClose($wmiVENDOR)
   Global $wmiVENDOR2 = StdoutRead($wmiVENDOR)

   ProcessWaitClose($cimMODEL)
   Global $cimMODEL2 = StdoutRead($cimMODEL)

   ProcessWaitClose($cimCAPTION)
   Global $cimCAPTION2 = StdoutRead($cimCAPTION)

   ProcessWaitClose($cimARCH)
   Global $cimARCH2 = StdoutRead($cimARCH)

   ProcessWaitClose($cimVERSION)
   Global $cimVERSION2 = StdoutRead($cimVERSION)

 EndFunc

Func Example()
    ; Create a GUI with various controls.
    Local $hTimer = TimerInit(), $hGUI = GUICreate("Example")
    Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25)

    GUICtrlCreateGraphic(0,0,400,55, 0)
    GUICtrlSetBkColor(-1, 0x660000)
    GUICtrlCreateGraphic(0,2,400,2, 0)
    GUICtrlSetBkColor(-1, 0xF4AA00)
    GUICtrlCreateGraphic(0,51,400,2, 0)
    GUICtrlSetBkColor(-1, 0xF4AA00)

    ; Display the GUI.
    GUISetState(@SW_SHOW, $hGUI)

    ComputerInfo()

    GUICtrlCreateInput("OS Version: " & $cimCAPTION2 & " (" & $cimARCH2 & "), " & $cimVERSION2, 5, 5, 390, 15, BitOR($ES_READONLY, $ES_LEFT), 0)
    GUICtrlSetBkColor(-1, 0x660000)
    GUICtrlSetColor (-1, 0xFFFFFF)
    GUICtrlSetFont(-1, 8.5, 800, 0)
    Opt("GUICoordMode", 0)
    GUICtrlCreateInput("Model:      " & $cimMODEL2 & ", " & $wmiVENDOR2, 0, 15, 390, 15, BitOR($ES_READONLY, $ES_LEFT), 0)
    GUICtrlSetBkColor(-1, 0x660000)
    GUICtrlSetColor (-1, 0xFFFFFF)
    GUICtrlSetFont(-1, 8.5, 800, 0)
    GUICtrlCreateInput("Serial Number:  " & $wmiSN2, 0, 15, 390, 15, BitOR($ES_READONLY, $ES_LEFT), 0)
    GUICtrlSetBkColor(-1, 0x660000)
    GUICtrlSetColor (-1, 0xFFFFFF)
    GUICtrlSetFont(-1, 8.5, 800, 0)
    Opt("GUICoordMode", 1)

    GUICtrlCreateInput("Time to load: " & Round(TimerDiff($hTimer)) & " ms.", 10, 115, 390, 15, BitOR($ES_READONLY, $ES_LEFT), 0)


    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idOK
                ExitLoop

        EndSwitch
    WEnd

    ; Delete the previous GUI and all controls.
    GUIDelete($hGUI)
EndFunc   ;==>Example

your code takes 5 sec., mine 1 sec. , so I guess 1 sec is good enough. Or load the gui first and fill the controls as data come in :)

Edited by argumentum
solved =)

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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...