Delphi - How to Change the Default File Extensions in Vista / Win 7

I am trying to add register exe file with file extension. The code below works fine with XP, but causes an error in Win Vista / 7.

var
  reg: TRegistry;
begin
  reg := TRegistry.Create;
  try
    reg.RootKey := HKEY_CLASSES_ROOT;
    reg.OpenKey('.' + ExtName, True);
    reg.WriteString('', ExtName + 'file');  //error: Failed to set data for ''
    reg.CloseKey;
    reg.CreateKey(ExtName + 'file');
    reg.OpenKey(ExtName + 'file\DefaultIcon', True);
    reg.WriteString('', AppName + ',0');
    reg.CloseKey;
    reg.OpenKey(ExtName + 'file\shell\open\command', True);
    reg.WriteString('', AppName + ' "%1"');
    reg.CloseKey;
  finally
    reg.Free;
  end;

  SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);

How can I accomplish the same task in Vista / 7?

+3
source share
1 answer

Have you tried running this as an administrator? You cannot write HKEY_CLASSES_ROOT like any old user in Vista. You also cannot in XP, unless you work as a powerful user / administrator. That many developers, but that apart from the point.

In other words, for this you need height. Here is a good link on how to customize the manifest to tag your application with this feature.

+10
source

Source: https://habr.com/ru/post/1730100/


All Articles