Link to home
Start Free TrialLog in
Avatar of daniel_c
daniel_c

asked on

Set default printer

How to set available printers in Windows to default from Delphi?
Avatar of ZifNab
ZifNab

Euhm, changing the PrinterIndex property?
eg

if (MessageDlg('Do you want to use the default printer',
                               mtInformation, mbYesNoCancel,0)=idYes) then
                                 Printer.PrinterIndex := -1;

 To switch another printer , set the aproprieted index to it .
You can write to register



[HKEY_LOCAL_MACHINE\Config\0001\System\CurrentControlSet\Control\Print\Printers]
"Default"="xxxxx"



[HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Print\Printers]
"Default"="xxxxx"

Set xxxxx to your  printer. but select only the installed printer’s to default.
You can test if a printer is install before you set it to default
just read the key’s under Printers in register.

If it is in a network with a lot of computers you can do like I did.

I dump all  Mac address to a file and filed with default ,ComputerName & printer..

I make I program that compare MAC from computer and file.
And then set the value’s to register and reboot the computer if it is wrong value’s

So now wen I ghost all 300 computer I don’t need to go to all to set Name and default printer.
The user that login first set the right value
That won't set the default WINDOWS printer, only the printer currently being used in the Delphi app. God knows how you actually modify THAT

To expand on what ZifNab has said, you can get the complete list of printer NAMES by accessing the Printers property of the TPrinter object.

ListBox1.Itesm.Assign(Printer.Printers);

It's then just a case of setting the PrinterIndex property to the item selected by the user (which is what ZifNab said)

The Neil
Avatar of daniel_c

ASKER

If I use Printer Index, whereas, I use combo box which contains the available printers, how do I know that...
for instance, HP Laser 1100 is 1, Epson LQ 1070 is 2, and so on?
ASKER CERTIFIED SOLUTION
Avatar of TheNeil
TheNeil

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Neil!
Thanks Tom!

I wish I can give point to both of you!