Jump to content

_RegExist(), _AddKey(), _DeleteKey() and _UpdateKey()


Go to solution Solved by ioa747,

Recommended Posts

Hey mate,

Just a thought, are you running autoit as 64bit or 32bit? - if you're using x86 "HKLM\Software" will in reality map to "HKLM\Software\Wow6432Node"

Try running this, then change the "Y" to "N". you will get different results.

#AutoIt3Wrapper_UseX64=N
ConsoleWrite(RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "Version") & @CRLF)

Also as a side note, this might give you problems down the track - if RegDelete fails, it can give you different error codes depending on the reason for failure.

RegDelete($sKeyName, $sValueName)
    ; -----------------
    If @error = 1 Then

If for e.g. if the error code is -1 ("unable to delete requested value" for RegDelete()), you're script will happily think all is ok.

Link to comment
Share on other sites

try this and tell me the results

#include <MsgBoxConstants.au3>
; -----------------------------------------------
_DeleteRegKey()
; -----------------------------------------------
Func _DeleteRegKey()
    ; Source data
    Local $sKeyName = "HKEY_LOCAL_MACHINE\Software\Native Instruments\Guitar Rig 5"
    Local $sValueName = "InstallVSTDir"
    ; -----------------------------------------------
    Local $check = RegDelete($sKeyName, $sValueName)
    ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $check = ' & $check & ' >Error code: ' & @error & @CRLF) ;### Debug Console
    
     $sConfirm = RegRead($sKeyName, $sValueName)
    If @error = 0 Then ; If @error = 0,  it means he read it,  so it wasn't deleted
        MsgBox($MB_TOPMOST, "RegWrite", $sValueName & "...not succesfully deleted" & @CRLF)
    Else
        MsgBox($MB_TOPMOST, "RegWrite", $sValueName & "...succesfully deleted")
    EndIf

EndFunc   ;==>_DeleteRegKey
; -----------------------------------------------

 

I know that I know nothing

Link to comment
Share on other sites

ioa747,

In this posting [Click_Me]. I really like the "Switch|Case" employment. Can this "Switch|Case" script employment be implemented in a similar manner in the "_DeleteRegKey" script?
• Is this altering of the "Switch|Case" employment simply a matter of altering the output text?

For $i = 1 To $_sSrcPath[0]
        $Result = FileDelete($_sSrcPath[$i])
        Switch $Result
            Case 0 ; The data does not exist
                $Result = "The data... " & $_sSrcPath[$i] & " ...does not exist!"
            Case 1 ; The data does exist
                $Result = "The data... " & $_sSrcPath[$i] & " ...was deleted sucessfullly!"
        EndSwitch
        $sMessage &= $i & ") " & $Result & @CRLF
        Sleep(300)
    Next
    $sMessage &= "Remove App data completed..." & @CRLF

I do hope that this all makes sense?

Link to comment
Share on other sites

above, the image is redundant
what i want to know is
1) there was a key/value of the first call to _DeleteRegKey()
2) after you call it, what does the console say? what does MsgBox() say
3) deleted the key/value?

 

(of course you backed up the registry, especially when you play with it)

I know that I know nothing

Link to comment
Share on other sites

ioa747,

How is this little tid-bit?

; -----------------------------------------------
Example()
; -----------------------------------------------
Func Example()
    Local $sFilePath = "E:\Desktop\File1.txt"
    Local $sMessage = "TestMe" & @CRLF
    ; -----------------------------------------------
    SplashTextOn("NOTICE!!", $sMessage, 380, 100, -1, -1, 4)
    ; -----------------------------------------------
    Local $Result = FileExists($sFilePath)
    ; -----------------
    Switch $Result
        Case 0     ; The data does not exist
            $Result = "The data... " & $sFilePath & " ...does not exist!"
        Case 1     ; The data does exist
            $Result = "The data... " & $sFilePath & " ...does exist!"
    EndSwitch
    ; -----------------
    $sMessage &= $Result & @CRLF & "TestMe" & @CRLF
    ; -----------------------------------------------
    SplashTextOn("NOTICE!!", $sMessage, 380, 100, -1, -1, 4)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>Example
