Exemple #1
0
        public GenericResult AddPrinterDriver(string driverName, string driverPath, string dataPath, string configPath, string helpPath)
        {
            GenericResult retVal = new GenericResult("AddPrinterDriver");
            DRIVER_INFO_3 di     = new DRIVER_INFO_3();

            di.cVersion         = 3;
            di.pName            = driverName;
            di.pEnvironment     = null;
            di.pDriverPath      = driverPath;
            di.pDataFile        = dataPath;
            di.pConfigFile      = configPath;
            di.pHelpFile        = helpPath;
            di.pDependentFiles  = "";
            di.pMonitorName     = null;
            di.pDefaultDataType = "RAW";

            try
            {
                if (AddPrinterDriver(null, 3, ref di) == 0)
                {
                    retVal.Exception = new Win32Exception(Marshal.GetLastWin32Error());
                    retVal.Message   = retVal.Exception.Message;
                }
            }
            catch (Exception ex)
            {
                retVal.Exception = ex;
                retVal.Message   = retVal.Exception.Message;
            }
            if (string.IsNullOrWhiteSpace(retVal.Message))
            {
                retVal.Success = true;
            }
            return(retVal);
        }
Exemple #2
0
        public void AddPrinterDriver(string driverName,
                                     string driverFileMain,
                                     string driverFileData,
                                     string driverFileConfig,
                                     string driverFileHelp,
                                     string driverFileDependencies)
        {
            var di = new DRIVER_INFO_3
            {
                cVersion         = 3,
                pName            = driverName,
                pEnvironment     = null,
                pDriverPath      = driverFileMain,
                pDataFile        = driverFileData,
                pConfigFile      = driverFileConfig,
                pHelpFile        = driverFileHelp,
                pDependentFiles  = driverFileDependencies,
                pMonitorName     = null,
                pDefaultDataType = "RAW"
            };

            if (AddPrinterDriver(null, 3, ref di) == 0)
            {
                throw new Win32Exception(Marshal.GetLastWin32Error());
            }
        }
Exemple #3
0
        public static void Install()
        {
            string driverDir;

            try { driverDir = GetPrinterDriverDirectory(); }
            catch { driverDir = DEFAULT_DRIVER_DIR; }
            DRIVER_INFO_3 di = new DRIVER_INFO_3();

            di.cVersion         = 3;
            di.pName            = NAME;
            di.pEnvironment     = null;
            di.pDriverPath      = driverDir + DRIVER_FILENAME;
            di.pDataFile        = driverDir + DATA_FILENAME;
            di.pConfigFile      = driverDir + CONFIG_FILENAME;
            di.pHelpFile        = driverDir + HELP_FILENAME;
            di.pDependentFiles  = "";
            di.pMonitorName     = null;
            di.pDefaultDataType = "RAW";
            try
            {
                if (!AddPrinterDriver(null, 3, ref di))
                {
                    int errorCode = Marshal.GetLastWin32Error();
                    if (errorCode != ERROR_PRINTER_DRIVER_ALREADY_INSTALLED)
                    {
                        throw new Win32Exception(Marshal.GetLastWin32Error());
                    }
                }
            }
            catch { throw; }
        }
Exemple #4
0
 private static extern int AddPrinterDriver(string pName, uint Level, ref DRIVER_INFO_3 pDriverInfo);
Exemple #5
0
 private static extern Int32 AddPrinterDriver(String pName, UInt32 Level, ref DRIVER_INFO_3 pDriverInfo);
Exemple #6
0
 private static extern Int32 AddPrinterDriver(String pName, UInt32 Level, ref DRIVER_INFO_3 pDriverInfo);
Exemple #7
0
 public void AddPrinterDriver(string driverName, string driverPath, string dataPath, string configPath, string helpPath)
 {
     DRIVER_INFO_3 di = new DRIVER_INFO_3();
     di.cVersion = 3;
     di.pName = driverName;
     di.pEnvironment = null;
     di.pDriverPath = driverPath;
     di.pDataFile = dataPath;
     di.pConfigFile = configPath;
     di.pHelpFile = helpPath;
     di.pDependentFiles = "";
     di.pMonitorName = null;
     di.pDefaultDataType = "RAW";
     if (AddPrinterDriver(null, 3, ref di) == 0)
     {
         throw new Win32Exception(Marshal.GetLastWin32Error());
     }
 }