Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
PrintStatus() always returns .T.
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire de rapports & Rapports
Versions des environnements
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Divers
Thread ID:
01204202
Message ID:
01204324
Vues:
20
>I did a SET PRINTER TO NAME MyLocalPrinter.
>I checked with SET('printer',3) to make sure.
>Everything was ok... then PrintStatus() return .T.
>I put printer offline... then PrintStatus() return .T.
>I put printer OFF... then PrintStatus() return .T.
>I disconnect printe... then PrintStatus() return .T.
>I put the printer in the garbage... and PrintStatus() return .T. again :-(
>Why?

It's funny you should post this today. I had to write something today that set the default printer to a label printer, then return to the default printer. My solution uses WMI code that I stold and modified. I think Stuart Dunkeld and/or Craig Boyd had the initial programs, but I never found any code in VFP/WMI for determing the default printer. The first program creates a cursor and populates it with all the installed printers, then does a browse FYI. So, here have some candy:
*wim_printerstatus
strComputer = "."
CREATE CURSOR tprinstatus (name c(80),location c(20),status c(20))
 objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + strComputer + "\root\cimv2")
 colInstalledPrinters = objWMIService.ExecQuery ("SELECT * FROM Win32_Printer")

For Each objPrinter in colInstalledPrinters

 m.name= objPrinter.Name
 m.Location=TRANSFORM(objPrinter.Location)
 m.status=''
 DO Case &&objPrinter.PrinterStatus
 Case objPrinter.PrinterStatus=1
 m.status="Other"
 Case objPrinter.PrinterStatus=2
 m.status="Unknown"
 Case objPrinter.PrinterStatus=3
 m.status="Idle"
 Case objPrinter.PrinterStatus=4
 m.status="Printing"
 Case objPrinter.PrinterStatus=5
 m.status="Warmup"
 Endcase
INSERT INTO tprinstatus FROM memvar 
NEXT
SELECT tprinstatus
browse
then there is the code I wrote to return the default printer
save it to wmi_defaultprinter and then issue ?wmi_defaultprinter()
*wmi_defaultprinter
WAIT WINDOW NOWAIT "Determining Default Printer . . . "
strComputer = "."
objWMIService = Getobject("winmgmts:"  + "{impersonationLevel=impersonate}!\\" + strComputer + "\root\cimv2")
colInstalledPrinters = objWMIService.ExecQuery ("Select * From Win32_Printer Where Default = TRUE")
retvar=''
For Each objPrinter In colInstalledPrinters
IF TYPE('objprinter.name')<>'U'
	retvar = objPrinter.Name
endif
ENDFOR
RETURN (retvar)
And finally I used some WSH code to set the default printer. Here I'm just grabbing the first printer. You will need to iterate through the printers array to find the one you want.
APRINTERS(laprinters)
LCPRINTER=LAPRINTERS(1,1)
oNet = CREATEOBJECT("WScript.Network")
oNet.SetDefaultPrinter(lcprinter)
John Harvey
Shelbynet.com

"I'm addicted to placebos. I could quit, but it wouldn't matter." Stephen Wright
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform