Sign in to follow this  
Followers 0
learningautoit

Script not working well

7 posts in this topic

Hi there:

Im trying to create this script to be able to query software install in any computer on the network. For some weird reason for this newbie the script does not work. Could you please help me ?

#include <EditConstants.au3>

#include <GUIConstantsEx.au3>

#include <StaticConstants.au3>

#include <WindowsConstants.au3>

Local $strComputer, $strInput

$Form1_1 = GUICreate("*** SIRC v1.1 ***", 343, 195, 192, 124)

GUICtrlCreateInput("", 64, 40, 225, 21)

$Label1 = GUICtrlCreateLabel("Enter Computer Name:", 64, 16, 198, 20)

GUICtrlSetFont(-1, 10, 400, 0, "Goudy Old Style")

GUICtrlSetColor(-1, 0x808000)

$Doneb1_2 = GUICtrlCreateButton( "Query", 216, 144, 75, 25)

GUISwitch($Form1_1)

GUISetState(@SW_SHOW)

While 1

$nMsg = GUIGetMsg(1)

Select

GUISetState(@SW_HIDE)

GUISwitch($Form1_2)

GUISetState(@SW_SHOW)

case $nMsg[0] = $GUI_EVENT_CLOSE and $nMsg[1] = $Form1_1

MsgBox(0, "Please read", "Click OK to exit application")

ExitLoop

EndSelect

WEnd

Do

GUICtrlCreateInput = $strComputer

If $strComputer <> '' Then

$strInput = 1

EndIf

Until $strInput = 1

$return = GUICtrlCreateInput()

_ArrayDisplay(GUICtrlCreateInput , "Installed Programs")

Func _SoftwareInfo($computer = $strComputer)

Local $Count = 1

If $computer <> '' Then $computer = '\\' & StringReplace($computer, '\', '') & '\'

Local Const $regkey = $computer & 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'

While 1

$key = RegEnumKey ($regkey, $Count)

If @error <> 0 then ExitLoop

$line = RegRead ($regkey & '\' & $key, 'Displayname')

$line = StringReplace ($line, ' (remove only)', '')

If $line <> '' Then

If Not IsDeclared('avArray') Then Dim $avArray[1]

ReDim $avArray[uBound($avArray) + 1]

$avArray[uBound($avArray) - 1] = $line

EndIf

$Count = $Count + 1

WEnd

If Not IsDeclared('avArray') Or Not IsArray($avArray) Then

Return(SetError(1, 0, ''))

Else

$avArray[0] = UBound($avArray) - 1

Return(SetError(0,0, $avArray))

EndIf

EndFunc

Share this post


Link to post
Share on other sites



way to double post and not use code tags!


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Here's something I was messing with several months ago. Perhaps it might help you.

#include <GuiListView.au3>
Opt("TrayAutoPause", 0)
Opt('GUIOnEventMode', 1)
;
Local $sSft
Global $sGui = GUICreate(' Installed Software Viewer v1.0.0', 810, 650, -1, -1)
Global $sLvw = GUICtrlCreateListView('#|Installed Software|Display Version|Publisher|Uninstall String', 5, 5, 800, 600)
_ComputerGetSoftware($sSft)
For $i = 1 To $sSft[0][0]
    GUICtrlCreateListViewItem($i & '|' & $sSft[$i][0] & '|' & $sSft[$i][1] & '|' & $sSft[$i][2] & '|' & $sSft[$i][3], $sLvw)
Next
GUICtrlSendMsg($sLvw, 0x101E, 1, 175)
GUICtrlSendMsg($sLvw, 0x101E, 2, 65)
GUICtrlSendMsg($sLvw, 0x101E, 3, 150)
GUICtrlSendMsg($sLvw, 0x101E, 4, 350)
Local $mMen = GUICtrlCreateContextMenu($sLvw)
Local $CopI = GUICtrlCreateMenuItem('Copy Uninstall String to Clipboard', $mMen)
GUICtrlSetOnEvent($CopI, '_Copy2Clip')
Local $exp = GUICtrlCreateButton('  Expand  ', 720, 615)
GUICtrlSetOnEvent($exp, '_Expand')
GUISetOnEvent(-3, '_AllExit')
GUISetState(@SW_SHOW, $sGui)
While 1
    Sleep(10)
WEnd
;
Func _AllExit()
    GUIDelete($sGui)
    Exit
EndFunc
;
Func _Copy2Clip()
    Local $proc = StringSplit(GUICtrlRead(GUICtrlRead($sLvw)), '|', 1)
    If $proc[1] == 0 Then Return -1
    If $proc[5] Then ClipPut($proc[5])
EndFunc
;
; Author JSThePatriot - Modified June 20, 2010 by ripdad
Func _ComputerGetSoftware(ByRef $aSoftwareInfo)
    Local Const $UnInstKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Local $i = 1
    Dim $aSoftwareInfo[1][4]
    For $j = 1 To 500
        $AppKey = RegEnumKey($UnInstKey, $j)
        If @error <> 0 Then ExitLoop
        If RegRead($UnInstKey & "\" & $AppKey, "DisplayName") = '' Then ContinueLoop
        ReDim $aSoftwareInfo[UBound($aSoftwareInfo) + 1][4]
        $aSoftwareInfo[$i][0] = StringStripWS(StringReplace(RegRead($UnInstKey & "\" & $AppKey, "DisplayName"), " (remove only)", ""), 3)
        $aSoftwareInfo[$i][1] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "DisplayVersion"), 3)
        $aSoftwareInfo[$i][2] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "Publisher"), 3)
        $aSoftwareInfo[$i][3] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "UninstallString"), 3)
        $i += 1
    Next
    $aSoftwareInfo[0][0] = UBound($aSoftwareInfo, 1) - 1
    If $aSoftwareInfo[0][0] < 1 Then
        MsgBox(0, 'Unknown Error', 'Invalid Array Count')
        Exit
    EndIf
    Return _ArraySort($aSoftwareInfo, 0, 1)
