We're going to use those same OpenPrinter and ClosePrinter calls that we used in that last sample, except we're going to have to make one mod on the OpenPrinter call. The third argument there is an optional printer_defaults structure that contains an attribute indicating the level of access we need to the printer. When we just wanted to read the status we didn't need any special rights, but now that we want to set the status we need to tell Windows that we want to have administrative right to it.
We do that by declaring a slightly different version of the local external function call that takes a structure for the last argument rather than a long. The structure we're going to pass is defined as:
global type printer_defaults from structure
And the modified version of the OpenPrinter call we're going to use is:
Function long OpenPrinter ( string pPrinterName,
ref ulong phPrinter, printer_defaults pDefault )
Library "winspool.drv" Alias For "OpenPrinterW"
We're also going to declare a local external function for the SetPrinter Windows API call used to set the status:
Function long SetPrinter (ulong hPrinter, long Level,
long pPrinter, long command ) Library "winspool.drv"
Once we've got that in place, setting the printer status is as simple as:
constant long PRINTER_CONTROL_PAUSE = 1
constant long PRINTER_ACCESS_ADMINISTER = 4
ls_printer = PrintGetPrinter()
ll_pos=pos (ls_printer, "~t")
ls_printer=left(ls_printer, ll_pos -1)
pd.desiredaccess = PRINTER_ACCESS_ADMINISTER
rc = OpenPrinter(ls_printer, hPrinter, pd )
rc = SetPrinter ( hPrinter, 0, 0, PRINTER_CONTROL_PAUSE )
rc = ClosePrinter ( hPrinter )