Question : Example on How to use AddPrinterDriver or AddPrinterDriverEx with C#?

Hello Experts,

I'm looking for an example on how to use AddPrinterDriver or AddPrinterDriverEx to install a printer driver that already ships with windows 7 (i.e HP 910).

Thanks.

Answer : Example on How to use AddPrinterDriver or AddPrinterDriverEx with C#?

Thanks for the reply, this is written in VB not C#, however, i was trying to write something and still having problems:

[DllImport("winspool.drv", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
        static extern int AddPrinterDriver(string pName, uint Level, [In] ref DRIVER_INFO_3 pDriverInfo);

 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
        public struct DRIVER_INFO_3
        {
            public IntPtr cVersion;
            public string pName;
            public string pEnvironment;
            public string pDriverPath;
            public string pDataFile;
            public string pConfigFile;
            public string pHelpFile;
            public string pDependentFiles;
            public string pMonitorName;
            public string pDefaultDataType;
        }

public static void AddPrinter()
{
  DRIVER_INFO_3 dInfo = new DRIVER_INFO_3
            {
                pConfigFile = "UNIDRVUI.DLL",
                pDataFile = "HPW100T.GPD",
                pHelpFile = "UNIDRV.HLP",
                pName = "HP Business Inkjet 1000",
               
               
            };

            if (AddPrinterDriver(name, 3, ref dInfo) == 0)
                throw new Win32Exception(Marshal.GetLastWin32Error());
}

This code always throw Access Denied Exception.
Random Solutions  
 
programming4us programming4us