Jump to content
Xtreme .Net Talk

ManagementObjectSearcher Win32_Printer - UnauthorizedAccessException


Recommended Posts

Posted

I recently had to open a project because someone on our production floor did not know how to navigate the menus. When I tried to run it, I got an Unauthorized Access Exception for code that I had not modified.

 

This query worked before installing VS2008, but now it will not run in a test application under VS2005 either.

 

My code fails in the foreach loop when the printer is assigned at this line:

(ManagementObject printer in Printers)

 

public static void GetPrintersCollection() {
 try {
   string sql = "SELECT * FROM Win32_Printer";
   using (ManagementObjectSearcher query = new ManagementObjectSearcher(sql)) {
     ManagementObjectCollection Printers = query.Get();
     foreach (ManagementObject printer in Printers) {
       Console.WriteLine(printer.Properties["Name"].Value.ToString());
     }
   }
 } catch (UnauthorizedAccessException err) { // err.Message is empty
   Console.WriteLine("You do not have authorization to access this printer.");
 } catch (Exception err) {
   Console.WriteLine(err.Message);
 }
}

 

Any ideas why?

 

Help! Please, and Thank You!

Posted

I have traced the problem down as far as Event Viewer, where the error shows up under the local System tab, and I do not know how to resolve this.

 

Here is a screen shot of the error:

 

http://sites.google.com/site/jp2code/home/list/wmiprvse-Event.gif

 

The description of the error is as follows (if the image is ever deleted):

Source: DCOM

EventID: 10000

User: NT AUTHORITY\NETWORK SERVICE

Description:

Unable to start a DCOM Server: {1F87137D-0E7C-44D5-8C73-4EFFB68962F2}. The error:

"Access is denied. "

Happened while starting this command:

C:\WINDOWS\system32\wbem\wmiprvse.exe -secured -Embedding

 

For more information, see Help and Support Center at

http://go.microsoft.com/fwlink/events.asp.

The link, however, is broken on my machine.

 

Any help in troubleshooting this problem is greatly appreciated.

 

Regards,

~Joe

  • Administrators
Posted (edited)

Has anything else changed apart from installing 2008? One possibility is a change in permissions for your network account.

 

If you have a good backup of ytour system you could try resetting the machine permissions to the default by typing

secedit /configure /cfg %windir%\repair\secsetup.inf /db secsetup.sdb /verbose

at a command prompt. Have you tried the executable on any other machine to see if it generates the same error?

Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...