Jump to content

Recommended Posts

Posted

I have a line that creates a registry key with a value name that’s a file path. It generates the file path with @ScriptDir in the script since this script is meant to work from any file path.

RegWrite ( "HKLM\My\Registry\Key" , @ScriptDir & "\file\path.exe" , "REG_SZ" , "My Data Value" )

So, the value name will turn from @ScriptDir & "\file\path.exe"  into “C:\Unknown\Path\To\file\path.exe.”

 

This script is being handled by an automated system and the value of @ScriptDir will change at the whim of this system. I’ll only know the beginning part of the file path for this registry value. I tried this line to delete the registry entry but it didn’t work.

RegDelete ( "HKLM\My\Registry\Key" , @ScriptDir & "\file\path.exe"  )

I’m new to AutoIt. I’m hoping there is way to find the registry key I created and delete it. There’s multiple registry entries at this HKLM path so I don’t want to just delete that entire key. I only want to delete my registry entry. Is there a way to maybe use RegRead or wildcards to find my registry entry and delete or something?

Posted (edited)

You can use RegEnumKey or RegEnumVal to enumerate keys/values, although if you already know the value it should work automatically, with that being said, are you writing to HKLM\Software?  Because you normally can't write directly to HKLM

Edited by Subz
Posted (edited)
22 hours ago, Troubleshooter5000 said:

I’m new to AutoIt.

I'm still learning.

22 hours ago, Troubleshooter5000 said:

I’m hoping there is way to find the registry key I created and delete it. There’s multiple registry entries at this HKLM path so I don’t want to just delete that entire key. I only want to delete my registry entry. Is there a way to maybe use RegRead or wildcards to find my registry entry and delete or something?

Try this:

#RequireAdmin ; you probably need this
#AutoIt3Wrapper_UseX64=Y ; maybe you need this

;~ Create a value in the registry like so:
;~ Top key: HKEY_LOCAL_MACHINE\SOFTWARE\MyKey
;~ Value name: HKEY_LOCAL_MACHINE\SOFTWARE\MyKey
;~ Value: Delete_Me

$s_keyval = "HKEY_LOCAL_MACHINE\SOFTWARE\MyKey" ; the top key
$s_srchVal = "\file\path.exe" ; the partial string in the value name

For $i = 1 To 65535 ; unlikely you have 65535 values to search
    $var = RegEnumVal($s_keyval, $i) ; read through each value in $s_keyval (top key to start searching from) one at a time and fetch it into variable $var
    If @error <> 0 Then ContinueLoop ; continue the loop until RegEnumVal sets an errorlevel other than 0 (meaning no more values to look at)
    If StringInStr($var, $s_srchVal) Then RegDelete($s_keyval, $var) ; if string in $var has partial match to $s_srchVal, delete only that value name
Next

 

Edited by ModemJunki
Typo in code comments

Always carry a towel.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...