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.