Installer imprimante local

Résolu
jmp77 Messages postés 1119 Date d'inscription lundi 4 février 2002 Statut Membre Dernière intervention 4 octobre 2006 - 5 oct. 2005 à 10:59
jmp77 Messages postés 1119 Date d'inscription lundi 4 février 2002 Statut Membre Dernière intervention 4 octobre 2006 - 17 oct. 2005 à 10:46
Hello,



Est ce que quelqu'un saurait comment installer une imprimante locale la HP 2000C par exemple directement depuis delphi ?



Merci d'avance.

Bonne prog,
JMP77.

N'oubliez pas de cliquer sur réponse acceptée.

9 réponses

florenth Messages postés 1023 Date d'inscription dimanche 1 août 2004 Statut Membre Dernière intervention 17 août 2008 3
5 oct. 2005 à 20:17
Hi,
Dans l'immédiat, je pencherais sur un truc comme cela:
<hr size= "2" width="100%"> uses
Printers, WinSpool;

function InstallLocalPrinter(const Name, PortName, DriverName, PrintProcessor: string): TPrinter;
var
Info: TPrinterInfo2;
PrinterHandle: THandle;
begin
{ Rempplisage de la structure. }
FillChar(Info,SizeOf(Info),0);
Info.pPrinterName : = PChar(Name);
Info.pPortName := PChar(PortName);
Info.pDriverName := PChar(DriverName);
Info.pPrintProcessor := PChar(PrintProcessor);
Info.Attributes := PRINTER_ATTRIBUTE_LOCAL;

{ Appel de la fonction. }
PrinterHandle := AddPrinter( nil ,2,@Info);

