Regdelete in action script won't delete multiple values

(imported topic written by SystemAdmin)

I’m want to use the following action script to delete multiple registry values, however it will only delete the last value every time. If I run it again and again and again I will eventually have everything delete, but why will it now just delete all three values with one pass?

if {exists value "SystemComponent1" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1" of registry}
  regdelete "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1]" "SystemComponent1"
 endif
 
 if {exists value "SystemComponent2" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1" of registry}
  regdelete "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1]" "SystemComponent2"
 endif
 
 if {exists value "SystemComponent3" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1" of registry}
  regdelete "[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1]" "SystemComponent3"
 endif

(imported comment written by dmccalla)

Hi Andrew,

You can get rid of the if statements and just run the regdelete commands like this…

regdelete "

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1

" “SystemComponent1”

regdelete "

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1

" “SystemComponent2”

regdelete "

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1

" “SystemComponent3”

Also, if you need to delete a 64-bit registry key/value you need to use regdelete64.

(imported comment written by SystemAdmin)

Duncan,

If one regdelete command fails due to a value not being present, will all the following commands not fail?

(imported comment written by dmccalla)

Yeah. I missed that. Was kind of late when I replied to this. I will write something up for you tomorrow if that is cool. Traveling today.

(imported comment written by dmccalla)

Sorry for the delay. End of last week was a tad hectic. Your original actionscript should have worked but it looks like we have a bug or perhaps we just need to write the actionscript for this use case a little differently because of how the regdelete command works.

I have submitted a bug report for this. For tracking purposes, the big ID is 53704. As for the “workaround”, when we run the regdelete command it writes out a .reg file and then regedit is called to process that file. Since we have multiple regdelete commands in sequence here what I think is happening is the regdelete commands are stepping on each other. The .reg file that gets created by the regdelete command is being overwritten by the following regdelete command before original regedit call has time to do its thing. Thus the behavior of the last detected registry key being deleted and the other ones remain. Other behavior is possible I suppose, depending on system performance, but the root cause seems to be the same. To get around this we can just add a pause into the actionscript to give regdelete time to do its thing.

Note that on x64 systems you will need to use ‘regdelete64’. You should also use ‘native registry’ instead of just ‘registry’. On 32 bit versions of windows, ‘native registry’ returns the same as x32 registry (or just plain old ‘registry’). On 64 bit versions of windows, it returns the same as x64 registry.

if {exists values “SystemComponent1” of keys “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1” of registry}

regdelete "

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1

" “SystemComponent1”

endif

pause while {exists values “SystemComponent1” of keys “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1” of registry}

if {exists values “SystemComponent2” of keys “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1” of registry}

regdelete"

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1

" “SystemComponent2”

endif

pause while {exists values “SystemComponent2” of keys “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1” of registry}

if {exists values “SystemComponent3” of keys “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1” of registry}

regdelete "

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1

" “SystemComponent3”

endif

pause while {exists values “SystemComponent3” of keys “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Test1” of registry}