Author: Mike Shkolnik
How can I change the default printer in Windows?
Answer:
If you want to change the the default printer in Windows OS, you must change the
device key in the Windows section of the WIN.INI. After that you must send a
WM_WININICHANGE message:
1 var2 strIni: array[0..MAX_PATH] of Char;
3 arrWindows: array[0..64] of Char;
4 begin5 GetWindowsDirectory(strIni, SizeOf(strIni));
6 StrCat(strIni, '\win.ini');
7 with TIniFile.Create(strIni) do8 try9 WriteString('windows', 'device', 'HP LaserJet 4 Plus,HPPCL5MS,LPT1:');
10 finally11 Free;
12 end;
13 14 StrCopy(arrWindows, 'windows');
15 SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@arrWindows));
16 end;