Elevation Required - Unable To Load Dll 'shell32.dll': Exception From Hresult: 0X80070542 Follow

Legacy Poster

I am trying to test the functionality of the .NET SDK specifically with respect to the Librarian functionality. I created a solution and, after realizing the mixed-mode requirements, ran into another problem with the Librarian API. If I try to reference the Librarian, the application crashes. Here is the sample code I used:


            Library library = new Library();
            LibrarianFolder folder = library.GetFolder("lib://Customer Labels");

            // Iterate through the subfolders 
            StringBuilder listingBuilder = new StringBuilder();

            foreach (LibrarianFolder subfolder in folder.Folders)
                listingBuilder.AppendFormat("Folder\t{0}\t{1}\tChildren: {2}\n", subfolder.Name, subfolder.Path, subfolder.Children.Count);

            // Iterate through the files in the directory 
            foreach (LibrarianFile file in folder.Files)
                listingBuilder.AppendFormat("File\t{0}\t{1}\tRevision: {2}\n", file.Name, file.Path, file.RevisionNumber);

            // Display the contents of the folder 
            System.Windows.Forms.MessageBox.Show(listingBuilder.ToString(), string.Format("Folder Contents ({0})", folder.Path)); 

I then get this error:


System.DllNotFoundException was unhandled
  Message=Unable to load DLL 'shell32.dll': Exception from HRESULT: 0x80070542
       at Microsoft.Win32.Win32Native.SHGetFolderPath(IntPtr hwndOwner, Int32 nFolder, IntPtr hToken, Int32 dwFlags, StringBuilder lpszPath)
       at System.Environment.InternalGetFolderPath(SpecialFolder folder, SpecialFolderOption option, Boolean suppressSecurityChecks)
       at System.Environment.GetFolderPath(SpecialFolder folder)
       at Seagull.Security.StorageManager.get_LocalFile()
       at Seagull.Security.StorageManager.GetSecurityXmlDocument()
       at Seagull.Security.SecurityDocCache.Refresh(RefreshCondition condition)
       at Seagull.Security.EffectivePermissionsManager.UpdatePermissions()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

This error occurs because the SDK is calling COM (specifically the shell32.dll) which is not accessible without Administrator privileges. It does work if the application is run as Administrator. This is a problem I am trying to avoid. Most of the workstations (especially those that are deployed for printing purposes) should not have users logged in with Administrator permissions.


I don't know exactly why the Librarian API needs to call the shell32.dll at all.


Is there a way to run this code without requiring elevation (Administrator privileges)?


I suspect that the shell32.dll is being called to get the logged in user's security context, but that seems wrong since it requires elevation (requiring Administrator permissions defeats the purpose of restricting permissions - I.e. limited workstations to print labels).  Again, I do not know exactly why the shell32.dll (unmanaged code requiring elevation) is being referenced in the Library API and I was just guessing that get the logged in user is the reason for the reference. Regardless of the reason(s) for the reference, does anyone know how to get the Librarian API working without requiring elevation?


Domingo Rodriguez
Comment actions Permalink

Could you try any of the below and let me know if it helps to stop this exception from ocurring?


  1. Open "Security Center" companion application, choose to "Modify Security Storage" and disable the "Enable Security for this PC" checkbox. Click "OK" to accept the changes.
  2. In Windows, set UAC to the minimum level (Never notify).
Domingo Rodriguez
Comment actions Permalink

Also, please note the following:


"Shell32.dll" will, by default, allow read&execute by anyone in the Users group. All users are, by default, in the Users group. So are all authenticated users. You would need to check permissions on shell32.dll, and check the "restricted user account" to ensure proper group membership.

Please sign in to leave a comment.