Ejemplo n.º 1
0
        private void RemoveJobs(String printerName)
        {
            IntPtr hPrinter;

            PrinterMonitorInstallerPInvoke.PRINTER_DEFAULTS defaults = new PrinterMonitorInstallerPInvoke.PRINTER_DEFAULTS
            {
                DesiredAccess = 0x000F000C, //PRINTER_ALL_ACCESS
                pDatatype     = IntPtr.Zero,
                pDevMode      = IntPtr.Zero
            };


            if (PrinterMonitorInstallerPInvoke.OpenPrinter(printerName, out hPrinter, ref defaults) == false)
            {
                int errno = Marshal.GetLastWin32Error();
                throw new Win32Exception(errno);
            }

            if (hPrinter == IntPtr.Zero)
            {
                int errno = Marshal.GetLastWin32Error();
                throw new Win32Exception(errno);
            }

            //3 == PRINTER_CONTROL_PURGE => Entfernt alle Jobs!
            if (PrinterMonitorInstallerPInvoke.SetPrinter(hPrinter, 0, IntPtr.Zero, PrinterMonitorInstallerPInvoke.PRINTER_CONTROL_PURGE) == false)
            {
                int errno = Marshal.GetLastWin32Error();
                throw new Win32Exception(errno);
            }

            if (PrinterMonitorInstallerPInvoke.ClosePrinter(hPrinter) == false)
            {
                int errno = Marshal.GetLastWin32Error();
                throw new Win32Exception(errno);
            }
        }
Ejemplo n.º 2
0
        private void UninstallPrinter(String printerName)
        {
            IntPtr hPrinter;

            PrinterMonitorInstallerPInvoke.PRINTER_DEFAULTS defaults = new PrinterMonitorInstallerPInvoke.PRINTER_DEFAULTS
            {
                DesiredAccess = 0x000F000C,  //PRINTER_ALL_ACCESS
                pDatatype     = IntPtr.Zero,
                pDevMode      = IntPtr.Zero
            };


            if (PrinterMonitorInstallerPInvoke.OpenPrinter(printerName, out hPrinter, ref defaults) == false)
            {
                int errno = Marshal.GetLastWin32Error();
                throw new Win32Exception(errno);
            }

            if (hPrinter == IntPtr.Zero)
            {
                int errno = Marshal.GetLastWin32Error();
                throw new Win32Exception(errno);
            }

            if (PrinterMonitorInstallerPInvoke.DeletePrinter(hPrinter) == false)
            {
                int errno = Marshal.GetLastWin32Error();
                throw new Win32Exception(errno);
            }

            if (PrinterMonitorInstallerPInvoke.ClosePrinter(hPrinter) == false)
            {
                int errno = Marshal.GetLastWin32Error();
                throw new Win32Exception(errno);
            }
        }