ndbrazerzkidai.blogg.se

How to change default printer in registry
How to change default printer in registry











how to change default printer in registry
  1. #HOW TO CHANGE DEFAULT PRINTER IN REGISTRY PDF#
  2. #HOW TO CHANGE DEFAULT PRINTER IN REGISTRY INSTALL#
  3. #HOW TO CHANGE DEFAULT PRINTER IN REGISTRY UPDATE#
  4. #HOW TO CHANGE DEFAULT PRINTER IN REGISTRY PRO#

To resolve this issue in Windows 7 SP1 or Windows Server 2008 R2 SP1, install the hotfix that is described in this article.

#HOW TO CHANGE DEFAULT PRINTER IN REGISTRY UPDATE#

To resolve this issue in Windows RT 8.1, Windows 8.1, or Windows Server 2012 R2, install update rollup 2955164. These values will be set in the service account's profile rather than in the impersonated user's profile. This issue occurs because when the impersonated user calls SetDefaultPrinter to set a default printer, some registry values may be set in the wrong user profile. When a service on the computer impersonates a user and then calls SetDefaultPrinter to set a default printer, you find the default printer is set to a wrong printer rather than to the expected one. Less SymptomsĪssume that you have a computer that is running Windows 8.1, Windows RT 8.1, Windows Server 2012 R2, Windows 7 Service Pack 1 (SP1), or Windows Server 2008 R2 SP1.

#HOW TO CHANGE DEFAULT PRINTER IN REGISTRY PRO#

Here is the code that works fine for me.Windows 8.1 Enterprise Windows 8.1 Pro Windows 8.1 Windows RT 8.1 Windows Server 2012 R2 Datacenter Windows Server 2012 R2 Essentials Windows Server 2012 R2 Foundation Windows Server 2012 R2 Standard Windows 7 Service Pack 1 Windows 7 Enterprise Windows 7 Home Basic Windows 7 Home Premium Windows 7 Professional Windows 7 Ultimate Windows Server 2008 R2 Service Pack 1 Windows Server 2008 R2 Datacenter Windows Server 2008 R2 Enterprise Windows Server 2008 R2 Standard Windows Server 2008 R2 for Itanium-Based Systems More.

how to change default printer in registry

So, I tried to simply write the SetDefaultPrinter as local function and then no hang occours. I also tried to use the "SendMessage( HWND_BROADCAST, WM_WININICHANGE, 0,LongInt(cs1))" code block and my program was hang. Writeln(Format('EOleException %s %x', )) SetDefaultPrinter('HP LaserJet') //here you must pass the DeviceID of one the printers listed above Result:=FWbemObject.SetDefaultPrinter()=0 Writeln(Format('DeviceID %s Name %s',)) įunction SetDefaultPrinter(const DeviceID:string):boolean įWbemObject := FWMIService.Get(Format('Win32_Printer.DeviceID="%s"',)) While oEnum.Next(1, FWbemObject, iValue) = 0 do OEnum := IUnknown(FWbemObjectSet._NewEnum) as IEnumVariant įSWbemLocator := CreateOleObject('WbemScripting.SWbemLocator') įWMIService := FSWbemLocator.ConnectServer('localhost', 'root\CIMV2', '', '') įWbemObjectSet:= FWMIService.ExecQuery('SELECT DeviceID, Name FROM Win32_Printer','WQL',wbemFlagForwardOnly)

how to change default printer in registry

Try using the Win32_Printer WMI class to list the printers and the SetDefaultPrinter method to set the default printer.

#HOW TO CHANGE DEFAULT PRINTER IN REGISTRY PDF#

The goal is to change the default printer to the selected printer in order to print the pdf to the desired printer and then return the printer to the original default on exit of the application The print job is actually a PDF being printed using ShellExecute(Application.Handle, 'print', PChar(sPath), nil, nil, SW_HIDE)

how to change default printer in registry

It's a piece of code I picked up while searching for a solution to my problem. SendMessage( HWND_BROADCAST, WM_SETTINGCHANGE, 0,LongInt(cs1)) Īnyone have any tips or a better way to do this?Īs a side note this is not my function. SendMessage( HWND_BROADCAST, WM_WININICHANGE, 0,LongInt(cs1)) WriteProfileString( cs1, cs2, pchar( s2 )) While GetProfileString( cs1, cs2, cs4, dum1, xx) > 0 do S2 := PrinterName + ',' + strpas( dum1 ) If (qq > 0) and (trim( strpas( dum1 )) '') then Qq := GetProfileString( cs3, pchar( PrinterName ), #0, dum1, xx) Printername is bv: '\\MYPRINTER\HP5-k' function TMainFrm.SetDefaultPrinter(const PrinterName: string): boolean However the program becomes unresponsive without any errors or program not responding messages when this line of code executes: SendMessage( HWND_BROADCAST, WM_WININICHANGE, 0,LongInt(cs1)) I am trying to use the below code to change the default printer and then my print code will print to that printer. I use "Printers" to get the printer index but the actual printing is done with proprietary print code that allows for direct to pdf printing and easier page layout. I am attempting to change the default printer in the on change event of a combo box that list the printer index.













How to change default printer in registry