I am developing a Visual C# class library (.dll) using Visual Studio 2005. I have successfully installed, registered, and referenced (within my C# class library project) the prnadmin.dll component. I wrote a function, using prnadmin.dll, which will dynamically create a printer port and printer on my local box.
Scenario 1: I create a windows application with a reference to my class library (.dll) containing the code below. The port is created successfuly by the windows application's call to create the port.
Scenario 2: I create a ASP.Net Web service application (published locally on localhost) which references the same dll containing the code below. The Web service call to create the port fails with the following error:
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
I tried impersonating, using my own Windows account with admin rights to my own box, within the Web services' Web.config file. The impersonation still gave me the 'Access denied' message.
I am thinking that the account IIS is using to run the class library function does not have the rights to use the Printer configuration services on my box. Is this a possibility?
Any suggestions on how I can get this to work would be helpful?
PRNADMINLib.PrintMasterClass g_objPrntMaster = new PRNADMINLib.PrintMasterClass();
PRNADMINLib.Port g_objPort = new PRNADMINLib.PortClass();
g_objPort.PortName = userPort; //userport = "C:\temp\temporary.prn"
g_objPort.PortType = 3;
g_objPrntMaster.PortAdd(g_objPort);// fails here by a Web service call