WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

UAC

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

wntAccessAdd 64-bit Registry Key

 Keywords: wntAccessAdd 64-bit Registry Key 

Question:

I'm trying to change the value HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}[LocalizedString] (Win7) but in order to do so I have to take ownership. The follwoign example doesn't work until I actually change the ownership:
AddExtender("WWWNT34I.DLL")
key=RegOpenKey(@REGCLASSES,"CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}")
Ok=wntAccessAdd("", key, "Administrators",401, "Reg:Full")
RegCloseKey(key)
key = RegCreateKey (@REGCLASSES,'CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}')
RegSetEx(key,'[LocalizedString]','%%Computername%%','',2)
RegCloseKey(key)
Can someone tell me how I can change ownership to Administrators?

HKEY_CLASSES_ROOT\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}

I just tried the code on a 32bit machine and there it works. On a 64bit machine there are 5 instances of this key:

T1 = wntOwnerSet("", @REGCLASSES, "CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 400, "Administrators", 0)
T2 = wntOwnerSet("", @REGCLASSES, "Wow6432Node\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 400, "Administrators", 0)
T3 = wntOwnerSet("", @REGMACHINE, "SOFTWARE\Classes\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 400, "Administrators", 0)
T4 = wntOwnerSet("", @REGMACHINE, "SOFTWARE\Classes\Wow6432Node\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 400, "Administrators", 0)
T5 = wntOwnerSet("", @REGMACHINE, "SOFTWARE\Wow6432Node\Classes\CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 400, "Administrators", 0)
If I run this code on a clean machine I see that the owner on T2, T4 and T5 is being changed while T1 and T3 remain unchanged. No Winbatch error though. The problem is that I need to change T1 or T3 in order to make this change work.

The question is how do I make the 32bit Winbatch exe change the owner of a 64bit key?

Note: UAC is enabled on the system and the script is running elevated. The compiled exe is signed and the ExecutionLevel is highestAvailable. The script works fine if I use RegOpenFlags to force it to use the 64bit key. So, the main question is: Is there a way to tell wntAccessAdd to use the 64bit key and not the redirected wow64 key?

Answer:

The wntAccessAdd() function isn't aware of the flags set by calling RegOpenFlags(); only the other Reg*() functions make use of those flags. You need to make sure that you are calling RegOpenKeyEx() to open handle to the appropriate key under the 64-bit portion of the registry and then pass that registry key handle in to wntAccessAdd().

User Reply:

Cool, that was the missing bit. The following lines did what I was looking for:
key = RegOpenKeyEx( @REGCLASSES, "", "READ", 64 , "" )
rslt = wntOwnerSet("", key, "CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", 400, "Administrators", 0)
RegCloseKey (key)
key = RegOpenKeyEx( @REGCLASSES, "CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "READ", 64 , "" )
rslt = wntAccessAdd("", key, "Administrators",401, "Reg:Full")
RegCloseKey (key)
key = RegOpenKeyEx( @REGCLASSES, "CLSID\{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "WRITE", 64 , "" )
rslt = RegSetEx(key,'[LocalizedString]','%%Computername%%','',2)
RegCloseKey (key)
Thanks for your help.

Article ID:   W18329
Filename:   wntAccessAdd 64-bit Registry Key.txt
File Created: 2012:11:26:09:57:14
Last Updated: 2012:11:26:09:57:14