小编Joh*_*ets的帖子

C#/ .NET:如何将联网打印机添加到本地PC帐户?

我正在使用WMI代码创建器来创建添加联网打印机的代码.

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 …
Run Code Online (Sandbox Code Playgroud)

.net c# windows printers

8
推荐指数
1
解决办法
5767
查看次数

标签 统计

.net ×1

c# ×1

printers ×1

windows ×1