我正在尝试使用WMI在远程计算机上安装/添加联网打印机。当我输入我的本地计算机名称时,下面的代码工作正常,但当我使用任何远程计算机名称时,我收到错误消息“不支持”。我在MSDN上查找了WMI错误,并显示“不支持功能或操作”。但也注意到MSDN他们有一个'howto'添加一个新的打印机连接到远程计算机和VBs的例子。我复制了VBs示例并运行它并收到了相同的错误“不支持”。我错过了什么?对我做错了什么的想法?
ConnectionOptions conOp = new ConnectionOptions();
conOp.Impersonation = ImpersonationLevel.Impersonate;
conOp.Authentication = AuthenticationLevel.Default;
conOp.EnablePrivileges = true;
ManagementScope manScope = new ManagementScope(@"\\pcname\ROOT\CIMV2", conOp);
manScope.Connect();
ManagementClass manClass = new ManagementClass(manScope, new ManagementPath("Win32_Printer"), null);
ManagementBaseObject inParams = manClass.GetMethodParameters("AddPrinterConnection");
inParams["Name"] = @"\\server\printer";
////////Error Occurs Here
ManagementBaseObject outParams = manClass.InvokeMethod("AddPrinterConnection", inParams, null);