Wiki

Case Status
Log In

Wiki

 
Using PrintUI.dll to change to…
  • RSS Feed

Last modified on 01/07/2015 14:27 by User.

Using PrintUI.dll to change to printer configuration

  • To connect a printer "globally" (ie not per-user) to a machine:
    rundll32 printui.dll PrintUIEntry /ga /n\\<HOSTNAME>\<PRINTER SHARENAME>
  • To delete a "globally-connected" printer:
    rundll32 printui.dll PrintUIEntry /gd /n\\<HOSTNAME>\<PRINTER SHARENAME>
  • To make Kappris the default printer:
    rundll32 printui.dll,PrintUIEntry /n Kappris /y
  • Install the "Kappris XPS" driver and create a printer instance connected to KXPS: that uses the new driver:
    rundll32 printui.dll PrintUIEntry /if /f kxpsdrv.inf /r "KXPS:" /m "Kappris XPS"
  • Delete the local printer named "Kappris XPS"
    rundll32 printui.dll PrintUIEntry /dl /n "Kappris XPS"
  • Delete the driver named "Kappris XPS"
    rundll32 printui.dll PrintUIEntry /dd /m "Kappris XPS"

Using these commands is much faster than using the Add Printer Wizard or the Print Server Properties UI or the PrintManagement msc plugin.

If you need to call the PrintUI methods from code rather than invoking them from a command-line, you can do this sort of thing. The thing to note is that PrintUIEntry expects four arguments, one one of them being the command line you'd utter if you were invoking via rundll32:

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
typedef void (CALLBACK *FNTYPE_CallPrintUIEntry)(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow);

BOOL KInstaller::CallPrintUIEntry(LPTSTR lpCmdLine)
{
	BOOL bSucceeded = TRUE;
	HMODULE hDLL;
	FNTYPE_CallPrintUIEntry fn = 0;

	if ((hDLL = LoadLibrary(TEXT("printui.dll"))) == NULL)
	{
		bSucceeded = FALSE;
	}

	if (bSucceeded)
	{
		fn = (FNTYPE_CallPrintUIEntry)GetProcAddress(hDLL, "PrintUIEntryW");
		if (fn == 0)
		{
			bSucceeded = FALSE;
		}
	}

	if (bSucceeded)
	{
		(*fn)(NULL, hDLL, lpCmdLine, SW_SHOW);
			// (TEXT("/if /f kxpsdrv.inf /r \"KXPS:\" /m \"Kappris XPS\""));
	}

	// Tidy Up.
	//
	if (hDLL != 0)
	{
		FreeLibrary(hDLL);
	}
	
	return bSucceeded;
}