Here are the PrintUI commands that I use.  I would test your parameters on a
target machine in a admin CMD box prior to integrating into a msi.
        LPWSTR pwzAddPrinterCommand = L"\"%lsRunDll32.exe\"
PrintUI.dll,PrintUIEntry /if /b \"%ls\" /f \"%ls\" /r %ls /m \"%ls\" /u /q
/z /Gw";
        LPWSTR pwzDelPrinterCommand = L"\"%lsRunDll32.exe\"
PrintUI.dll,PrintUIEntry /dl /n \"%ls\" /q /Gw";
        LPWSTR pwzDelDriverCommand = L"\"%lsRunDll32.exe\" 
PrintUI.dll,PrintUIEntry
/dd /m \"%ls\" /q /Gw";


Snippet of deferred CA code that uses the above commands.  While this is
working the driver is not in the driver store and I have yet to work on a
DifxApi solution.  There is other refactoring that I am in the process of
doing to extension project.
        switch (iOperation)
        {
                case WCA_TODO_INSTALL:
        case WCA_TODO_REINSTALL:
                        fDoQuietExec = true;
                        hr = RegOpen(HKEY_LOCAL_MACHINE, pwzPrinterKey, 
KEY_QUERY_VALUE,
&hkPrinter);
                        if (ERROR_SUCCESS == hr) {
                                /*If the printer exsts, skip calling the 
'install' command on PrintUI
api to avoid creating another printer*/
                                WcaLog(LOGMSG_VERBOSE, "Printer exists, so skip 
calling install
action.\nPrinter Key: %ls\n", pwzPrinterKey);
                                fDoQuietExec = false;
                                break;
                        }

                        if (true == fDoQuietExec) {
                                hr = StrAllocFormatted(&pwzCommand, 
pwzAddPrinterCommand, pwzSystemPath,
pwzModel, pwzInfPath, pwzPort, pwzName);
                                ExitOnFailure(hr, "failed to format the command 
to install a printer");

                                hr = QuietExec(pwzCommand, dwTimeout);
                                ExitOnFailure1(hr, "QuietExec failed to execute 
install command, %ls,
and may have timed out.", pwzCommand);
                        }
            break;
        case WCA_TODO_UNINSTALL:
                        //uninstalling so look for printers with names which 
include our printer
name.  Typically 'printer name (Copy 1)'
                        hr = RegOpen(HKEY_LOCAL_MACHINE, pwzPrintersKey, 
KEY_READ, &hkPrinters);
                        ExitOnFailure1(hr, "Failed to open the Windows Printers 
key: %ls, ",
pwzPrintersKey);

                        for (DWORD dwIndex = 0; /* exit via break below */; 
++dwIndex)
                        {
                                ReleaseNullStr(pwzPrinterObject);
                                hr = RegKeyEnum(hkPrinters, dwIndex, 
&pwzPrinterObject);
                                if (E_NOMOREITEMS == hr)
                                {
                                        hr = S_OK;
                                        break;
                                }
                                ExitOnFailure(hr, "Failed to enumerate printer 
objects.");

                                if (NULL == wcsistr(pwzPrinterObject, pwzName)) 
{
                                        //WcaLog(LOGMSG_VERBOSE, "RegKeyEnum 
returned %ls, which is not of any
interest to us.  Look for another printer.", pwzPrinterObject);
                                        continue;
                                }

                                //create a list of printers with similar name, 
to remove later
                                hr = WcaWriteStringToCaData(pwzPrinterObject, 
&pwzRelatedPrinters);
                                ExitOnFailure2(hr, "failed to add printer ( %ls 
) to the list: %ls",
pwzPrinterObject, pwzId);

                                cPrinters++;
                        }

                        ReleaseNullStr(pwz);
                        pwz = pwzRelatedPrinters;
                        while (pwz && *pwz)
                        {
                                ReleaseNullStr(pwzPrinterObject);
                                hr = WcaReadStringFromCaData(&pwz, 
&pwzPrinterObject);
                                ExitOnFailure(hr, "failed to read related 
printer name from related
printer list.");

                                //remove this printer
                                ReleaseNullStr(pwzCommand);
                                hr = StrAllocFormatted(&pwzCommand, 
pwzDelPrinterCommand, pwzSystemPath,
pwzPrinterObject);
                                ExitOnFailure(hr, "failed to format the command 
to remove a printer");

                                hr = QuietExec(pwzCommand, dwTimeout);
                                ExitOnFailure1(hr, "QuietExec failed to execute 
uninstall printer
command, %ls, and may have timed out.", pwzCommand);

                                // Tick the progress bar along
                                hr = WcaProgressMessage(COST_RDPPRINTERS, 
FALSE);
                                ExitOnFailure1(hr, "failed to tick progress bar 
for printer instance:
%ls", pwzId);
                        }

                        //Remove the printer driver
                        ReleaseNullStr(pwzCommand);
                        hr = StrAllocFormatted(&pwzCommand, 
pwzDelDriverCommand, pwzSystemPath,
pwzModel);
                        ExitOnFailure(hr, "failed to format the command to 
remove a printer
driver");

                        hr = QuietExec(pwzCommand, dwTimeout);
                        ExitOnFailure1(hr, "QuietExec failed to execute 
uninstall driver command,
%ls, and may have timed out.", pwzCommand);

                        break;
        } //switch (iOperation)



--
View this message in context: 
http://windows-installer-xml-wix-toolset.687559.n2.nabble.com/Installing-HP-LaserJet-4-Printer-Driver-on-FILE-instead-of-LPT1-tp7593244p7593284.html
Sent from the wix-users mailing list archive at Nabble.com.

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech
_______________________________________________
WiX-users mailing list
WiX-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wix-users

Reply via email to