AddPrinterDriver因ERROR_ACCESS_DENIED而失败

时间:2012-01-18 16:09:31

标签: c++ windows winapi printing

在几台计算机上,对AddPrinterDriver的调用因ERROR_ACCESS_DENIED而失败。我的程序确保以管理员权限运行,并将驱动程序DLL复制到C:\ WINDOWS中,没有任何错误(访问被拒绝或其他)。

// structure for AddPrinterDriver
DRIVER_INFO_3 di3 = { 0 };
di3.cVersion = 3;
di3.pName = _T(MyAppPrinterName) _T(" Driver");
di3.pDefaultDataType = _T("");
// path to driver dll
FilePath file1(strDriverDirectory.c_str());
di3.pDriverPath = (LPTSTR) file1.Append(MyAppPrinterDriverDllFileName).ToString();
// path to driver ui dll
FilePath file2(strDriverDirectory.c_str());
di3.pConfigFile = (LPTSTR) file2.Append(MyAppPrinterUiDllFileName).ToString();
// path to license file
FilePath file3(strDriverDirectory.c_str());
di3.pDataFile = (LPTSTR) file3.Append(_T(MyAppPrinterName) _T(".dat")).ToString();

// add driver
bResult = AddPrinterDriver(NULL, 3, (LPBYTE) &di3);
StoreLastError(_T("AddPrinterDriver"));
if (!bResult)
    return FALSE;

这是我的DrvPrinterEvent函数:

BOOL DrvPrinterEvent(
                    LPWSTR  lpwstrPrinterName,
                    INT     iEvent,
                    DWORD   dwFlags,
                    LPARAM  lParam
                    )
{
    return TRUE;
}

0 个答案:

没有答案