I am using WMI to connect to my lab machine as a domain admin. I then run this command line to create a printer:
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -a -p Test002 -m "Canon Inkjet iP100 series" -r FAKE002
That works fine.
I then run this command line to set the printer as the default:
cscript C:\Windows\System32\Printing_Admin_Scripts\en-US\prnmngr.vbs -t -p Test002
That doesn't work at all.
Some pertinent details:
- Both command lines are executed by the same method
- The second command line works fine if I run it through WMI with a local scope
- The user I am running the script with has admin rights on the machine and can set the default printer manually
- The user parameters I am creating the remote scope with belong to a domain admin.
- The script reports success when I run it remotely. No errors are seen.
I am completely stumped as to why the same script with different parameters doesn't work when called using remote WMI. I spent several hours searching and did not find an adequate answer.
Here is the method I am using to create the scope I am connecting to the remote machine with:
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);
}
Can anyone tell me why the second command line is not setting the printer on the remote machine as the default printer?