Jump to content

Searching 2 Registry Keys For The Same Thing?


 Share

Recommended Posts

Ok i started with this from storme, but it dosent give 64 bit checking and install location is not very reliable, so i started looking at UninstallString instead as most programs seem to have it

Func GetInstalledPath()
Static $sInstalledPath = ""
If $sInstalledPath = "" Then
  $sInstalledPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Malwarebytes' Anti-Malware_is1", "InstallLocation")
  If @error Then
   $sInstalledPath = ""
   Return SetError(1, 0, "")
  EndIf
EndIf
Return $sInstalledPath
EndFunc   ;==>GetInstalledPath

So i started messing about like this

$FindPath = GetInstalledPath()
$TrimPath = StringTrimRight( $FindPath, 11)
ConsoleWrite ($TrimPath & @CRLF)
Func GetInstalledPath()
    Static $sInstalledPath = ""
    If $sInstalledPath = "" Then
  $RegExist = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\CCleaner", "UninstallString")
  If @error = 1 Then
   $sInstalledPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\CCleaner", "UninstallString")
  Else
   $sInstalledPath = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\CCleaner", "UninstallString")
  EndIf
        If @error Then
            $sInstalledPath = ""
            Return SetError(1, 0, "")
        EndIf
    EndIf
    Return $sInstalledPath
EndFunc   ;==>GetInstalledPath

This dosent work so i tried the guinness approach

MsgBox(0, "_IsRegistryExist()", _IsRegistryExist("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\CCleaner", "UninstallString")) ; 0 = Doesn't Exist
MsgBox(0, "_IsRegistryExist()", _IsRegistryExist("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\avast", "UninstallString")) ; 1 = Exists
Func _IsRegistryExist($sKeyName, $sValueName)
    RegRead($sKeyName, $sValueName)
    If @error Then
        Return 0
    EndIf
    Return 1
EndFunc   ;==>_IsRegistryExist

and blow me down it dosent work either...

The CCleaner exists without a shadow of doubt yet it wont find it..

all im trying to do is make it find the right uninstall key whether 32/64 so i can set the program location using the $TrimPath = StringTrimRight( $FindPath, 11)

anyone know why this wont work?

Edited by Chimaera
Link to comment
Share on other sites

Already tried that and also

#AutoIt3Wrapper_Res_Compatibility=Vista,Windows7

When i set it up for a 64 bit like the avast eg in the guinness one it works for me but i cant get both to work

Ive been messing about a few hrs now and i cant see why the hell it dosent work

Well unless im doing something dumb

Link to comment
Share on other sites

Just tried again with the guinness one and requireadmin and it still gives me a 0

ive been in regedit and yes the key is there with about 8 values

UninstallString being one off them and ""C:\Program Files\CCleaner\uninst.exe"" being the data within

Edited by Chimaera
Link to comment
Share on other sites

Don't complicate this, disable the registry reflection. Change HKEY_LOCAL_MACHINE to HKEY_LOCAL_MACHINE64

Now You only need to check, depending on the OS architecture and the software installed. but no longer have to care about which Autoit.exe you use.

Link to comment
Share on other sites

The whole point is for it to find the uninstall string whether its a 32 or 64 bit OS

It has nothing to do with the autoit exe type as i only compile to x86

Im using the result from this as a check to whether a program exists on a drive which i then check for file version, this is to save hardcoding c:\program files etc etc for 32 bit and 64bit os es as this will give me the correct location to work with

Edited by Chimaera
Link to comment
Share on other sites

Maybe do a little debugging to see what DOES show up?

#include <Array.au3>
Local $sKey="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
Local $aVals[100]
For $i= 1 to 100
    $aVals[$i]= RegEnumKey($sKey, $i)
    If @error <> 0 then ExitLoop
Next
_ArrayDisplay($aVals,"Subkeys under "&$sKey)

*edit: Have you also tried this registry key?:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall
Edited by Ascend4nt
Link to comment
Share on other sites

Gives me an error

(15) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$aVals[$i]= RegEnumKey($sKey, $i)

^ ERROR

Ill have a look into that as well thanks HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall

Im only trying to find a simple way that checks whether a program exists and gives me the install location, which i can then feed to other things that use it

Link to comment
Share on other sites

oops, that should be:

$aVals[$i-1]= RegEnumKey($sKey, $i)

You can adjust the array size of course to whatever you need.

Link to comment
Share on other sites

Gives me an error

(15) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:

$aVals[$i]= RegEnumKey($sKey, $i)

This "For $i= 1 to 100", should be this "For $i= 0 to 99".

Nevermind, that wouldn't work for the RegEnumKey, it just causes the exitloop to fire because of the 0. Ascend4nt was right in his post above.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Ok that works and gives me this

[0]|AddressBook

[1]|Adobe Flash Player ActiveX

[2]|Adobe Flash Player Plugin

[3]|Adobe Shockwave Player

[4]|AlwaysUnloadDll

[5]|AudELSvc

[6]|AudioCS

[7]|AutoItv3

[8]|avast

[9]|CADI

[10]|Connection Manager

[11]|DAEMON Tools Lite

[12]|Digsby

[13]|DirectDrawEx

[14]|Driver San Francisco

[15]|ENTERPRISE

