Jon Lennart Aasenden
Jon Lennart Aasenden

Reputation: 4020

Check registry write permission

Is there an API call to check if the current user has write access to the registry? We have an older program which sadly stores several critical values in HKLM that must be updated when the application starts and ends (there is a service which picks these up). Elevating the user is not an option and running as admin is also not an option. We just need to check if we can write (and no, writing a key and catching the exception is not what im looking for).

Upvotes: 0

Views: 566

Answers (1)

David Heffernan
David Heffernan

Reputation: 612954

The Win32 API function that you ask for is AccessCheck. However, it's not the easiest function to use.

The commonly accepted way to do what you are attempting is to write the value without performing any checks beforehand. If the write fails with ERROR_ACCESS_DENIED, then you don't have rights. It's better to ask forgiveness than permission, certainly when it comes to Windows security!

Upvotes: 2

Related Questions