Solved

Self Registering DLL's

Posted on 2004-12-15
15
17,929 Views
Last Modified: 2013-12-03
I have an application, which upon startup, registers a required DLL for integration with another product.

The main problem is that a standard windows user does NOT have the correct permissions to self register a DLL, so obviously the operation is failing under restricted accounts.

Even if I pre-register the DLL as an administrator, the DLL does not seem to be registered anymore when logging back on as a user, it seems to un-register itself. Is this behavior expected for self registering DLLs?

How can I get around this problem?
0
Comment
Question by:jschweg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
  • +1
15 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 12834013
>>Even if I pre-register the DLL as an administrator, [...] it seems to un-register itself.

No, the problem is that when registering such a DLL as an admin, the registry entries get security settings that make them unaccessible for 'normal'´users.

BTW, check whith the dependency walker (www.dependencywalker.com) *why* these DLLs cannot be registered - if it is an issue about another DLL being unaccessible or something else.
0
 
LVL 4

Author Comment

by:jschweg
ID: 12834094
Essentially the program is doing a "regsvr32 dllname"

Is it even possible for ANY regular user to even register ANY dll, since it would require write access to the registry which regular user don't have?
0
 
LVL 86

Expert Comment

by:jkr
ID: 12834136
That's why I asked why the registration is failing - if you're only writing to HKEY_CLASSES_ROOT, this should not happen. BTW, RegMon (http://www.sysinternals.com/ntw2k/source/regmon.shtml) helps detecting access rights problems
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 14

Expert Comment

by:RichieHindle
ID: 12834490
A non-admin user cannot write directly to HKEY_CLASSES_ROOT.  Many self-registering DLLs try to do this, and they will fail for non-admin users.  MFC DLLs generated with MSVC 6 have this problem.  A non-admin user can only write to HKEY_CURRENT_USER\SOFTWARE\Classes, which is that user's own private HKEY_CLASSES_ROOT.

As jkr said, you should use RegMon to see where the DLL is trying to write to.  If it's HKEY_CLASSES_ROOT and it's failing with permissions errors, you need to get the author of the DLL to make it fall back to writing to HKEY_CURRENT_USER\SOFTWARE\Classes if HKET_CLASSES_ROOT fails.

(I went though all this just last week with one of our MFC DLLs. 8-)
0
 
LVL 86

Expert Comment

by:jkr
ID: 12834535
>> A non-admin user cannot write directly to HKEY_CLASSES_ROOT
>> HKEY_CURRENT_USER\SOFTWARE\Classes

Sorry to disagree, but HKEY_CLASSES_ROOT is just a link to HKEY_CURRENT_USER\SOFTWARE\Classes, as HKEY_CURRENT_USER is a link to HKEY_USERS\[some user SID]
0
 
LVL 14

Expert Comment

by:RichieHindle
ID: 12834723
jkr: Clearly HKEY_CLASSES_ROOT is *not* just a link to HKEY_CURRENT_USER\SOFTWARE\Classes, otherwise a user would only see the registry entries that he himself had created.  It is an combination of HKCU\SOFTWARE\Classes and HKLM\SOFTWARE\Classes.

It's not difficult to verify that a non-admin user cannot write directly to HKCR.  In Windows XP, go Start / Control Panel / User Accounts / Create a new account / call it "nonadmin" / Next / select Limited / Create Account.  Log in as "nonadmin" / Start / Run / "regedit".  Open HKCR and try to create a key.  You can't.  Now try again in HKCU\SOFTWARE\Classes - success.  Go back to HKCR and you'll see the new key there.
0
 
LVL 86

Expert Comment

by:jkr
ID: 12834789
From 'Inside Windows 2000"

Table 5-2 Registry Root Keys

Root Key Abbreviation Description Link
HKEY_CURRENT_USER HKCU Points to the user profile of the currently logged-on user  Subkey under HKEY_USERS corresponding to currently logged-on user
HKEY_USERS HKU  Contains subkeys for all loaded user profiles  Not a link
HKEY_CLASSES_ROOT HKCR  Contains file association and COM registration information HKLM\SOFTWARE\ Classes
HKEY_LOCAL_MACHINE HKLM Placeholder— contains other keys  Not a link
HKEY_CURRENT_CONFIG HKCC Current hardware profile HKLM\SYSTEM\CurrentControlSet\Hardware Profiles\Current
HKEY_PERFORMANCE_DATA HKPD  Performance counters Not a link

HKEY_CLASSES_ROOT
HKCR consists of two types of information: file extension associations and COM class registrations. A key exists for every registered filename extension. Most keys contain a REG_SZ value that points to another key in HKCR containing the association information for the class of files that extension represents. For example, HKCR\.xls would point to information on Microsoft Excel files in a key such as HKCU\Excel.Sheet.8. Other keys contain configuration details for COM objects registered on the system.

The data under HKEY_CLASSES_ROOT comes from two sources:

The per-user class registration data in HKCU\SOFTWARE\Classes (mapped to the file on hard disk \Documents and Settings\<username> \Local Settings\Application Data\Microsoft\Windows\Usrclass.dat)


Systemwide class registration data in HKLM\SOFTWARE\Classes

The addition of per-user class registration data is new to Windows 2000. This change was made to separate per-user registration data from systemwide state so that roaming profiles can contain these customizations. It also closes a security hole: in Microsoft Windows NT 4, a nonprivileged user could change or delete keys in HKEY_CLASSES_ROOT, thus affecting the operation of applications on the system. In Windows 2000, nonprivileged users and applications can read systemwide data but can modify only their private data.

0
 
LVL 14

Expert Comment

by:RichieHindle
ID: 12834881
jkr: Thanks for the official confirmation of what I said.

jschweg: Any luck with RegMon?  Is the DLL trying and failing to write to HKCR?
0
 
LVL 4

Author Comment

by:jschweg
ID: 12837005
Thanks for all the replies, I appreciate it.

RichieHindle: I know for an absolute fact that it is attempting to write to CLASSES_ROOT, because if I give the users group full access to CLASSES_ROOT, the DLL actually registers just fine. Regmon also reveals this as well.

So what you guys are saying is that I need to register the DLL to HKEY_CURRENT_USER\SOFTWARE\Classes? Cool.

I didn't think the creator of the DLL had any control over where and how it gets registered, I thought regsvr32 took care of all of that. So what you are saying is that the developers can change this behavior?

Sorry, bear with me, I'm not a developer.
0
 
LVL 14

Assisted Solution

by:RichieHindle
RichieHindle earned 200 total points
ID: 12838164
Yes, it's up to the author of the DLL where it registers - all regsvr32 does is call a function in the DLL to tell it to register itself.  What we did when we had this problem was try writing the registry keys to HKCR, and if that fails, write them to HKCU\SOFTWARE\Classes instead.

(If it's an MFC DLL then the exported function is written for you, so the developer might not even be aware of it.  It's called DllRegisterServer, and by default an MFC DLL will simply call MFC to get it to register.  The problem is that with MFC 6, MFC will only try to write to HKCR.  If this is the case with your DLL, the author will have to duplucate the MFC functionality, adding the ability to write to HKCU\SOFTWARE\Classes if HKCR fails.  This may well be irrelevant in your case, but it could be worth passing on to the developer, just in case he's not familiar with the problem.)
0
 
LVL 9

Accepted Solution

by:
_ys_ earned 300 total points
ID: 12839354
> Yes, it's up to the author of the DLL where it registers
True. But there exists an API that allows re-pointing of the hive constants HKCR etc. to alternate values.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/regoverridepredefkey.asp

Furthermode a registration tool has been developed that incorporates this API for you.
http://www.codeproject.com/w2k/regsvrex.asp
0
 
LVL 14

Expert Comment

by:RichieHindle
ID: 12839814
_ys_: Fantastic!  I wish I'd known about that last week, when I had to rewrite our DLL registration code.  8-)
0
 
LVL 86

Expert Comment

by:jkr
ID: 12869859
So, I am glad that it was *not* a permission problem that could have been spotted with RegMon...
0
 
LVL 4

Author Comment

by:jschweg
ID: 12870114
I already knew it was a permissions problem as I mentioned in my first comment, what I needed was a workaround to sucessfully register the DLL without having to modify permissions.
0
 
LVL 14

Expert Comment

by:RichieHindle
ID: 14439714
Additional note: RegOverridePredefKey (the API that _ys_ mentions above) is only available on Windows 2000 and later.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question