我正在使用WMI Code Creator创建添加联网打印机的代码。C#/。NET:如何将联网打印机添加到本地PC帐户?
http://img13.imageshack.us/img13/9847/wmicodecreatorwin32prin.png
这是产生伟大的作品(在我的域帐户反正)代码:
using System;
using System.Management;
using System.Windows.Forms;
namespace WMISample
{
public class CallWMIMethod
{
public static void Main()
{
try
{
ManagementClass classInstance =
new ManagementClass("root\\CIMV2",
"Win32_Printer", null);
// Obtain in-parameters for the method
ManagementBaseObject inParams =
classInstance.GetMethodParameters("AddPrinterConnection");
// Add the input parameters.
inParams["Name"] = "\\\\PrintServer\\PrinterName";
// Execute the method and obtain the return values.
ManagementBaseObject outParams =
classInstance.InvokeMethod("AddPrinterConnection", inParams, null);
// List outParams
Console.WriteLine("Out parameters:");
Console.WriteLine("ReturnValue: " + outParams["ReturnValue"]);
}
catch(ManagementException err)
{
MessageBox.Show("An error occurred while trying to execute the WMI method: " + err.Message);
}
}
}
}
不过,我需要到网络打印机添加到本地计算机帐户,即一个无权访问\ PrintServer的非域帐户。
我可以在哪里将域用户的(服务帐户)用户名和密码放入上面的代码中?
我一直在谷歌搜索几个小时,但我可以找到的是一个愚蠢的职位,说如何在远程机器上添加一台打印机,这不是我想要做的。
(我需要一个远程打印机添加到当前 PC,而不是到远程计算机。)(需要说明的是登录的用户是本地计算机帐户)。
有谁知道这可以实现?
更好地启用打印服务器上的Guest帐户。 – Skomski