Jump to content

[Resolved] -- Registry issue when key is not found


Recommended Posts

I am trying to check some file extensions to make sure they have the "open confirm" and "always show extention" boxes checked. I am having issue with the application not catching if the key is not there. Basically if the AlwaysShowExt is not found it doesnt add it to the list of findings. What am I over looking here?

#include <Array.au3>
#include <File.au3>
#include <GuiConstantsEx.au3>
#include <Misc.au3>
#Include <GuiButton.au3>

_Singleton("FileChecker")

; #########################################################################################
; # Create GUI
; #########################################################################################

GUICreate("File Checker", 300, 300)

; PROGRESS

$progress = 0

$progressbar = GuiCtrlCreateProgress(60, 10, 210, 20)
GuiCtrlSetData($progressbar, $progress)
$label = GuiCtrlCreateLabel("Progress:", 5, 15)
$label2 = GUICtrlCreateLabel("File Extentions that failed:", 15, 40)
$ExtList = GUICtrlCreateList("", 10, 60, 280, 200)
$finishedButton = GUICtrlCreateButton("Finished", 120, 260, 60)
GuiSetState(@SW_SHOW)


; #########################################################################################
; # GUI Events
; #########################################################################################

Opt("GUIOnEventMode",1)
GUISetOnEvent ($GUI_EVENT_CLOSE, "Close")
GUICtrlSetOnEvent ($GUI_EVENT_CLOSE, "Finished")


Func Finished()
    Exit
EndFunc

Func Close()
    Exit
EndFunc

; ########################################################################################
; # Check Open Restricted File Type Properties
; ########################################################################################

;set keys to check
$EditFlags = "EditFlags"
$AlwaysShowExt = "AlwaysShowExt"

;set path
$RegPath = "HKEY_LOCAL_MACHINE\Software\Classes\"

Local $keyArray[50]

;set rest of path
$keyArray[0] = "AcroExch.Document"
$keyArray[1] = "PowerPoint.Show.8"
$keyArray[2] = "AcroExch.FDFDoc"
$keyArray[3] = "AcroExch.XFDFDoc"
$keyArray[4] = "PowerPoint.SliderShow.8"


$checker1 = ""
$checker2 = ""

For $x = 0 To $x = 50
    
;~  $checker1 = ""
;~  $checker2 = ""
    
    $checker1 = RegRead($RegPath & $keyArray[$x], $EditFlags)
    
    If $checker1 <> 0 Then
        $listOfFails = $x+1 & " : " & $keyArray[$x] & " : " & $checker1
        $progress = $progress + 10
        GUICtrlSetData($ExtList, $listOfFails)
        GuiCtrlSetData($progressbar, $progress)
    EndIf
    
    $checker2 = RegRead($RegPath & $keyArray[$x], $AlwaysShowExt)
    
    If $checker2 <> "" Then
        $listOfFails = $x+1 & " : " & $keyArray[$x] & " : " & $checker2
        $progress = $progress + 10
        GUICtrlSetData($ExtList, $listOfFails)
        GuiCtrlSetData($progressbar, $progress)
    EndIf
    
Next

$progress = 100

GuiCtrlSetData($progressbar, $progress)

; ########################################################################################
; # Keep GUI Alive
; ########################################################################################

 While 1
    sleep(50)
 Wend
Edited by HumperHard
Link to comment
Share on other sites

Just test @error flag after RegRead()

Return Value

Success: Returns the requested registry value. @EXTENDED is set to the type of the value $REG_... . These types are defined in the "Constants.au3" include file. 

Failure: Returns "" and sets the @error flag: 

 1 if unable to open requested key 

 2 if unable to open requested main key 

 3 if unable to remote connect to the registry 

 -1 if unable to open requested value 

 -2 if value type not supported 

Edited by Zedna
Link to comment
Share on other sites

Just test @error flag after RegRead()

I have tried that but with no luck.. I might be doing it wrong....

If $checker2 <> "" & @error <> -1 Then
        $listOfFails = $x+1 & " : " & $keyArray[$x] & " : " & $checker2
        $progress = $progress + 10
        GUICtrlSetData($ExtList, $listOfFails)
        GuiCtrlSetData($progressbar, $progress)
EndIf

I also tried just:

If @error <> -1 Then
        $listOfFails = $x+1 & " : " & $keyArray[$x] & " : " & $checker2
        $progress = $progress + 10
        GUICtrlSetData($ExtList, $listOfFails)
        GuiCtrlSetData($progressbar, $progress)
EndIf
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...