1

我正在尝试使用 Windows API 函数 AddPrinterDriver 添加打印机驱动程序。始终生成 Win32 错误 1008(尝试引用不存在的令牌。)。我的代码如下所示

[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);

在添加打印机驱动程序之前,我还尝试通过“ImpersonateSelf”获取令牌。但错误 1008 坚持。

4

0 回答 0