如何使用连接在不同网络中的打印机/打印服务器 [英] How use a Printer/Print Server connected in a different network
问题描述
如果我在打印机所连接的服务器上拥有管理员权限的用户帐户的凭据,我如何以编程方式连接到位于不同网络的打印机?
尝试以下代码:
How can I programatically connect to a printer located at a different network if I have the credentials to a user account with admin previliages on the server to which the printer is connected?
Tried the following code:
try
{
ConnectionOptions connection = new ConnectionOptions();
connection.Username = "username";
connection.Password = "password";
connection.Authority = "ntlmdomain:DOMAINNAME";
connection.Impersonation = ImpersonationLevel.Impersonate;
ManagementScope scope = new ManagementScope("\\\\Servers' public ip\\root\\CIMV2", connection);
scope.Connect();
ManagementObject classInstance =
new ManagementObject(scope,
new ManagementPath("Win32_Printer.DeviceID='\\\\Servers' public ip\\Printer name'"),
null);
// no method in-parameters to define
// Execute the method and obtain the return values.
ManagementBaseObject outParams =
classInstance.InvokeMethod("PrintTestPage", null, null);
// List outParams
Console.WriteLine("Out parameters:");
Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);
}
catch (ManagementException err)
{
Console.WriteLine("An error occurred while trying to execute the WMI method: " + err.ErrorCode);
}
catch (System.UnauthorizedAccessException unauthorizedErr)
{
Console.WriteLine("Connection error (user name or password might be incorrect): " + unauthorizedErr.Message);
}
这个是使用WMI Code Creator生成的,但弹出以下异常:
RPC服务器不可用。 (来自HRESULT的异常:0x800706BA)
尝试设置入站规则,如以下链接所述: http://technet.microsoft.com/en-us/library/jj717250.aspx ,但没有结果。非常感谢任何和所有的帮助。
谢谢。
This one is generated using WMI Code Creator, but the following Exception pops up:
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
Tried out setting the inbound rules as explained in the following link: http://technet.microsoft.com/en-us/library/jj717250.aspx, but availed no result. Any and all help is greatly appreciated.
Thank you.
推荐答案
这个链接可能对您有所帮助你。
1. 打印机和SafeHandles [ ^ ]
2. < a href =http://www.codeproject.com/Articles/51085/Monitor-jobs-in-a-printer-queue-NET>监控打印机队列(.NET)中的作业 [ ^ ]
3. http://www.codeproject.com/KB/printing/ [< a href =http://www.codeproject.com/KB/printing/target =_ blanktitle =New Window> ^ ]
4. HTTP:// STA ckoverflow.com/questions/15612370/printing-to-non-default-printer-from-c-sharp [ ^ ]
This links might be helpful to you.
1. Printers and SafeHandles[^]
2. Monitor jobs in a printer queue (.NET)[^]
3. http://www.codeproject.com/KB/printing/[^]
4. http://stackoverflow.com/questions/15612370/printing-to-non-default-printer-from-c-sharp[^]
这篇关于如何使用连接在不同网络中的打印机/打印服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!