DelphiFAQ Home Search:

Change the windows default printer


commentsThis article has not been rated yet. After reading, feel free to leave comments and rate it.

The following code changes the default printer. Attention - this is a systemwide change and will affect other applications. Since this is discouraged, do it only if you have a really good reason.

program dummy;

// sample code by Peter Below

  Device: array [0..255] of Char;
  Driver: array [0..255] of Char;
  Port: array [0..255] of Char;
  hDeviceMode: THandle;

  Printer.PrinterIndex := 1; {select printer to make default}
  Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
  StrCat(Device, ',');
  StrCat(Device, Driver);
  StrCat(Device, ',');
  StrCat(Device, Port);
  WriteProfileString('windows', 'device', Device);
  StrCopy(Device, 'windows');
  SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, longint(@Device))
You don't like the formatting? Check out SourceCoder then!


2011-10-27, 11:11:10
anonymous from United Kingdom  



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: