Exemplo n.º 1
0
        private void InstallPrinter(String printerName, String printerPortName, String printerDriverName)
        {
            PrinterMonitorInstallerPInvoke.PRINTER_INFO_2 pInfo = new PrinterMonitorInstallerPInvoke.PRINTER_INFO_2
            {
                pPrinterName    = printerName,
                pPortName       = printerPortName,
                pDriverName     = printerDriverName,
                pPrintProcessor = "WinPrint",
                pShareName      = printerName,
                pDatatype       = "RAW",
                pComment        = printerName,
                Priority        = 1,
                DefaultPriority = 1
            };


            IntPtr hPrt = PrinterMonitorInstallerPInvoke.AddPrinter("", 2, ref pInfo);

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

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