【问题标题】:Can't install driver with printui. Is this because the driver certificate expired?无法使用 printui 安装驱动程序。这是因为驱动程序证书过期了吗?
【发布时间】:2014-07-03 13:52:10
【问题描述】:

我想用 printui 安装虚拟打印机驱动程序,但我得到“无法完成操作(错误 0x00000002)”(操作系统为 Win7 x64)。这是因为用于签署驱动程序的证书已过期吗?还是有其他原因?如果是,那么我怎样才能获得有关错误的更多信息(我不是 C 程序员)?

这里是安装驱动的代码:

int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
    if (wcsstr(lpCmdLine, L"/chkxps"))
    {
        if (!PrinterExists(L"Microsoft XPS Document Writer"))
        {
            DispError(L"A MediSmart ePrinter nem telepíthető, mivel nem található XPS nyomtató a rendszerben");
            return -10;
        }
        return 0;
    }


    LPWSTR printername = L"MediSmart ePrinter";
    LPWSTR printername1 = L"MediSmart ePrinter - HealthFund";
    LPWSTR printername2 = L"MediSmart ePrinter - B2B Electronic";
    LPWSTR printername3 = L"MediSmart ePrinter - B2B Paper based";
    LPWSTR portname = L"NUL:";

    bool inst = wcsstr(lpCmdLine, L"/uninst") == NULL;

    if (inst)
    {
        PRINTER_DEFAULTS pdef;
        pdef.pDatatype = NULL;
        pdef.pDevMode = NULL;
        pdef.DesiredAccess = SERVER_ACCESS_ADMINISTER;

        DWORD oneed;
        DWORD err;

        HANDLE hxcv;
        if (!OpenPrinter(L",XcvMonitor Local Port", &hxcv, &pdef))
        {
            DispError(L"A virtuális nyomtató port létrehozása nem sikerült");
            return -1;
        }
        XcvData(hxcv, L"AddPort", (LPBYTE)portname, (wcslen(portname) + 1)*2, NULL, NULL, &oneed, &err);
        ClosePrinter(hxcv);
        if (err && err != ERROR_ALREADY_EXISTS)
        {
            DispError(L"A virtuális nyomtató port létrehozása nem sikerült");
            return -2;
        }
    }

    //TODO ez nem lesz igy jo, ha majd drivert akarunk frissiteni
    if (!inst || !PrinterExists(printername))
    {
        typedef void (CALLBACK *RunDllEntry)(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow);

        HMODULE hmod = LoadLibrary(L"printui.dll");
        if (!hmod)
        {
            DispError(L"A virtuális nyomtatót nem sikerült telepíteni: a printui.dll nem található");
            return -3;
        }
        RunDllEntry entry = (RunDllEntry)GetProcAddress(hmod, "PrintUIEntryW");
        if (!entry)
        {
            FreeLibrary(hmod);
            DispError(L"A virtuális nyomtatót nem sikerült telepíteni: hibás printui.dll");
            return -3;
        }
        WCHAR cmd[1000];
        if (inst)
        {
            wsprintf(cmd, L"/if /m \"%s\" /r \"%s\" /f \"%s\\mseprinter.inf\"", printername, portname, lpCmdLine);
            entry(NULL, hmod, cmd, SW_SHOW);
            wsprintf(cmd, L"/if /m \"%s\" /r \"%s\" /f \"%s\\mseprinter_hf.inf\"", printername1, portname, lpCmdLine);
            entry(NULL, hmod, cmd, SW_SHOW);
            wsprintf(cmd, L"/if /m \"%s\" /r \"%s\" /f \"%s\\mseprinter_b2bel.inf\"", printername2, portname, lpCmdLine);
            entry(NULL, hmod, cmd, SW_SHOW);
            wsprintf(cmd, L"/if /m \"%s\" /r \"%s\" /f \"%s\\mseprinter_b2bpb.inf\"", printername3, portname, lpCmdLine);
            entry(NULL, hmod, cmd, SW_SHOW);
        }
        else
        {
            wsprintf(cmd, L"/dl /n \"%s\"", printername);
            entry(NULL, hmod, cmd, SW_SHOW);
            wsprintf(cmd, L"/dl /n \"%s\"", printername1);
            entry(NULL, hmod, cmd, SW_SHOW);
            wsprintf(cmd, L"/dl /n \"%s\"", printername2);
            entry(NULL, hmod, cmd, SW_SHOW);
            wsprintf(cmd, L"/dl /n \"%s\"", printername3);
            entry(NULL, hmod, cmd, SW_SHOW);
        }
        FreeLibrary(hmod);
    }

    #ifndef _DEBUG
    if (inst)
        RemoveDirectoryTree(lpCmdLine);
    #endif

    return 0;
}

【问题讨论】:

  • Win32 错误代码 0x00000002 = ERROR_FILE_NOT_FOUND:“系统找不到指定的文件。”。但是您既没有指定返回错误代码的函数。
  • @Gonmator:哦,谢谢。当我搜索“无法完成操作(错误 0x00000002)”时,我只收到与打印机相关的错误
  • 您可以查看系统错误代码列表here。我猜错误在XcvData()?确保portname 正确,然后尝试从(wcslen(portname) + 1)*2 中删除+ 1
  • @jliv902:谢谢。抱歉,忘记指定错误在哪一行。在 4 次调用中:entry(NULL, hmod, cmd, SW_SHOW);

标签: c++ printing driver


【解决方案1】:

我找到了答案:我必须使用指定路径的命令参数运行它...

【讨论】:

  • 只是补充,运行 printui 来安装没有有效或过期证书的驱动程序将提示一个窗口,要求确认对驱动程序提供商的信心。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-09
  • 1970-01-01
  • 1970-01-01
  • 2013-06-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多