无法使用prnmngr.vbs设置远程计算机上的默认打印机

我正在使用WMI作为域pipe理员连接到我的实验室机器。 然后我运行这个命令行来创build一个打印机:

cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -a -p Test002 -m "Canon Inkjet iP100 series" -r FAKE002 

这工作正常。

然后我运行这个命令行将打印机设置为默认值:

 cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -t -p Test002 

这根本不起作用。

一些相关的细节:

  • 两个命令行都以相同的方法执行
  • 第二个命令行工作正常,如果我通过本地范围与WMI运行它
  • 我正在运行脚本的用户在机器上具有pipe理权限,并且可以手动设置默认打印机
  • 我正在创build远程作用域的用户参数属于域pipe理员。
  • 当我远程运行脚本时,脚本会报告成功。 没有错误被看见。

我完全难以理解为什么使用远程WMI调用不同参数的脚本不起作用。 我花了几个小时的search,没有find一个合适的答案。

下面是我用来创build我连接到远程机器的作用域的方法:

 public static ManagementScope CreateScope() { string nameSpace = @"\\" + Parameters.FQDN + @"\root\cimv2"; ManagementPath path = new ManagementPath(nameSpace); ConnectionOptions Connection = new ConnectionOptions(); Connection.Username = Parameters.User; // Username value includes the domain Connection.Password = Parameters.Password; Connection.Impersonation = ImpersonationLevel.Impersonate; return new ManagementScope(path, Connection); } 

任何人都可以告诉我,为什么第二个命令行不是作为默认打印机在远程机器上设置打印机?

希望这可以帮助。 我建议你在运行时使用你的两个命令创建一个批处理文件,并以这种方式创建一个进程。 但现在测试最后的命令,你有这样的麻烦:

 string Command = @"cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -t -p Test002"; ManagemenConnectionOptions connOptions = new ConnectionOptions(); connOptions.Impersonation = ImpersonationLevel.Impersonate; connOptions.EnablePrivileges = true; tScope manScope = new ManagementScope (String.Format(@"\\{0}\ROOT\CIMV2", Parameters.FQDN), connOptions); manScope.Connect(); ObjectGetOptions objectGetOptions = new ObjectGetOptions(); ManagementPath managementPath = new ManagementPath("Win32_Process"); ManagementClass processClass = new ManagementClass (manScope, managementPath, objectGetOptions); ManagementBaseObject inParams = processClass.GetMethodParameters("Create"); inParams["CommandLine"] = Command; ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null); Console.WriteLine("Creation of the process returned: " + outParams["returnValue"]); Console.WriteLine("Process ID: " + outParams["processId"]);