Sign in to follow this  
Followers 0
RvdH

Registry Related Question

23 posts in this topic

ok, let me try to explain,

got several applications that are installed and have writen a few registry entries,

now i wan't to remove 1 app from registry but if the other app is present it may not remove registry entries that are shared, like:

if RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App2") then
   RegDelete("HKEY_CURRENT_USER\Software\MyProg\App1")
   RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App1")         
else
   RegDelete("HKEY_CURRENT_USER\Software\MyProg")
   RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg")
endif

i've tried several things,

if RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App2")<>"" then

if RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App2")="" then

if RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App2","<variable>")="" then

But unfortunatly it doesn't like my script...

How can i check if a registry value exists and if it does exist

the <variable> is different every time so, if possible it should ignore that :)

RvdH

Share this post


Link to post
Share on other sites



Look at the file file for the RedRead() function

It does return error code for key and value not found

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

i do not quite get it i think...

$app2 = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", "App2")
   If @error Then
      $app2 = 0
   Else
      $app2 = 1
   EndIf
If $app2 <> 0 Then   
   RegDelete("HKEY_CURRENT_USER\Software\MyProg\App1")
   RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App1") 
else
   RegDelete("HKEY_CURRENT_USER\Software\MyProg")
   RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg")
endif

Seems like it should work, but as i hardly have any experience with auto-it it could be a simple syntax error,

Can anyone give a example on how it should be done?

thx,

RvdH

Edited by RvdH

Share this post


Link to post
Share on other sites

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

If RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", "App2") = "" Then
   RegDelete("HKEY_CURRENT_USER\Software\MyProg\App1")
   RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App1")
EndIf
RegDelete("HKEY_CURRENT_USER\Software\MyProg")
RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg")

As i do not have your registry i cannot replicate the problem.

Can you take a screenshot of your registry in "regedit"?

#)

Share this post


Link to post
Share on other sites

Nothing to make a screenshot from... it just this code i am experimenting with...

If RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", "App2") = "" Then

RegDelete("HKEY_CURRENT_USER\Software\MyProg\App1")

RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App1")

EndIf

RegDelete("HKEY_CURRENT_USER\Software\MyProg")

RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg")

In you method it deletes both, eg; "HKEY_CURRENT_USER\Software\MyProg\App1" & "HKEY_LOCAL_MACHINE\SOFTWARE\MyProg"

The required event should be if another app exists in the same registy tree it would only remove the registry entry for that app, and if no other apps are in that registry tree it removes all

Share this post


Link to post
Share on other sites

If RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", "App2") = "" Then
RegDelete("HKEY_CURRENT_USER\Software\MyProg\App1")
RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App1")
Else
RegDelete("HKEY_CURRENT_USER\Software\MyProg")
RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg")
EndIf

This works?

#)

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

kinda, think i had the exact same code somewhere in my attempts, but think i know now why it isn't working as i would it should,

if the registry, HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", "App2" doesn't have any values besides the (default) value and other settings are stored in additional subkeys (like, HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App2", "settings") the presense of the (default) value makes the above function think it isn't empty, but for this function to work properly it should... (am i right?)

To access the (Default) value use "" (a blank string) for the valuename.

Edited by RvdH

Share this post


Link to post
Share on other sites

Anything i can do to prevent that?

can we use wildcards as regsitry keys, like:

If RegRead ("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App2\*", "") = "" Then

RegDelete("HKEY_CURRENT_USER\Software\MyProg\App1")

RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App1")

Share this post


Link to post
Share on other sites

Another thingy, can't RegEnumKey be used to check if "app2" is installed?

$var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", "App2")

if $var @error then

RegDelete("HKEY_CURRENT_USER\Software\MyProg")

RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg")

else

RegDelete("HKEY_CURRENT_USER\Software\MyProg\App1")

RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App1")

end if

Share this post


Link to post
Share on other sites

Ah come on, there has to be a way :)

once again i will try to explain what i am trying to do...

the idea is to remove a registry key, BUT only if it isn't used by other programs, like:

HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App1") ; this is the one we are removing

HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App2")

HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App3")

; here is should check if other programs are present

if RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App2") = "" or RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App3") = "" then

; other appz exist, so here it removes registry entries for only app1

RegDelete("HKEY_CURRENT_USER\Software\MyProg\App1")

RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App1")

else

; other appz do not exist, so here it removes the whole key

