Sign in to follow this  
Followers 0
learningautoit

Script not working well

4 posts in this topic

#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



What are you attempting to do with this script, and what is it not doing that it's supposed to?

Other than noticing that you have a button that does nothing because you don't reference it anywhere in the script. You need to look at the help files for how to create the input control because you did it all wrong. That's just from taking a quick look at your code...BTW, if you repost the code, please use the [ autoit] [ /autoit], it makes it easier to follow.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Welcome to the forum learningautoit ! Please explain what you want to do


[font="Lucida Sans Unicode"]M a k. a v e L ![/font]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi,

her you go.

#include <GUIConstantsEx.au3>
#include <Array.au3> ; Only needed for _ArrayDisplay

Global $hGui, $iComputerName, $iQuery
Global $iMsg, $aSoftware

$hGui = GUICreate("*** SIRC v1.1 ***", 343, 195, 192, 124)
GUICtrlCreateLabel("Enter Computer Name:", 64, 16, 198, 20)
GUICtrlSetFont(-1, 10, 400, 0, "Goudy Old Style")
GUICtrlSetColor(-1, 0x808000)
$iComputerName = GUICtrlCreateInput("", 64, 40, 225, 21)
$iQuery = GUICtrlCreateButton("Query", 216, 144, 75, 25)
GUISetState(@SW_SHOW, $hGui)

While 1
    $iMsg = GUIGetMsg()
    Switch $iMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $iQuery
            $aSoftware = _SoftwareInfo(GUICtrlRead($iComputerName))
            Switch @error
                Case 0 ; No errors, do what you want with the returned $aSoftware array
                    _ArrayDisplay($aSoftware)
                Case 1 ;Computer Name hasn't been supplied
                    MsgBox(32, "Computer Name?", "Please enter Computer Name before submitting your Query.", 5, $hGui)
                Case 2 ;Enumerate reg failed to retrieve any data
                    MsgBox(16, "Error", "Encountered a problem while submitting your query." & @LF & "Error Code: " & @error, 5, $hGui)
            EndSwitch
    EndSwitch
WEnd

Func _SoftwareInfo($sComputer)
    If $sComputer = "" Then Return SetError(1, 0, 0)
    Local $sRegkey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
    Local $sKey, $sLine, $sTmp = "", $iCnt = 1
    $sRegkey = '\\' & StringReplace($sComputer, '\', '') & '\' & $sRegkey
    While 1
        $sKey = RegEnumKey($sRegkey, $iCnt)
        If @error <> 0 Then ExitLoop
        $sLine = StringReplace(RegRead($sRegkey & '\' & $sKey, 'Displayname'), ' (remove only)', '')
        If $sLine <> '' Then $sTmp &= $sLine & "|"
        $iCnt += 1
    WEnd
    If $sTmp = "" Then Return SetError(2, 0, 0)
    Return SetError(0, 0, StringSplit(StringTrimRight($sTmp, 1), "|"))
EndFunc   ;==>_SoftwareInfo

Cheers

Edited by smashly

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