[16]|Fontcore

[17]|IE40

[18]|IE4Data

[19]|IE5BAKEX

[20]|IEData

[21]|IrfanView

[22]|KLiteCodecPack_is1

[23]|Malwarebytes' Anti-Malware_is1

[24]|MobileOptionPack

[25]|Mozilla Firefox 8.0 (x86 en-US)

[26]|NewsLeecher_is1

[27]|OpenAL

[28]|QuickPar

[29]|Rage_is1

[30]|SchedulingAgent

[31]|SciTE4AutoIt3

[32]|True BoxShot_is1

[33]|Universal Extractor_is1

[34]|VLC media player

[35]|WIC

[36]|WinCHM 4.19 - Help authoring software_is1

[37]|WinRAR archiver

[38]|YTdetect

There was 143 in total

all the lower ones were MS stuff and office components

Anyway look whats missing, im beginning to suspect this is something to do with 64bit issues

I even tried a wow64 redirect disable just in case but ccleaner is still in regedit and programs and features as installed

This is beyond weird

Ive attached a image of the regedit so you can see im not lying

Link to comment
Share on other sites

Through some research the only keys that are valid are (well on my system)

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall

So ive knocked up a test rig and ill take it to work and check there as some machines have ccleaner installed

I just dont understand why the key is there and its not at the same time on my system ??

Link to comment
Share on other sites

What's the output if you run this?

ConsoleWrite(@OSVersion & ' ' & @OSArch & @CRLF & @CRLF)
$var1 = RegRead("HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\CCleaner", "UninstallString")
ConsoleWrite('1: ' & $var1 & @TAB & @error & @CRLF)
$var2 = RegRead("HKLM64\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\CCleaner", "UninstallString")
ConsoleWrite('2: ' & $var2 & @TAB & @error & @CRLF)
$reg_query = Run('REG QUERY HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\CCleaner /v UninstallString', '', @SW_HIDE, 2)
Local $var3
While 1
    $var3 &= StdoutRead($reg_query)
    If @error Then ExitLoop
Wend
ConsoleWrite('3: ' & $var3 & @CRLF)
 
$reg_query = Run(@WindowsDir & '\sysnative\REG.exe QUERY HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\CCleaner /v UninstallString', '', @SW_HIDE, 2)
Local $var4
While 1
    $var4 &= StdoutRead($reg_query)
    If @error Then ExitLoop
Wend
ConsoleWrite('4: ' & $var4 & @CRLF)

Is it different if you run as admin or not?

Link to comment
Share on other sites

I get this as normal but i only use an admin acc

WIN_7 X64
1: &quot;C:\Program Files\CCleaner\uninst.exe&quot; 0
2:  1
3:
ERROR: The system was unable to find the specified registry key or value.
4:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\CCleaner
    UninstallString REG_SZ  &quot;C:\Program Files\CCleaner\uninst.exe&quot;

with a couple of blank spaces underneath

EDIT

With the help from you all i ended up with this

#RequireAdmin
 
$soft = "\CCleaner"
$string_search = "UninstallString"
$path_1 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall" & $soft
$path_2 = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" & $soft
$path_3 = "HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" & $soft
$path_4 = "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" & $soft
 
If _IsRegistryExist($path_1, $string_search) = 1 Then
$soft_path = RegRead($path_1, $string_search)
ConsoleWrite("1 " & $soft_path & @CRLF)
ElseIf _IsRegistryExist($path_2, $string_search) = 1 Then
$soft_path = RegRead($path_2, $string_search)
ConsoleWrite("2 " & $soft_path & @CRLF)
ElseIf _IsRegistryExist($path_3, $string_search) = 1 Then
$soft_path = RegRead($path_3, $string_search)
ConsoleWrite("3 " & $soft_path & @CRLF)
ElseIf _IsRegistryExist($path_4, $string_search) = 1 Then
$soft_path = RegRead($path_4, $string_search)
ConsoleWrite("4 " & $soft_path & @CRLF)
EndIf
 
 
Func _IsRegistryExist($sKeyName, $sValueName); 0 = Doesn't Exist / 1 = Exists  <<< author = guinness
RegRead($sKeyName, $sValueName)
If @error Then
  Return 0
EndIf
Return 1
EndFunc   ;==>_IsRegistryExist
Edited by Chimaera
Link to comment
Share on other sites

Ooh, nice catch JFX. I didn't even know that HKLM64 option was available in RegRead. That must use the flag 'KEY_WOW64_64KEY' when opening the registry key (via RegOpenKeyEx). That should solve Chimaera's 32-bit code problem then. (try HKLM64 if HKLM doesn't work, HKCU64 if HKCU doesn't.. etc). Good stuff to know.

Some good MSDN links:

32-bit and 64-bit Application Data in the Registry

Accessing an Alternate Registry View

Registry Reflection

Registry Redirector

Seems most programs should always avoid tacking 'Wow6432Node' onto a registry key value, even though some use it in 64-bit code. However, there's no HKLM32 equivalent in AutoIt regread currently (i.e. using KEY_WOW64_32KEY when opening a key), so thats why some code uses it, I presume. 'Registry Reflection' should prevent such a need in most keys though.

Edited by Ascend4nt
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...