1

I tried to create regisrty key in HKEY_CLASSES_ROOT but windows doesn't allow to do this , I'm trying to create it in HKEY_CURRENT_USER \SOFTWARE\Classes\CLSID{xxxxxx-xxxxxxx-xxxxxxx-xxxxxx}\abc , but it didn't created.

this is my code, whers my fault and how i can solve it.

procedure TForm1.FormCreate(Sender: TObject);
const
RegKey = '\Software\Classes\CLSID';
var
Reg: TRegistry;
DelphiPath: String;
begin
Reg:= TRegistry.Create;
Reg.RootKey := HKEY_CURRENT_USER;
Reg.CreateKey('SOFTWARE\Classes\CLSID\{018D5C66-4533-4307-9B53-224DE2ED1FE6}\abc');
Reg.Free;
end;
Adam
  • 78
  • 2
  • 11

1 Answers1

0

The key will have been created. That you did not report an exception means that the code executed sucessfully. But HKCU\Software\Classes\CLSID is a redirected key. You have a 32 bit process and the registry redirector will have created the key in the 32 bit view, that is HKCU\Software\Classes\Wow6432Node\CLSID.

If you need to create the key in the 64 bit view you can include the KEY_WOW64_64KEY flag in the Access property of the registry object. This answer has more detail: https://stackoverflow.com/a/9126382/505088

However, if your COM server is a 32 bit server, then you should let the redirector do its work.

If all of the above makes no sense to you because you've never heard of the registry redirector then you need to follow the link in the first paragraph before proceeding.

Community
  • 1
  • 1
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • You are right , I found the registry key in KEY_WOW64_64KEY ,, But i need to create it in HKEY_CLASSES_ROOT "CLSID\" because i got this message "Class not Registered ,Class ID: {DF8A4FE2-221A-4504-987A-3FD4720DB929} " when i run my delphi project on my pc – Adam Feb 02 '16 at 15:54
  • Actually you found it in the 32 bit view. I told you how to write to the 64 bit view in the answer. Did you not understand a particular part of what I said. Judging by your comment you ignored my final paragraph. Don't seek code. Seek understanding. Then the code writes itself. – David Heffernan Feb 02 '16 at 15:58
  • Are you 100% sure that the COM server is a 64 bit server? – David Heffernan Feb 02 '16 at 16:05
  • I'm sorry , i miss your last paragraph , i added KEY_WOW64_64KEY to Access property , it's still not working , and showing the same message to me. Yes I'm sure , the COM server is a 64 bit.. – Adam Feb 02 '16 at 16:09
  • @Adam If you check for the key using Registry editor that ships with Windows does it exist? If it does then your program might not be looking for that specific registry key in the correct place. Registry redirection is being used for both reading and writing to the registry. But if you can't find your generated key using registry editor then it is possible you need to grant elevated privileges to your application. Another cause might be your Anti Virus software blocking the registry key creation. – SilverWarior Feb 02 '16 at 16:22
  • Using KEY_WOW64_64KEY works but I can't see how you applied it – David Heffernan Feb 02 '16 at 16:27
  • Please, for the last time ,,, I need to add this key{DF8A4FE2-221A-4504-987A-3FD4720DB929} , in ''CLSID" in HKEY_CLASSES_ROOT ... HOW I CAN DO THIS ??????????? – Adam Feb 02 '16 at 17:09
  • 1
    Can you please stop shouting. – David Heffernan Feb 02 '16 at 17:14
  • It is plausible that XE2 doesn't apply the WOW64 access flags correctly when call RegCreateKeyEx. I can't check the source right now. But it's hard to debug the code we can't see. I answered the original question though. – David Heffernan Feb 02 '16 at 17:25
  • @DavidHeffernan: `CreateKey()` in XE2 *does* apply WOW64 flags correctly. However, it forces the key to be created with `KEY_ALL_ACCESS` rights without regard to the `Access` property, and that can fail for non-admin users. To use custom rights, you have to use `OpenKey()` instead, which respects `Access`. Set its `CanCreate` parameter to true to make it call `RegCreateKeyEx()` instead of `RegOpenKeyEx()`. – Remy Lebeau Feb 02 '16 at 17:53
  • @Remy Thanks. In this case under HKCU I doubt that rights are an issue. – David Heffernan Feb 02 '16 at 18:01