Sign in to follow this  
Followers 0
beato

reg delete a key w/ only part of it name

6 posts in this topic

I'm sure this is easy for most, but I cant seem to get this.

I have a reg key I want to delete, but part of the key name could be different for some users (by design).

For example

RegDelete("HKLM64\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Autoit Installation Manager 123456-789")

Where the number "123456-789" could be different, so I just want to search for "Autoit Installation" and if it finds that, delete that key.

So I have tried several methods like:

$sKey = 'HKLM64\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Autoit Installation Manager *'
$i = 1
While 1
    $Key = RegEnumVal($sKey, $i)
    If @error = -1 Then ExitLoop
    If Not @error And StringRegExp($Key, 'Autoit Installation Manager[ ]?') Then
        RegDelete($sKey)
        ContinueLoop
    EndIf
    $i += 1
WEnd

But again I can't seem to correctly filter (wildcard) directories and reg keys correctly. Any suggestions?

Thanks.

Share this post


Link to post
Share on other sites



$$i = 1
$root = "'HKLM64\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"

while 1

$key = regenumkey ($root, $i)
If @Error Then exitloop

msgbox (0, '' , $key)

If stringinstr($key , "autoit installation") Then
    regdelete ($root & $key)
    $i += 1
Else
    $i += 1
EndIf

wend


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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

$$i = 1
$root = "'HKLM64\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"

while 1

$key = regenumkey ($root, $i)
If @Error Then exitloop

msgbox (0, '' , $key)

If stringinstr($key , "autoit installation") Then
    regdelete ($root & $key)
    $i += 1
Else
    $i += 1
EndIf

wend

Perfect, thank you very much :) I commented out the msgbox since this portion will run inside a larger piece that is silent.

Can you explain how the $i += 1 works/its purpose?

Edited by beato

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

keeps incrementing the value for the subkey , the messagebox was just for that visual.

it means

$i = $i + 1
if thats what you were inquiring. Edited by iamtheky

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

Share this post


Link to post
Share on other sites

keeps incrementing the value for the subkey , the messagebox was just for that visual.

it means

$i = $i + 1
if thats what you were inquiring.

Yep, that's what I was referring to. So when it "keeps incrementing the value for the subkey" does that mean it reads (loops) all the keys in the ....Version\Uninstall hive then stops?

Thanks again

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

yup it runs them until the @Error, which will hopefully be caused by the loop incrementing to the value 1 greater than the number of subkeys, and not some other cause.

Edited by iamtheky

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

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