views:

410

answers:

1

Is there a way to check whether the current user can write to the registry? More specifically if it's not an administrator, can it write to HKEY_LOCAL_MACHINE or the policy keys on HKEY_CURRENT_USER.

I tried with LookupPrivilegeValue() but I don't think it's the right thing to do.

Code is appreciated.

+6  A: 

Theres one really simple and reliable way to see if the user has write access to a registry key:-

LONG err = RegOpenKeyEx(....,KEY_READ|KEY_WRITE);
if(err) {
  // Test err to see if its a permission error. if so, the user does not have permission.
Chris Becke