Error_No_Token by adding printer driver (c#)
Posted
by
user1686388
on Stack Overflow
See other posts from Stack Overflow
or by user1686388
Published on 2012-09-20T15:35:50Z
Indexed on
2012/09/20
15:37 UTC
Read the original article
Hit count: 244
I'm trying to add printer drivers using the windows API function AddPrinterDriver. The Win32 error 1008 (An attempt was made to reference a token that does not exist.) was always generated. My code is shown as following
[DllImport("Winspool.drv")]
static extern bool AddPrinterDriver(string Name, Int32 Level, [in] ref DRIVER_INFO_3 DriverInfo);
[StructLayout(LayoutKind.Sequential)]
public struct DRIVER_INFO_3
{
public Int32 cVersion;
public string Name;
public string Environment;
public string DriverPath;
public string DataFile;
public string ConfigFile;
public string HelpFile;
public string DependentFiles;
public string MonitorName;
public string DefaultDataType;
}
//.......................
DRIVER_INFO_3 di = new DRIVER_INFO_3();
//......................
AddPrinterDriver(Environment.MachineName, 3, ref di);
I have also tried to get a token by "ImpersonateSelf" before adding the printer driver. But the error 1008 insists. Does anyone have an idea?
best regards.
© Stack Overflow or respective owner