; -----------------------------------------------

 

Link to comment
Share on other sites

Hello,

May I ask "Why is this script not working?"

; -----------------------------------------------
Example()
; -----------------------------------------------
Func Example()
    Local $sKeyName = "HKEY_LOCAL_MACHINE\Software\Native Instruments\Guitar Rig 5"
    Local $sValueName = "InstallVSTDir"
    ; -----------------
    Local $sMessage = ""
    ; -----------------------------------------------
    Local $Result = RegRead($sKeyName, $sValueName)
    ; -----------------
    Switch $Result
        Case 0     ; The data does not exist
            $Result = "The Value... " & $sValueName & " ...does not exist!"
        Case 1     ; The data does exist
            $Result = "The Value... " & $sValueName & " ...does exist!"
    EndSwitch
    ; -----------------------------------------------
    SplashTextOn("NOTICE!!", $Result & $sMessage, 350, 50, -1, -1, 4)
    Sleep(5000)
    SplashOff()
EndFunc   ;==>Example
; -----------------------------------------------

 

 

Example.png

Edited by mr-es335
Link to comment
Share on other sites

I still suspect the script is running as 32bit, which remaps the software key to wow6432node.

If this is the case, you'll think that you're checking :

HKEY_LOCAL_MACHINE\Software\Native Instruments\Guitar Rig 5

but in reality you'll be checking:

HKEY_LOCAL_MACHINE\Software\WOW6432Node\Native Instruments\Guitar Rig 5

Make this the first line in the script and see if it changes things.

#AutoIt3Wrapper_UseX64=Y

Also FYI you're now not handling the success condition of RegRead correctly - The following will not happen!

"The Value... " & $sValueName & " ...does exist!"

 Success and fail conditions differ between functions, so check the helpfile so you know what to look for!

 

Edit: Correction

Edited by MattyD
Link to comment
Share on other sites

2 hours ago, mr-es335 said:

May I ask "Why is this script not working?"

case 1
here $Result will never be 1 or 0
will be "" or "C:\Program Files\Native Instruments\VSTPlugins 32 bit"

case 2
If the key was 64bit, maybe you need to change the key to
Local $sKeyName = "HKEY_LOCAL_MACHINE64\Software\Native Instruments\Guitar Rig 5"

try

; -----------------------------------------------
Example()
; -----------------------------------------------

Func Example()
    Local $sKeyName = "HKEY_LOCAL_MACHINE\Software\Native Instruments\Guitar Rig 5"
;~  Local $sKeyName = "HKEY_LOCAL_MACHINE64\Software\Native Instruments\Guitar Rig 5"
    Local $sValueName = "InstallVSTDir"
    ; -----------------
    Local $sMessage = ""
    ; -----------------------------------------------
    Local $Result = RegRead($sKeyName, $sValueName)
    ConsoleWrite("$Result=" & $Result & @CRLF)
    ; -----------------
    Switch $Result
        Case "C:\Program Files\Native Instruments\VSTPlugins 32 bit"
            $Result = "The Value... " & $sValueName & " ...does exist!"
        Case Else
            $sMessage = "The Value... " & $sValueName & " ...does not exist!"
    EndSwitch
    ; -----------------------------------------------
    SplashTextOn("NOTICE!!", $sMessage, 350, 50, -1, -1, 4)
    Sleep(5000)
    SplashOff()
EndFunc   ;==>Example
; -----------------------------------------------

 

try it
and if ConsoleWrite("$Result=" & $Result & @CRLF)
no refund
comment out Local $sKeyName = "HKEY_LOCAL_MACHINE\Software\Native Instruments\Guitar Rig 5"
and uncomment Local $sKeyName = "HKEY_LOCAL_MACHINE64\Software\Native Instruments\Guitar Rig 5"
and try again

Edited by ioa747
correction from VSTPluains to VSTPlugins

I know that I know nothing

Link to comment
Share on other sites

