Board index » delphi » Registry Permissions & COM Registration

Registry Permissions & COM Registration

Hi,
I am having a problem with the way that Delphi's COM libraries try to
register a COM object.

In Windows 2000, there are two places in the Windows registry where a COM
object class can be registered:
HKEY_LOCAL_MACHINE\SOFTWARE\CLASSES or HKEY_CURRENT_USER\SOFTWARE\CLASSES

A merged view of these two can be viewed under HKEY_CLASSES_ROOT
(for more information, see
http://msdn.microsoft.com/library/psdk/winbase/regapi_18l5.htm )

Now unless a person is logged in as Administrator or as a "Power User", she
cannot modify HKEY_LOCAL_MACHINE.  So if she runs my COM server, it must be
registered under HKEY_CURRENT_USER.  However the Delphi COM libraries do not
do this.  Whenever I try to run my COM server, it dies with an exception
while trying to register itself, because it is denied access to
HKEY_LOCAL_MACHINE.  This would appear to make any Delphi-produced COM /
Automation server software unusable in Windows 2000 (or Windows NT?) unless
the user is logged in as a Administrator or "Power User" (which is
unfortunately very common).

My question is this: how do I change or work around the behaviour of the
Delphi COM libraries to allow COM servers to work in Windows 2000?

Thanks!
Luke.

 

Re:Registry Permissions & COM Registration


Quote
"Luke Deller" <ldel...@xplantechnology.com> wrote in message

news:3aee2bc6_1@dnews...

Quote
> Hi,
> I am having a problem with the way that Delphi's COM libraries try to
> register a COM object.

> Now unless a person is logged in as Administrator or as a "Power User",
she
> cannot modify HKEY_LOCAL_MACHINE.  So if she runs my COM server, it must
be
> registered under HKEY_CURRENT_USER.  However the Delphi COM libraries do
not
> do this.  Whenever I try to run my COM server, it dies with an exception
> while trying to register itself, because it is denied access to
> HKEY_LOCAL_MACHINE.  This would appear to make any Delphi-produced COM /
> Automation server software unusable in Windows 2000 (or Windows NT?)
unless
> the user is logged in as a Administrator or "Power User" (which is
> unfortunately very common).

> My question is this: how do I change or work around the behaviour of the
> Delphi COM libraries to allow COM servers to work in Windows 2000?

Hi Luke,

I had exactly this problem a couple of weeks ago.  A client moved to Win 2k,
and all of our COM servers stopped working.

The work around that I've implemented involves changing comserv.pas...

The default behaviour is to call UpdateRegistry(true) when the start mode is
anything other than smUnRegServer.  So every time the server starts, it
tries to get at the registry.  The modification below changes this so that
the registry is only updated if the server is explicitly started with
regServer / unRegServer

procedure TComServer.Initialize;
begin
  try
    case FStartMode of
      smRegServer   : UpdateRegistry(true);
      smUnRegServer : UpdateRegistry(false);
    end;
  except
    on E: EOleRegistrationError do
      // User may not have write access to the registry.
      // Squelch the exception unless we were explicitly told to register.
      if FStartMode = smRegServer then raise;
  end;
  if FStartMode in [smRegServer, smUnregServer] then Halt;
  ComClassManager.ForEachFactory(Self, FactoryRegisterClassObject);
end;

With this modification, you need to be sure that an admin user registers the
server before "normal" users try to use it.  Not generally a problem if the
server is registered during an installation process.

Hope this helps,

Mark.

--
Delphi Developers :
"The Really Useful Program for
 Setting Delphi Project Options"

Get it today from
http://www.sci-clone.co.uk/Shareware/

Other Threads