Jump to content

Recommended Posts

Posted

$strComputer = InputBox("Computer Name", "")
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2") 
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32Reg_AddRemovePrograms") 

$Message = "Add/Remove Programs for " & $strComputer & @CRLF & "-----------------" & @CRLF

For $objItem in $colItems
    $Message &= "DisplayName: " & $objItem.DisplayName & @CRLF & _
    "InstallDate: " & $objItem.InstallDate & @CRLF & _
    "ProdID     : " & $objItem.ProdID & @CRLF & _
    "Publisher  : " & $objItem.Publisher & @CRLF & _
    "Version    : " & $objItem.Version & @CRLF & @CRLF
Next

MsgBox(64, "Results", $Message)

The above works but the resulting MsgBox is WAY too long. What would I use in place of MsgBox to put the results in a window with a vertical scroll bar?

Support bacteria; it's the only culture most people have.LxP's Learning to Script with AutoIt 3 - Excellent starting placeVolly's Links Page - Links to cool and useful scriptsAutoIt Wrappers - Valuater's AutoIt Wrappers post. Lots of good stuff.Support AutoIt - Make a donation here; I did.[size="2"]#include <Guinness.pint>[/size]

  • Moderators
Posted (edited)

Well this was fun... I also added x and y position as well.

#Include <MsgBox.au3>

#include-once
Global $h_include_msgbox_hwnd = 0
Global $a_include_msgbox[7]
Global $i_include_msgbox_return = "NoValue"
Global $f_include_msgbox = False
Global $f_include_msgbox_wait = False

Func _MsgBox($i_flag, $s_title, $s_text, $i_time = 0, $h_parent = 0, $i_x = -1, $i_y = -1)
    If $i_x = Default Then $i_x = -1
    If $i_y = Default Then $i_y = -1
    
    $a_include_msgbox[0] = $i_flag
    $a_include_msgbox[1] = $s_title
    $a_include_msgbox[2] = $s_text
    $a_include_msgbox[3] = $i_time
    $a_include_msgbox[4] = $h_parent
    $a_include_msgbox[5] = $i_x
    $a_include_msgbox[6] = $i_y
    
    Local $h_mod, $h_timer, $i_ret
    $h_timer = _MsgBox_StartTimer($h_mod, "_MsgBox_Execute", "int", "", 0, 10001, 10)
    While $i_include_msgbox_return = "NoValue"
        Sleep(10)
    WEnd
    _MsgBox_StopTimer($h_mod, $h_timer)
    
    $i_ret = $i_include_msgbox_return
    $i_include_msgbox_return = "NoValue"
    $f_include_msgbox = False
    $f_include_msgbox_wait = False
    $h_include_msgbox_hwnd = 0
    
    Return $i_ret
EndFunc

