How to check if a register key exists?

Windows specific forum
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

How to check if a register key exists?

Post by Caronte3D »

Why this procedure output is ever = 1 ?? (no matter if key exists or not)

Code: Select all

Procedure.i RegKeyExists(exePath$)

  Protected Key.l = #HKEY_CURRENT_USER
  Protected Path.s = "Software\Microsoft\Windows\CurrentVersion\Run"
  Protected Value.s = "TEST"
  Protected String.s = Chr(34)+exePath$+Chr(34)
  Protected CurKey.l
  
      Define res.l=RegOpenKeyEx_(Key,@Path,0,#KEY_ALL_ACCESS,@CurKey)
      If res<>#ERROR_SUCCESS
        RegCloseKey_(CurKey)
        ProcedureReturn 0
      Else
        RegCloseKey_(CurKey)
        ProcedureReturn 1        
      EndIf
EndProcedure
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: How to check if a register key exists?

Post by Caronte3D »

I've figured out why happen this (this key already exists :lol: )

Then perhaps I must read the inside key value? :?

I see an: RegSetValueEx_ but not a: RegGetValueEx_

Any help apreciate
User avatar
Caronte3D
Addict
Addict
Posts: 1027
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: How to check if a register key exists?

Post by Caronte3D »

Nevermind, I already found: RegQueryValueEx_
Thanks anyway :wink:
Post Reply