EndFunc
;
Func _Expand()
    _GUICtrlListView_SetColumnWidth($sLvw, 1, $LVSCW_AUTOSIZE)
    _GUICtrlListView_SetColumnWidth($sLvw, 2, $LVSCW_AUTOSIZE)
    _GUICtrlListView_SetColumnWidth($sLvw, 3, $LVSCW_AUTOSIZE)
    _GUICtrlListView_SetColumnWidth($sLvw, 4, $LVSCW_AUTOSIZE)
EndFunc
Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Share this post


Link to post
Share on other sites

Hi Ripdad:

Thanks for your reply. However i get and error when trying to run your script. Check the attachment for the detail error code.

Any ideas ?post-59505-1285337460963_thumb.jpg

Here's something I was messing with several months ago. Perhaps it might help you.

#include <GuiListView.au3>
Opt("TrayAutoPause", 0)
Opt('GUIOnEventMode', 1)
;
Local $sSft
Global $sGui = GUICreate(' Installed Software Viewer v1.0.0', 810, 650, -1, -1)
Global $sLvw = GUICtrlCreateListView('#|Installed Software|Display Version|Publisher|Uninstall String', 5, 5, 800, 600)
_ComputerGetSoftware($sSft)
For $i = 1 To $sSft[0][0]
    GUICtrlCreateListViewItem($i & '|' & $sSft[$i][0] & '|' & $sSft[$i][1] & '|' & $sSft[$i][2] & '|' & $sSft[$i][3], $sLvw)
Next
GUICtrlSendMsg($sLvw, 0x101E, 1, 175)
GUICtrlSendMsg($sLvw, 0x101E, 2, 65)
GUICtrlSendMsg($sLvw, 0x101E, 3, 150)
GUICtrlSendMsg($sLvw, 0x101E, 4, 350)
Local $mMen = GUICtrlCreateContextMenu($sLvw)
Local $CopI = GUICtrlCreateMenuItem('Copy Uninstall String to Clipboard', $mMen)
GUICtrlSetOnEvent($CopI, '_Copy2Clip')
Local $exp = GUICtrlCreateButton('  Expand  ', 720, 615)
GUICtrlSetOnEvent($exp, '_Expand')
GUISetOnEvent(-3, '_AllExit')
GUISetState(@SW_SHOW, $sGui)
While 1
    Sleep(10)
WEnd
;
Func _AllExit()
    GUIDelete($sGui)
    Exit
EndFunc
;
Func _Copy2Clip()
    Local $proc = StringSplit(GUICtrlRead(GUICtrlRead($sLvw)), '|', 1)
    If $proc[1] == 0 Then Return -1
    If $proc[5] Then ClipPut($proc[5])
EndFunc
;
; Author JSThePatriot - Modified June 20, 2010 by ripdad
Func _ComputerGetSoftware(ByRef $aSoftwareInfo)
    Local Const $UnInstKey = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    Local $i = 1
    Dim $aSoftwareInfo[1][4]
    For $j = 1 To 500
        $AppKey = RegEnumKey($UnInstKey, $j)
        If @error <> 0 Then ExitLoop
        If RegRead($UnInstKey & "\" & $AppKey, "DisplayName") = '' Then ContinueLoop
        ReDim $aSoftwareInfo[UBound($aSoftwareInfo) + 1][4]
        $aSoftwareInfo[$i][0] = StringStripWS(StringReplace(RegRead($UnInstKey & "\" & $AppKey, "DisplayName"), " (remove only)", ""), 3)
        $aSoftwareInfo[$i][1] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "DisplayVersion"), 3)
        $aSoftwareInfo[$i][2] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "Publisher"), 3)
        $aSoftwareInfo[$i][3] = StringStripWS(RegRead($UnInstKey & "\" & $AppKey, "UninstallString"), 3)
        $i += 1
    Next
    $aSoftwareInfo[0][0] = UBound($aSoftwareInfo, 1) - 1
    If $aSoftwareInfo[0][0] < 1 Then SetError(1, 1, 0)
    Return _ArraySort($aSoftwareInfo)
EndFunc
;
Func _Expand()
    _GUICtrlListView_SetColumnWidth($sLvw, 1, $LVSCW_AUTOSIZE)
    _GUICtrlListView_SetColumnWidth($sLvw, 2, $LVSCW_AUTOSIZE)
    _GUICtrlListView_SetColumnWidth($sLvw, 3, $LVSCW_AUTOSIZE)
    _GUICtrlListView_SetColumnWidth($sLvw, 4, $LVSCW_AUTOSIZE)
EndFunc

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

For $i = 1 To $sSft [0][0]

should be:

For $i = 1 To ubound($sSft) - 1
Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Thanks Iamtheky:

That works great. I would like to be able to call a computer in the network using this. Any way that I can enter a text box in which I will type the computer name and query?

For $i = 1 To $sSft [0][0]

should be:

For $i = 1 To ubound($sSft) - 1

Share this post


Link to post
Share on other sites

Actually, it was an unforseen bug on my part.

If a numeral is in the software name list then ArraySort will override the array count in the first cell.

Changed:

Return _ArraySort($aSoftwareInfo)

To:

Return _ArraySort($aSoftwareInfo, 0, 1)

in my first post.

This will sort the array -- except for the first cell.


"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

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  
Followers 0