Hello,

Thanks for both of your help...appreciated!!

The environment IS 32-bit. Nothing either of you has suggested is apparently working!

All that I am attempting to do is convert this [...and which DOES work!]...

; -----------------------------------------------
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Example2a()
; -----------------------------------------------
Func Example2a()
    Local $sKeyName = "HKEY_LOCAL_MACHINE\Software\Native Instruments\Guitar Rig 5"
    Local $sValueName = ""
    ; -----------------
    Local $iRegKeyExists = RegRead($sKeyName, $sValueName)
    ; -----------------------------------------------
    If @error <= 0 Then
        MsgBox($MB_SYSTEMMODAL, "", "The Reg Key does exist!")
    Else
        MsgBox($MB_SYSTEMMODAL, "", "The Reg Key does not exist!")
    EndIf
EndFunc   ;==>Example2a
; -----------------------------------------------

to this [...which DOES NOT work!]...

; -----------------------------------------------
Example2b()
; -----------------------------------------------
Func Example2b()
    Local $sKeyName = "HKEY_LOCAL_MACHINE\Software\Native Instruments\Guitar Rig 5"
    Local $sValueName = ""
    ; -----------------
    Local $sMessage = ""
    Local $Result = RegRead($sKeyName, $sValueName)
    ; -----------------------------------------------
    SplashTextOn("NOTICE!!", $sMessage, 250, 50, -1, -1, 4)
    ; -----------------------------------------------
    Switch $Result
        Case 0
            $Result = "The Reg Key does exist!"
        Case 1
            $Result = "The Reg Key does not exist!"
    EndSwitch
    ; -----------------
    $sMessage = $Result
    ; -----------------------------------------------
    SplashTextOn("NOTICE!!", $sMessage, 250, 50, -1, -1, 4)
    Sleep(2000)
    SplashOff()
EndFunc   ;==>Example2b
; -----------------------------------------------

Just for interest, the above two examples work fine when employing "data files"...however, NOT with Reg Keys?!?
• See attached...

Example1a.au3 Example1b.au3

Edited by mr-es335
Link to comment
Share on other sites

5 minutes ago, mr-es335 said:

The environment IS 32-bit. Nothing either of you has suggested is apparently working!

what I said above does not only concern the environment
so read again more carefully

I know that I know nothing

Link to comment
Share on other sites

guys, a couple of hours ago I prepared an answer before yours, but I deleted it as it was too vehement. Now I'll rephrase it differently, focusing on the one and only important fact :


@mr-es335
1) You used the FileExists function in your penultimate post, like this :

3 hours ago, mr-es335 said:
Local $Result = FileExists($sFilePath)
    ; -----------------
    Switch $Result
        Case 0     ; The data does not exist
            $Result = "The data... " & $sFilePath & " ...does not exist!"
        Case 1     ; The data does exist
            $Result = "The data... " & $sFilePath & " ...does exist!"
    EndSwitch

In this case, the $Result variable you tested could be 0 or 1, as indicated in the help file, topic FileExists :

FileExists :

Return Value
Success:    1.
Failure:    0 if path/file does not exist.

So far, so good.

2) In your last post, you're using the RegRead function in the same way, like this :

3 hours ago, mr-es335 said:
Local $Result = RegRead($sKeyName, $sValueName)
    ; -----------------
    Switch $Result
        Case 0     ; The data does not exist
            $Result = "The Value... " & $sValueName & " ...does not exist!"
        Case 1     ; The data does exist
            $Result = "The Value... " & $sValueName & " ...does exist!"
    EndSwitch

Did you read the help file (topic RegRead) before asking "why it doesn't work" ?
If you had read it, then you would have discovered by yourself that there is no $Result = 0 or 1 for RegRead

Help file, topic RegRead :

RegRead
Return Value

Success:    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:    sets the @error flag to non-zero.
@error:     1 = unable to open requested key
 2 = unable to open requested main key
 3 = unable to remote connect to the registry
-1 = unable to open requested value
-2 = value type not supported