{ Renvoi de l'imprimante. }
if PrinterHandle <> 0 then
begin
{ Ajout réussi. }
ClosePrinter(PrinterHandle);
Result : = Printer;
Printer.PrinterIndex := Printer.Printers.IndexOf(Name);
end
else
{ Echec de l'ajout. }
Result := nil ;
end;
<hr size ="2" width="100%">Chez moi cela ne marche pas mais je crois que le principe y est.
Le problème, c'est que Borland encapsule les APIs windows dans des classes pour les rendre plus faciles à manipuler (on ne se plaint pas ) mais le hic, c'est qu'il n'encapsule pas tout.
Si l'on a besoin de faire le lien entre les classes de Borland et les APIs windows, ça devient vite la panique.
Une seule solution: l'héritage mais après ça complique tout.

Il vaut mieux, je pense, explorer ces pistes là:
[ms-help://MS.PSDKXPSP2.1033/gdi/prntspol_1po2.htm ms-help://MS.PSDKXPSP2.1033/gdi/prntspol_1po2.htm]
[ms-help://MS.PSDKXPSP2.1033/gdi/prntspol_9otu.htm ms-help://MS.PSDKXPSP2.1033/gdi/prntspol_9otu.htm]

@ ++
Florent

Si tu ne te plantes pas ......
tu ne poussera jamais
3
cs_Delphiprog Messages postés 4297 Date d'inscription samedi 19 janvier 2002 Statut Membre Dernière intervention 9 janvier 2013 32
8 oct. 2005 à 23:40
Voilà un sujet nouveau et intéressant.
Voir aussi Adding a printer automatically

Dis Florenth, ces quoi ces liens que tu donnes en référence : ms-help... Chez moi, en cliquant dessus, il ne se passe rien.

<HR color=#008000>
Pensez à cliquer sur Réponse acceptée lorsque la réponse vous convient.
3
florenth Messages postés 1023 Date d'inscription dimanche 1 août 2004 Statut Membre Dernière intervention 17 août 2008 3
9 oct. 2005 à 14:51
Il pourrait être pas mal ton sujet mais il faut s'inscrire. Je n'ai pas pu le voir.
Ces liens sont des références au "Windows XP SP2 Platform SDK Documentation" donc il faut taper ces adresses dans le Platform SDK pour voir la rubrique concernée. C'est très interressant mais un peu compliqué (en anglais bien sûr).

@ ++
Florent

l rights reserved.

Si tu ne te plantes pas ......
tu ne poussera jamais
3
florenth Messages postés 1023 Date d'inscription dimanche 1 août 2004 Statut Membre Dernière intervention 17 août 2008 3
9 oct. 2005 à 14:53
Pour ceux qui n'auraient pas le SDK, voila ce que contient la page [ms-help://MS.PSDKXPSP2.1033/gdi/prntspol_1po2.htm ms-help://MS.PSDKXPSP2.1033/gdi/prntspol_1po2.htm]
<hr size= "2" width="100%"><hr size="2" width="100%">[ pName]</italique> , // server name
DWORD [ Level] , // printer information level
LPBYTE [ pPrinter] // printer information buffer
);



Parameters

* pName : [in] Pointer to a null-terminated string that specifies the name of the
server on which the printer should be installed. If this string is NULL, the
printer is installed locally.
Windows 95/98/Me: This parameter must be NULL. The AddPrinter
function can only install local printers.

* Level : [in] Specifies the version of the structure to which pPrinter points.
This value must be 2.
* pPrinter : [in] Pointer to a [prntspol_4w1e.htm ClosePrinter] function to close it.


If the function fails, the return value is NULL. To get extended error
information, call GetLastError.


Remarks

The following are the members of the PRINTER_INFO_2 structure that can
be set before the AddPrinter function is called:


Attributes
pPrintProcessor
DefaultPriority
Priority
pComment
pSecurityDescriptor
pDatatype,
pSepFile
pDevMode
pShareName
pLocation
StartTime
pParameters
UntilTime


The Status, cJobs, and AveragePPM members of the
PRINTER_INFO_2 structure are reserved for use by the [prntspol_1gky.htm GetPrinter] function. They must not be set
before calling AddPrinter.


Windows NT/2000/XP: If pSecurityDescriptor is NULL, the system
assigns a default security descriptor to the printer. The default security
descriptor has the following permissions.


Value |
Description |
----

Administrators and Power Users,
Full control on the print queue. This means members of these
groups can print, manage the queue (can delete the queue, change any setting of
the queue, including the security descriptor), and manage everybodys jobs
(delete, pause, resume, restart jobs).
Note that Power Users do not exist before Windows XP
Professional.,
----

Creator/Owner,
Can manage own jobs. This means that user who submit jobs can
manage (delete, pause, resume, restart) their own jobs.,
----

Everyone,
Execute and standard read control. This means that members of
the everyone group can print and read properties of the print queue.


After an application creates a printer object with the AddPrinter
function, it must use the [prntspol_9ynn.htm PrinterProperties] function to specify the
correct settings for the printer driver associated with the printer object.


The AddPrinter function returns an error if a printer object with the
same name already exists, unless that object is marked as pending deletion. In
that case, the existing printer is not deleted, and the AddPrinter
creation parameters are used to change the existing printer settings (as if the
application had used the [prntspol_13ua.htm SetPrinter]
function).


Use the [prntspol_4z8z.htm EnumPrintProcessors]
function to enumerate the set of print processors installed on a server. Use
the [prntspol_1mlv.htm EnumPrintProcessorDatatypes]
function to enumerate the set of data types that a print processor supports.
Use the [prntspol_994j.htm EnumPorts] function to enumerate
the set of available ports. Use the [prntspol_752r.htm EnumPrinterDrivers] function to enumerate the
installed printer drivers.


Windows NT/2000/XP:The caller of the AddPrinter function must
have SERVER_ACCESS_ADMINISTER access to the server on which the printer is to be
created. The handle returned by the function will have PRINTER_ALL_ACCESS
permission, and can be used to perform administrative operations on the printer.


Windows 95/98/Me: Windows 95 does not support access validation or
security on printer objects.


Windows XP: If the DrvPrinterEvent function is passed the
PRINTER_EVENT_FLAG_NO_UI flag, the driver should not use a UI call during
DrvPrinterEvent. To do UI-related jobs, the installer should either use
the VendorSetup entry in the printer's .inf file or, for Plug and Play
devices, the installer can use a device-specific co-installer. For more
information about VendorSetup, see the Microsoft Windows 2000 Driver
Development Kit.


Windows 95/98/Me: AddPrinterW is supported by the Microsoft
Layer for Unicode. To use this, you must add certain files to your application,
as outlined in Microsoft
Layer for Unicode on Windows 95/98/Me Systems.


Requirements

Windows NT/2000/XP: Included in Windows NT 3.1 and
later.
Windows 95/98/Me: Included in Windows 95 and
later.
Header: Declared in Winspool.h; include
Windows.h.
Library: Use Winspool.lib.
Unicode:
Implemented as Unicode and ANSI versions on Windows NT/2000/XP. Also
supported by Microsoft Layer for Unicode.

<hr size ="2" width="100%"><hr size="2" width="100%">
3

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
florenth Messages postés 1023 Date d'inscription dimanche 1 août 2004 Statut Membre Dernière intervention 17 août 2008 3
9 oct. 2005 à 14:54
Et pour la page [ms-help://MS.PSDKXPSP2.1033/gdi/prntspol_9otu.htm ms-help://MS.PSDKXPSP2.1033/gdi/prntspol_9otu.htm] :
[ pServerName];
LPTSTR [ pPrinterName];
LPTSTR [ pShareName];
LPTSTR [ pPortName];
LPTSTR [ pDriverName];
LPTSTR [ pComment];
LPTSTR [ pLocation];
LPDEVMODE [ pDevMode];
LPTSTR [ pSepFile];
LPTSTR [ pPrintProcessor];
LPTSTR [ pDatatype];
LPTSTR [ pParameters];
PSECURITY_DESCRIPTOR [ pSecurityDescriptor];
DWORD [ Attributes];
DWORD [ Priority];
DWORD [ DefaultPriority];
DWORD [ StartTime];
DWORD [ UntilTime];
DWORD [ Status];
DWORD [ cJobs];
DWORD [ AveragePPM];
} PRINTER_INFO_2, *PPRINTER_INFO_2;



Members

* pServerName : Pointer to a null-terminated string identifying the server that controls the
printer. If this string is NULL, the printer is controlled locally.
* pPrinterName : Pointer to a null-terminated string that specifies the name of the printer.
* pShareName : Pointer to a null-terminated string that identifies the sharepoint for the
printer. (This string is used only if the PRINTER_ATTRIBUTE_SHARED constant was
set for the Attributes member.)
* pPortName : Pointer to a null-terminated string that identifies the port(s) used to
transmit data to the printer. If a printer is connected to more than one port,
the names of each port must be separated by commas (for example,
\"LPT1:,LPT2:,LPT3:\").
Windows 95/98/Me: This member can specify only one port because
multiple ports per printer are not supported.

* pDriverName : Pointer to a null-terminated string that specifies the name of the printer
driver.
* pComment : Pointer to a null-terminated string that provides a brief description of the
printer.
* pLocation : Pointer to a null-terminated string that specifies the physical location of
the printer (for example, \"Bldg. 38, Room 1164\").
* pDevMode : Pointer to a DEVMODE structure that
defines default printer data such as the paper orientation and the resolution.
* pSepFile : Pointer to a null-terminated string that specifies the name of the file used
to create the separator page. This page is used to separate print jobs sent to
the printer.
* pPrintProcessor : Pointer to a null-terminated string that specifies the name of the print
processor used by the printer. You can use the EnumPrintProcessors function to obtain a
list of print processors installed on a server.
* pDatatype : Pointer to a null-terminated string that specifies the data type used to
record the print job. You can use the EnumPrintProcessorDatatypes function to
obtain a list of data types supported by a specific print processor.
* pParameters : Pointer to a null-terminated string that specifies the default
print-processor parameters.
* pSecurityDescriptor : Pointer to a SECURITY_DESCRIPTOR
structure for the printer. This member may be NULL.
Windows 95/98/Me: This member is ignored.

* Attributes : Specifies the printer attributes. This member can be any reasonable
combination of the following values.
Value |
Meaning |
----

PRINTER_ATTRIBUTE_DEFAULT,
Windows 95/98/Me: Indicates the printer is the default
printer in the system.,
----

PRINTER_ATTRIBUTE_DIRECT,
Job is sent directly to the printer (it is not spooled).,
----

PRINTER_ATTRIBUTE_DO_COMPLETE_FIRST,
If set and printer is set for print-while-spooling, any jobs
that have completed spooling are scheduled to print before jobs that have not
completed spooling.,
----

PRINTER_ATTRIBUTE_ENABLE_BIDI,
Windows 95/98/Me: Indicates whether bi-directional
communications are enabled for the printer.,
----

PRINTER_ATTRIBUTE_ENABLE_DEVQ,
If set, DevQueryPrint is called. DevQueryPrint may
fail if the document and printer setups do not match. Setting this flag causes
mismatched documents to be held in the queue.,
----

PRINTER_ATTRIBUTE_FAX,
Windows XP: If set, printer is a fax printer. This can
only be set by AddPrinter, but it can be
retrieved by EnumPrinters and GetPrinter.,
----

PRINTER_ATTRIBUTE_KEEPPRINTEDJOBS,
If set, jobs are kept after they are printed. If unset, jobs are
deleted.,
----

PRINTER_ATTRIBUTE_QUEUED,
If set, the printer spools and starts printing after the last
page is spooled. If not set and PRINTER_ATTRIBUTE_DIRECT is not set, the printer
spools and prints while spooling.,
----

PRINTER_ATTRIBUTE_SHARED,
Printer is shared.,
----

PRINTER_ATTRIBUTE_WORK_OFFLINE,
Windows 95/98/Me: Indicates whether the printer is
currently connected. If the printer is not currently connected, print jobs will
continue to spool.,
----

PRINTER_ATTRIBUTE_PUBLISHED,
Windows 2000/XP: Indicates whether the printer is
published in the directory service.,
----

PRINTER_ATTRIBUTE_NETWORK,
Printer is a network printer connection.,
----

PRINTER_ATTRIBUTE_HIDDEN,
Reserved.,
----

PRINTER_ATTRIBUTE_LOCAL,
Printer is a local printer.,
----

PRINTER_ATTRIBUTE_RAW_ONLY,
Indicates that only raw data type print jobs can be
spooled.

* Priority : Specifies a priority value that the spooler uses to route print jobs.
* DefaultPriority : Specifies the default priority value assigned to each print job.
* StartTime : Specifies the earliest time at which the printer will print a job. This
value is expressed as minutes elapsed since 12:00 AM GMT (Greenwich Mean Time).
* UntilTime : Specifies the latest time at which the printer will print a job. This value
is expressed as minutes elapsed since 12:00 AM GMT (Greenwich Mean Time).
* Status : Specifies the printer status. This member can be any reasonable combination
of the following values.
Value |
Meaning |
----

PRINTER_STATUS_BUSY,
The printer is busy.,
----

PRINTER_STATUS_DOOR_OPEN,
The printer door is open.,
----

PRINTER_STATUS_ERROR,
The printer is in an error state.,
----

PRINTER_STATUS_INITIALIZING,
The printer is initializing.,
----

PRINTER_STATUS_IO_ACTIVE,
The printer is in an active input/output state,
----

PRINTER_STATUS_MANUAL_FEED,
The printer is in a manual feed state.,
----

PRINTER_STATUS_NO_TONER,
The printer is out of toner.,
----

PRINTER_STATUS_NOT_AVAILABLE,
The printer is not available for printing.,
----

PRINTER_STATUS_OFFLINE,
The printer is offline.,
----

PRINTER_STATUS_OUT_OF_MEMORY,
The printer has run out of memory.,
----

PRINTER_STATUS_OUTPUT_BIN_FULL,
The printer's output bin is full.,
----

PRINTER_STATUS_PAGE_PUNT,
The printer cannot print the current page.
Windows 95/98/Me: Indicates the page is being \\"punted\\" (that is, not
printed) because it is too complex for the printer to print.,
----

PRINTER_STATUS_PAPER_JAM,
Paper is jammed in the printer,
----

PRINTER_STATUS_PAPER_OUT,
The printer is out of paper.,
----

PRINTER_STATUS_PAPER_PROBLEM,
The printer has a paper problem.,
----

PRINTER_STATUS_PAUSED,
The printer is paused.,
----

PRINTER_STATUS_PENDING_DELETION,
The printer is being deleted.,
----

PRINTER_STATUS_POWER_SAVE,
The printer is in power save mode.,
----

PRINTER_STATUS_PRINTING,
The printer is printing.,
----

PRINTER_STATUS_PROCESSING,
The printer is processing a print job.,
----

PRINTER_STATUS_SERVER_UNKNOWN,
The printer status is unknown.,
----

PRINTER_STATUS_TONER_LOW,
The printer is low on toner.,
----

PRINTER_STATUS_USER_INTERVENTION,
The printer has an error that requires the user to do
something.,
----

PRINTER_STATUS_WAITING,
The printer is waiting.,
----

PRINTER_STATUS_WARMING_UP,
The printer is warming up.

* cJobs : Specifies the number of print jobs that have been queued for the printer.
* AveragePPM : Specifies the average number of pages per minute that have been printed on
the printer.

Requirements

Windows NT/2000/XP: Included in Windows NT 3.1 and
later.
Windows 95/98/Me: Included in Windows 95 and
later.
Header: Declared in Winspool.h; include
Windows.h.
Unicode: Declared as Unicode and ANSI structures.

NB: Les liens ne sont pas valides puisuqe ce sont des liens internes au Platform SDK documentation.
3
florenth Messages postés 1023 Date d'inscription dimanche 1 août 2004 Statut Membre Dernière intervention 17 août 2008 3
9 oct. 2005 à 15:01
Je vous prie de m'excuser pour ces deux posts inutiles.
En effet, tout le contenu du SDK est aussi contenu sur le site MSDN de Microsoft ici:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_1po2.asp
et là
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/prntspol_9otu.asp

Enfin, l'important c'est d'avoir trouvé.

PS: Le platform SDK est seulement en anglais mais le Platform .NET SDK est disponible dans plusieurs langues. Une façon de microsoft pour attirer le monde

@ ++
Florent

Si tu ne te plantes pas ......
tu ne poussera jamais
3
jmp77 Messages postés 1119 Date d'inscription lundi 4 février 2002 Statut Membre Dernière intervention 4 octobre 2006 7
10 oct. 2005 à 14:06
Bonjour à tous,



Déjà merci de vos réponses. Je n'ai pas réussi avec les api alors
finalement je suis passé par un petit fichier .bat contenant ceci :



rundll32 printui.dll,PrintUIEntry /if /b "HP 2000C" /f %windir%\inf\ntprint.inf /r "lpt1:" /m "HP 2000C"



Cette commande permet d'ajouter l'imprimante HP 2000C.


Voilà ca pourra peut être servir à d'autre.


Bonne prog,
JMP77.

N'oubliez pas de cliquer sur réponse acceptée.
3
florenth Messages postés 1023 Date d'inscription dimanche 1 août 2004 Statut Membre Dernière intervention 17 août 2008 3
10 oct. 2005 à 16:49
Tu n'est pas obligé de passer par un fichier .bat car tu peux envoyer cette commande via ShellExecute().
C'est plus simple :

<hr size= "2" width="100%"> uses
ShellApi;
begin
ShellExecute(0,'rundll32 printui.dll,PrintUIEntry /if /b "HP 2000C" /f %windir%\inf\ntprint.inf /r "lpt1:" /m "HP 2000C"',nil,nil,0);
end;
<hr size ="2" width="100%">Mais c'est vrai que ces API sont un evraie prise de nerfs. Mai QUI les a inventé ? Qui ?
Enfin. l'important c'est le résultat, peut importe la manière (quoique ...)

@ ++
Florent

Si tu ne te plantes pas ......
tu ne poussera jamais
3
jmp77 Messages postés 1119 Date d'inscription lundi 4 février 2002 Statut Membre Dernière intervention 4 octobre 2006 7
17 oct. 2005 à 10:46
Effectivement je pourrais aussi lancer avec un shellexecute.



Merci Florenth.

Bonne prog,
JMP77.

N'oubliez pas de cliquer sur réponse acceptée.
0
Rejoignez-nous