Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if the current user can write to the registry (C, windows)

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.

like image 440
wonderer Avatar asked Feb 01 '26 10:02

wonderer


1 Answers

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.
like image 98
Chris Becke Avatar answered Feb 03 '26 02:02

Chris Becke