Func _MsgBox_Execute()
    If Not $f_include_msgbox Then
        $f_include_msgbox = True
        $i_include_msgbox_return = _
            MsgBox($a_include_msgbox[0], _
                $a_include_msgbox[1], _
                $a_include_msgbox[2], _
                $a_include_msgbox[3], _
                $a_include_msgbox[4])
    EndIf
    If $f_include_msgbox Then
        If Not $f_include_msgbox_wait Then
            $f_include_msgbox_wait = True
            $h_include_msgbox_hwnd = WinGetHandle("[TITLE:" & $a_include_msgbox[1] & ";CLASS:#32770]")
            WinMove($h_include_msgbox_hwnd, "", 0, 0, 0, 0)
            Local $h_edit_handle = ControlGetHandle($h_include_msgbox_hwnd, "", "Static2")
            Local $s_text = ControlGetText($h_include_msgbox_hwnd, "", $h_edit_handle)
            If StringLen($s_text) > 30 Then
                Local $a_list = WinGetClassList($h_include_msgbox_hwnd)
                Local $s_hold_button = "", $i_add, $h_button_handle
                While 1
                    $i_add += 1
                    $h_button_handle = ControlGetHandle($h_include_msgbox_hwnd, "", "Button" & $i_add)
                    If Not $h_button_handle Then ExitLoop
                    $s_hold_button &= "Button" & $i_add & ","
                WEnd
                Local $a_buttons = StringSplit(StringTrimRight($s_hold_button, 1), ","), $a_cpos
                Switch $a_buttons[0]
                    Case 1
                        ControlMove($h_include_msgbox_hwnd, "", "Button1", 160, 120)
                    Case 2
                        ControlMove($h_include_msgbox_hwnd, "", "Button1", 120, 120)
                        ControlMove($h_include_msgbox_hwnd, "", "Button2", 205, 120)
                    Case 3
                        ControlMove($h_include_msgbox_hwnd, "", "Button1", 80, 120)
                        ControlMove($h_include_msgbox_hwnd, "", "Button2", 160, 120)
                        ControlMove($h_include_msgbox_hwnd, "", "Button3", 240, 120)
                EndSwitch
                Local $h_edit_handle = ControlGetHandle($h_include_msgbox_hwnd, "", "Static2")
                $a_cpos = ControlGetPos($h_include_msgbox_hwnd, "", $h_edit_handle)
                Local $s_text = ControlGetText($h_include_msgbox_hwnd, "", $h_edit_handle)
                ControlHide($h_include_msgbox_hwnd, "", $h_edit_handle)
                Local $h_gui = GUICreate("", 330, 100, $a_cpos[0] - 10, $a_cpos[1] - 10, 0x80000000)
                Local $h_edit_control = GUICtrlCreateEdit($s_text, 0, 0, 330, 100, BitOR(0x0800, 0x00200000, 0x00100000))
                DllCall("user32.dll", "int", "SetParent", "hwnd", $h_gui, "hwnd", $h_include_msgbox_hwnd)
                GUISetState(@SW_SHOW, $h_gui)
                If $a_include_msgbox[5] = -1 Then $a_include_msgbox[5] = (@DesktopWidth / 2.5)
                If $a_include_msgbox[6] = -1 Then $a_include_msgbox[6] = (@DesktopHeight / 2) - 150
                WinMove($h_include_msgbox_hwnd, "", $a_include_msgbox[5], $a_include_msgbox[6], 400, 185)
                DllCall("User32.dll", "int", "UpdateWindow", "hwnd", $h_include_msgbox_hwnd)
                ControlFocus($h_include_msgbox_hwnd, "", "Button1")
            Else
                If $a_include_msgbox[5] = -1 Then $a_include_msgbox[5] = (@DesktopWidth / 2.5)
                If $a_include_msgbox[6] = -1 Then $a_include_msgbox[6] = (@DesktopHeight / 2) - 150
                WinMove($h_include_msgbox_hwnd, "", $a_include_msgbox[5], $a_include_msgbox[6])
            EndIf
        EndIf
    EndIf
EndFunc

Func _MsgBox_StartTimer(ByRef $h_mod, $s_func, $v_ret_type, $v_params, $h_wnd, $i_event_id, $i_event_time)
    $h_mod = DllCallbackRegister($s_func, $v_ret_type, $v_params)
    If @error Then Return SetError(@error, 1, 0)
    Local $h_timer = DllCall("User32.dll", "int", "SetTimer", _
                        "hwnd", $h_wnd, _
                        "uint", $i_event_id, _
                        "uint", $i_event_time, _
                        "ptr", DllCallbackGetPtr($h_mod))
    If @error Then Return SetError(@error, 2, 0)
    Return $h_timer[0]
EndFunc

Func _MsgBox_StopTimer($h_mod, $h_timer, $h_wnd = 0)
    DllCallbackFree($h_mod)
    DllCall("User32.dll", "int", "KillTimer", "hwnd", $h_wnd, "int", $h_timer)
    If @error Then Return SetError(@error, 0, 0)
    Return 1
EndFunc
Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

Nice job on the script, however in the MsgBox.au3 include file it is showing an error in the script. ( around 40th line, in _MsgBox_Execute() function)

MsgBox($a_include_msgbox[0], _
                $a_include_msgbox[1], _
                $a_include_msgbox[2], _
                $a_include_msgbox[3], _
                $a_include_msgbox[4]) ;<- problem line

The above has one more argument than MsgBox can handle. I got rid of the 5th arg and it seems to run fine.

[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

  • Moderators
Posted

Nice job on the script, however in the MsgBox.au3 include file it is showing an error in the script. ( around 40th line, in _MsgBox_Execute() function)

MsgBox($a_include_msgbox[0], _
                $a_include_msgbox[1], _
                $a_include_msgbox[2], _
                $a_include_msgbox[3], _
                $a_include_msgbox[4]) ;<- problem line

The above has one more argument than MsgBox can handle. I got rid of the 5th arg and it seems to run fine.

You're not running a current release then :P ...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted

You're not running a current release then :idea: ...

Fair enough :P ... been a while since I've checked for the latest version, haven't had the need for the latest version.

FYI..for those running 3.2.10.x, removing that 5th arg for the MsgBox makes it work :(

[font="Verdana"]People who say it cannot be done should not interrupt those who are doing it. - George Benard Shaw[/font]

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
×
×
  • Create New...