So testing @error immediately after RegRead is the best way to check what's happening.

My advice is you should always read the help file, for any function, to make sure that you check correctly :
* The type of result that the function returns (RegRead will NEVER return 0 or 1)
* The @error value (if indicated by the help file) to be checked asap (If not @error Then... ) and certainly not the type of line I see in one of your script : if @error <= 0  .... check it always <> 0, not <=

Good luck

Edited by pixelsearch
Link to comment
Share on other sites

pixelsearch,

You stated, "Did you read the help file (topic RegRead) before asking "why it doesn't work" ? If you had read it, then you would have discovered by yourself that there is no $Result = 0 or 1 for RegRead"
• As I had noted in a previous post, I am just beginning to see the importance|significance of "error checking"!
• Thanks then...for the "head's up" here! Appreciated!

The employment of "if @error <= 0" is something that I would have gleaned from a search...I am not smart enough to understand what that particular syntax infers.

As to my original question - stated in  a different manner, "Is there any way to employ SplashTextON instead of a MsgBox?"

Lastly, I would assume then that whatever "loop" structures are deployed, that such structures must be able to "handle" the output of a particular keyboard? Would this be a correct assertion?

Thank you for the assistance here...very much appreciated!

Edited by mr-es335
Link to comment
Share on other sites

1 hour ago, mr-es335 said:

As to my original question - stated in  a different manner, "Is there any way to employ SplashTextON instead of a MsgBox?"

Why not, it depends of your goal.
* If you want to interact with the user, asking him to click "Yes" or "No", then MsgBox will do the job.
* If you need just an "informative" box indicating the user what's happening while the script is working in the background (if it takes a few seconds for example), then SplashTextOn could be used.

For example, I used it in a real script to inform the user about what was going on, 9 times in the same script (9 SplashTextOn + 9 SplashOff) . To reduce the number of arguments when calling the function, I used it with a personalized function named _SplashOn :

#include<AutoItConstants.au3>

_SplashOn("Closing file")
Sleep(5000)
SplashOff()

; _SplashOn("Closing file")
; _SplashOn("1/3 : CSV Read")
; _SplashOn("2/3 : CSV Split")
; _SplashOn("3/3 : Populating ListView")
; _SplashOn("1/2 : Export prepare")
; _SplashOn("2/2 : Export write")
; _SplashOn("Delete in progress...", $sHeader_Text) ; takes a little more time on Col 0 (wherever it has been dragged)
; _SplashOn((($iMenu_Choice = 100 Or $iMenu_Choice = 110) ? "Numeric" : "String") & " sort in progress...", $sHeader_Text)
; _SplashOn("Natural sort in progress...", $sHeader_Text)

;===========================================================
Func _SplashOn($sFirstLine, $sSecondLine = "please wait...")
    SplashTextOn("", $sFirstLine & @CRLF & $sSecondLine, _
        250, 50, -1, -1, $DLG_NOTITLE + $DLG_TEXTVCENTER)
EndFunc   ;==>_SplashOn

But the SplashOn in the precedent script isn't movable, because of what we read in the help file, topic SplashOn :

opt : $DLG_NOTITLE (1) = Thin bordered titleless window

Splash with opt=1 cannot be moved and cannot be activated by click.

So if you absolutely want your SplashOn to be moveable, then you'll need other options, without $DLG_NOTITLE
Just try and experiment, the help file is your friend.

Link to comment
Share on other sites

Good day,

Well, it would appear that ..."I have finally done it!!"

I have thus, created two scripts namely, 1) _DoesRegKeyExist and 2) _DoesRegValueExist...without the employment of MsgBox.

; -----------------------------------------------
_DoesRegKeyExist()
; -----------------------------------------------
Func _DoesRegKeyExist()
    Local $sKeyname = "HKEY_LOCAL_MACHINE\Software\Native Instruments\Guitar Rig 5"
    Local $sValuename = ""
    ; -----------------------------------------------
    RegRead($sKeyname, $sValuename)
    ; -----------------
    If @error = 1 Then
        SplashTextOn("NOTICE!!", "The registry key " & $sKeyname & " does not exist!", 800, 50, -1, -1)
        Sleep(3000)
    Else
        SplashTextOn("NOTICE!!", "The registry key " & $sKeyname & " does exist!", 800, 50, -1, -1)
        Sleep(3000)
        SplashOff()
    EndIf
