gpt4 book ai didi

C#/.NET : How to add networked printer to a local PC account?

转载 作者:可可西里 更新时间:2023-11-01 12:53:21 25 4
gpt4 key购买 nike

我正在使用 WMI Code Creator 创建代码以添加联网打印机。

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);
}
}
}
}

但是,我需要将网络打印机添加到本地 PC 帐户,即无权访问\PrintServer 的非域帐户。

在上面的代码中,我可以在哪里输入域用户(服务帐户)的用户名和密码?

我已经在谷歌上搜索了几个小时,但我所能找到的只是一个愚蠢的帖子,上面说如何在远程机器上添加打印机,这不是我想要做的。

(我需要将远程打印机添加到当前 PC,而不是远程 PC。)(需要注意的是登录用户是本地 PC 帐户。)

有人知道如何实现吗?

最佳答案

您可以在打印服务器上创建相同的本地帐户,从而启用对等身份验证...

即pc1 在本地有用户 bob1。使 bob1 成为打印服务器上的用户。

在 pc1 上以 bob1 运行你的 map 程序,你应该能够访问打印机。

这有帮助吗?

否则,网络打印机是针对每个用户的...以具有访问权限(即 runas)的域用户身份运行您的程序是行不通的,因为它只会将打印机映射到用户 session ,而不是您真正想要的 session 。

...这个呢? http://www.codescript.co.uk/wmi_connect_as_another_user.htm

...还是脚本化? http://www.microsoft.com/download/en/details.aspx?DisplayLang=en&id=12028(即使它不适用于 c#,它仍然可以提供 wmi synatx 的东西)

关于C#/.NET : How to add networked printer to a local PC account?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6963152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com