Product SiteDocumentation Site

8.86. SysWinSetDefaultPrinter (Windows only)


>>-SysWinSetDefaultPrinter(description)------------------------><

Sets the default printer.
Parameter:
description
A string identifying the printer. On Windows 2000 or later this string can be just the printer name. For earlier versions of Windows, the string must have the form "Printername,Drivername,Portname".

Note

For Windows 2000 or later either form of the description string is accepted. However, using just the printer name is the preferred method. Using the "Printername,Drivername,Portname" form will invoke an outdated Windows API that Microsoft has deprecated.
Return codes:
0
Success
non-zero
A Windows System Error code (Section 8.1, “A Note on Error Codes”). You can use SysGetErrortext() to get a description of the error.

Example 8.47. RexxUtil - SysWinGetPrinters and SysWinGetDefaultPrinter


/* set default printer */

default = SysWinGetDefaultPrinter()
parse var default default",".
say 'The Default printer is:' default
say

if SysWinGetPrinters(list.) == 0 then do
  say "List of available printers (* = default):"
  do i=1 to list.0
    parse var list.i pname",".
    if pname == default then
      say i list.i "*"
    else
      say i list.i
  end
  say
  say "Please enter number of new default printer (0 = keep default)"
  pull i

  numberOk = .false

  if i~datatype('W') then do
    if 0 <= i & i <= list.0 then do
      numberOK = .true

      if i > 0 then do
        /* Assumes we are on Windows 2000 or later. */
        parse var list.i pname",".
        ret = SysWinSetDefaultPrinter(pname)
        if ret <> 0 then do
          say "Error setting default printer ("ret"):" SysGetErrorText(ret)
        end
        else do
          say "The new default printer is:" pname
        end
      end
    end
  end

  if \ numberOk then do
    say "You did not enter a valid printer number."
  end
end
else do
  say "Failed to get a list of the available printers."
end