EndFunc   ;==>_DoesRegKeyExist
; -----------------------------------------------
; -----------------------------------------------
_DoesRegValueExist()
; -----------------------------------------------
Func _DoesRegValueExist()
    Local $sKeyname = "HKEY_LOCAL_MACHINE\Software\Native Instruments\Guitar Rig 5"
    Local $sValuename = "InstallVSTDir"
    ; -----------------------------------------------
    RegRead($sKeyname, $sValuename)
    ; -----------------
    If @error = 0 Then
        SplashTextOn("NOTICE!!", "The registry key" & $sKeyname & $sValuename & " exists!", 850, 50, -1, -1)
        Sleep(2000)
    Else
        SplashTextOn("NOTICE!!", "The registry key" & $sKeyname  & $sValuename & "...does not exist!", 850, 50, -1, -1)
        Sleep(2000)
        SplashOff()
    EndIf
EndFunc   ;==>_DoesRegValueExist
; -----------------------------------------------

These two scripts will be deployed in all of the Registry manipulation scripts!

Edited by mr-es335
Link to comment
Share on other sites

Hello,

Unless there are some "issues" with the above scripts, I am really looking forward to closing this chapter in my scripting journey!

I now have the following five Registry scripts at my disposal:

  1. _DoesRegKeyExist.au3
  2. _DoesRegValueExist.au3
  3. _AddRegKey.au3
  4. _DeleteRegKey.au3
  5. _UpdateRegKey.au3

My heartfelt thanks to all whom assisted me thus far - especially to ios747!

Thank you all for your time, wisdom and attention, to the above. Each are very, very much appreciated!

Link to comment
Share on other sites

in this part

; -----------------------------------------------
_DoesRegKeyExist()
; -----------------------------------------------
Func _DoesRegKeyExist()
    Local $sKeyname = "HKEY_LOCAL_MACHINE\Software\Native Instruments\Guitar Rig 5"
    Local $sValuename = ""
    ; -----------------------------------------------
    RegRead($sKeyname, $sValuename)
    ; -----------------
    If @error = 1 Then
        SplashTextOn("NOTICE!!", "The registry key " & $sKeyname & " does not exist!", 800, 50, -1, -1)
        Sleep(3000)
    Else
        SplashTextOn("NOTICE!!", "The registry key " & $sKeyname & " does exist!", 800, 50, -1, -1)
        Sleep(3000)
        SplashOff()
    EndIf
EndFunc   ;==>_DoesRegKeyExist
; -----------------------------------------------

if  RegRead($sKeyname, $sValuename)  return  @error = 1 Then
SplashTextOn() does not have SplashOff()

 

in this part

; -----------------------------------------------
_DoesRegValueExist()
; -----------------------------------------------
Func _DoesRegValueExist()
    Local $sKeyname = "HKEY_LOCAL_MACHINE\Software\Native Instruments\Guitar Rig 5"
    Local $sValuename = "InstallVSTDir"
    ; -----------------------------------------------
    RegRead($sKeyname, $sValuename)
    ; -----------------
    If @error = 0 Then
        SplashTextOn("NOTICE!!", "The registry key" & $sKeyname & $sValuename & " exists!", 850, 50, -1, -1)
        Sleep(2000)
    Else
        SplashTextOn("NOTICE!!", "The registry key" & $sKeyname  & $sValuename & "...does not exist!", 850, 50, -1, -1)
        Sleep(2000)
        SplashOff()
    EndIf
EndFunc   ;==>_DoesRegValueExist
; -----------------------------------------------

if  RegRead($sKeyname, $sValuename)  return  @error = 0  Then
SplashTextOn() does not have SplashOff()

I know that I know nothing

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