Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7689589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:11:59+00:00 2026-05-31T20:11:59+00:00

I recently made a c# printer management tool that uses a WCF service which

  • 0

I recently made a c# printer management tool that uses a WCF service which contains WMI Win32_Printer methods like AddPrinterConnection and SetDefaultPrinter.

Everything works fine if both the client and the WCF service run on the same machine. But if i try to move the WCF service on another machine, the methods stop working but nothing crashes.

The AddPrinterConnection for example returns 0 which means success but no printer is really added on the local machine. The default printer even if is set to default returns false, etc. The printers list is somehow accesible.

The WCF service behaves the same even if is hosted in IIS with an administrator identity for the application pool or hosted in ASP development server on the server.

But with the same identity on the local machine all is fine. The printer name and local machine address are sent as parameters to the WCF methods.

Is this a rights, delegation or impersonation issue? Is this a limitation of the WMI? Does anyone encountered this problem? I really need a solution for this. Thank you in advance.

EDIT: Here is some code representing the function called on the WCF service that adds a printer.

Note: On both local instalation (client and service local) and remote (client local, service remote) the function returns 0, which means “success” and no error but in the second case nothing is really added.

I tried all kind of impersonations too, and as i said the identity under which the WCF service runs is the same as the user that uses the client. I supose is a thing related to the user context, because it doesn’t make much sense. I tried to find some information from Microsoft regarding this but with no luck.

public static string AddPhysicalPrinter(string sPrinterName, string address)
    {
        try
        {
            ConnectionOptions options = new ConnectionOptions();
            options.Impersonation = ImpersonationLevel.Impersonate;
            options.Authentication = AuthenticationLevel.PacketPrivacy;
            options.EnablePrivileges = true;
            options.Username = "username";
            options.Password = "password";

            oManagementScope = new ManagementScope(new ManagementPath("\\\\" + address + "\\root" + "\\cimv2"), options);

            oManagementScope.Connect();

            ManagementClass oPrinterClass = new ManagementClass (new ManagementPath("Win32_Printer"), null);
            ManagementBaseObject oInputParameters = oPrinterClass.GetMethodParameters("AddPrinterConnection");

            oInputParameters.SetPropertyValue("Name", sPrinterName);

           ManagementBaseObject x = oPrinterClass.InvokeMethod("AddPrinterConnection", oInputParameters, null);

            foreach(PropertyData p in x.Properties)
            {
                switch ((UInt32)p.Value)
                {
                    case 0:
                        return "has been added successfuly";//success
                    case 5:
                        return "access denied";//access denied
                    case 1801:
                        return "invalid printer name";//invalid printer name
                    case 1930:
                        return "incompatible printer driver";//incompatible printer driver
                    default:
                        return "unknown error";
                }
            }

            return "unknown error";
        }
        catch (Exception ex)
        {
            return "exception caught";
        }
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:12:00+00:00Added an answer on May 31, 2026 at 8:12 pm

    After some research i found out that it is not possible to do that from a third machine. It must be done with a local logon.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a site that is using Facebook Connect and recently made some
Recently I have discovered that my release executable (made with msvc++ express 2008) becomes
I've recently made an UserControl , which took quite a long time, because I
I know that NULL isn't necessary in a programming language, and I recently made
I need help, I'm new to the WCF world having recently made the transition
I recently made the statement to a colleague that: NullReferenceExceptions should never be explicitly
I have recently made a change to an existing app and we would like
I've recently made a decompiler for AVM2/AS3, and I've noticed that Flash compiler tends
I have recently made a new homepage for my company so that employees can
I recently made this wordpress blog, where you can sign up a team for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.