PrintTestPage from C # on Windows Vista
I have a very strange problem when printing a test page after installing the printer on the network. Everything works very well and when you run the "Admin" code ... a test page is also printed. But when I run the program "normally" I get "Access Denied".
So here's the code:
// get the printer
string path = "Win32_Printer.DeviceId='" + printerName + "'";
using (ManagementObject printer = new ManagementObject(path))
{
// invoke the method
object obj = printer.InvokeMethod("PrintTestPage", null);
System.Windows.Forms.MessageBox.Show(obj.ToString());
}
obj is always 5, which means "Access Denied".
When I call the "SetDefaultPrinter" method in the same way, everything is fine for the administrator and not for him.
Hopefully anyone has the key.
Thanks Simon
I decided. I found another piece of code that does the same and works in both contexts.
WshShell shell = new WshShell (); string command = "RUNDLL32 PRINTUI.DLL, PrintUIEntry / k / n \" "+ printerInfo.PrinterName +" \ ""; object windowStyle = null; object waitOnReturn = null; shell.Run (command, ref windowStyle, ref waitOnReturn);
So what is it. Thanks anyway.
Cheers, Simon