RegDelete("HKEY_CURRENT_USER\Software\MyProg")

RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg")

endif

Obviously, the code above isn't working... whatever i try always something remains in the registry :mellow:

Man, never could have thought it would be this hard to accomplish such a easy task :)

Anyone can give me more insight?

RvdH

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Ah come on, there has to be a way :)

Untested but something like this ?

; here is should check if other programs are present
RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App2")
$Check1 = @error
RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App3")
$Check2 = @error
; here is should check if other programs are present
if $Check1 <> 1 and $Check2  <> 1 then
; other appz exist, so here it removes registry entries for only app1
    RegDelete("HKEY_CURRENT_USER\Software\MyProg\App1")
    RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App1") 
else
; other appz do not exist, so here it removes the whole key
    RegDelete("HKEY_CURRENT_USER\Software\MyProg")
    RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg")
endif

EDIT.. Changed test if you want that both are present ..

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

"Error: Incorrect number of parameters in function call." on the two lines below,

RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App2")

RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App3")

but if i change it in its proper format, eg;

RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", "App2")

RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", "App3")

ii always end up with a empty registry key and it's not being removed (maybe the "default" value we discussed above)

like:

HKEY_LOCAL_MACHINE\SOFTWARE\MyProg

Edited by RvdH

Share this post


Link to post
Share on other sites

You cuold use RegEnumVal() to check if there are any values in the key

huh? can you give me a example, the example given in the help doesn't help much in this case

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

"Error: Incorrect number of parameters in function call." on the two lines below,

RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App2")

RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App3")

but if i change it in its proper format, eg;

RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", "App2")

RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", "App3")

ii always end up with a empty registry key and it's not being removed (maybe the "default" value we discussed above)

like:

HKEY_LOCAL_MACHINE\SOFTWARE\MyProg

Yea should have run a au3check on that...

If the APP1 is part of the KEY then it cannot be put in the Keywork parameter...

You should then use :

; here is should check if other programs are present
RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App2","")
$Check1 = @error
RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App3","")
$Check2 = @error
; here is should check if other programs are present
if $Check1 = 1 or $Check2 = 1 then
; other appz exist, so here it removes registry entries for only app1
    RegDelete("HKEY_CURRENT_USER\Software\MyProg\App1")
    RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App1") 
else
; other appz do not exist, so here it removes the whole key
    RegDelete("HKEY_CURRENT_USER\Software\MyProg")
    RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg")
endif
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

ok, that still didn't work, i ended up with everything being deleted, but finally i think i have seen the light, eg:

; here is should check if other programs are present
$var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", 1)
$var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", 2)
            
; here is should check if other programs are present
if $var = "App2" or $var = "App3" then
; other appz do exist, so here it removes the app1 key
   RegDelete("HKEY_CURRENT_USER\Software\MyProg\App1")
   RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App1") 
else
; other appz do not exist, so here it removes the whole key
   RegDelete("HKEY_CURRENT_USER\Software\MyProg")
   RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg")
endif

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

but that brings me to the next issue App1 registry entries are still present at that point, thus:

$var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", 1) --> App1

$var = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg", 2) --> App2

And what if in the future more app(nr) get added to the same key?

Can i somehow loop trough the $var and check if "App2" & "App3" are in it?

BTW, Thanks to you all for all your help on this this far!

RvdH

Edited by RvdH

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

I am still not sure about your exact logic.

So if either app1 OR app2 registry key exists, your want to delete the app1 keys

Else remove Myprog ?

Like this ?

; here is should check if other programs are present
RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App2","")
$Check1 = @error
RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App3","")
$Check2 = @error
; here is should check if other programs are present
if $Check1 = 0 or $Check2 = 0 then
; other appz exist, so here it removes registry entries for only app1
    RegDelete("HKEY_CURRENT_USER\Software\MyProg\App1")
    RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg\App1") 
else
; other appz do not exist, so here it removes the whole key
    RegDelete("HKEY_CURRENT_USER\Software\MyProg")
    RegDelete("HKEY_LOCAL_MACHINE\SOFTWARE\MyProg")
endif
Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

your method just doesn't work...i do not know why,

with yours every registry entry gets deleted, it has to be something with (DEFAULT) value

To access the (Default) value use "" (a blank string) for the valuename.

the "RegEnumKey" method works but now i have to find a way to loop through al subkeys in the particular registry key

Edited by RvdH

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