Accessing a network Printer when running under a different Windows account
Hi
In essence, I need to programatically add network printers. I am happy to
utilise the API call to AddPrinterConnection but once that is done, how can
I be sure to get ReportBuilder to see this new printer? I know that simply
adding another printer within the IDE does not refresh the printer list
until Delphi(6) closes / re-opens.
Any suggestions?
Many thanks
Clive Crocker
--
Background for my problem:
I have some NT services which include Report Builder to print labels to a
thermal printer and laser printer as part of an interface to some industrial
handheld equipment. It's all running lovely, and the service runs under a
user 'Domain\Services'. The 'printers' in question are specified in registry
keys, and the service responds correctly when changing those keys... but
only if the printers are 'local' rather than 'network' devices.
I know why this is : since Network printers are 'personal' to the user
account, and because the 'Services' account has never had a 'desktop' login
session, those printers do not exist for the Services account profie.
Therefore, when my registry key (and thus OP code) sets the ReportBuilder
printer to '\\Server\HP Laserjet 4000', actually that printer does not
exist. Foolishly, I imagined that Windows would sort it all out... simply by
making a reference to the desired printer!
As a workaround, I have created a local printer which in turn prints to the
same printer queue on the server.
--
In essence, I need to programatically add network printers. I am happy to
utilise the API call to AddPrinterConnection but once that is done, how can
I be sure to get ReportBuilder to see this new printer? I know that simply
adding another printer within the IDE does not refresh the printer list
until Delphi(6) closes / re-opens.
Any suggestions?
Many thanks
Clive Crocker
--
Background for my problem:
I have some NT services which include Report Builder to print labels to a
thermal printer and laser printer as part of an interface to some industrial
handheld equipment. It's all running lovely, and the service runs under a
user 'Domain\Services'. The 'printers' in question are specified in registry
keys, and the service responds correctly when changing those keys... but
only if the printers are 'local' rather than 'network' devices.
I know why this is : since Network printers are 'personal' to the user
account, and because the 'Services' account has never had a 'desktop' login
session, those printers do not exist for the Services account profie.
Therefore, when my registry key (and thus OP code) sets the ReportBuilder
printer to '\\Server\HP Laserjet 4000', actually that printer does not
exist. Foolishly, I imagined that Windows would sort it all out... simply by
making a reference to the desired printer!
As a workaround, I have created a local printer which in turn prints to the
same printer queue on the server.
--
This discussion has been closed.
Comments
There is a way to refresh the printer list without having to call any API
functions directly. Be sure you include ppPrintr in your 'uses' clause,
then call:
ppPrinters.Refresh;
This will change the available printers at runtime.
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
The solution is now fully implemented and seems to work well using
AddPrinterConnection and ppPrinters.Refresh
Thank you for your prompt reply - it is appreciated.
Regards
Clive
I have found something slightly weird.
If we have already created the ppReport component, and then add a printer as
described earlier, and then ppPrinters.refresh, our new printer is indeed
there. IndexOf(MyNewPrinter) returns the correct index etc.
But when we assign the new printer name to the
ppReport.PrinterSetup.PrinterName property, I am seeing access violations of
varying types; also an 'External Exception' occasionally.
Next time the ppReport is created and the same printer assigned, it is fine
because the printer already existed.
As a workaround, I am dealing with the creation of a new printer connection
before actually creating the ppReport component.
Have you any comments? Have you a suggestion how I may persuade ppReport to
correctly work with this having just created the new report, or do you think
I am attempting to do something which would be handled better by my existing
solution? Is there some kind of method to 'refresh' the ppReport internal
settings to agree with the current environment?
Thank you
Clive
I would recommend using the solution you already have of creating the new
printer connection before you call Report.Print. I believe the
Report.PrinterSetup is saving down the current list of printers so when you
chang them on the fly, the errors are given.
--
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com