How to set DesiredAccess so any user can execute OpenPrinter

  • Thread starter Thread starter Academia
  • Start date Start date
A

Academia

I've seen:
PRINTER_DEFAULTS pd;

pd.pDatatype = null;
pd.pDevMode = null;
pd.DesiredAccess = PRINTER_ACCESS_ADMINISTER;

bResult = OpenPrinter(printerName, &hPrinter, &pd);

I looked at what little documentation I could find but can't figure if what
DesiredAccess is set to, gives the user that privilege for this Open
or if it is saying
that the user must have that privilege in order to run this code.

I'd like any user to be able to open the printer

Can you tell me how to set DesiredAccess so any user can execute the
OpenPrinter statement?

Is that possible?



Thanks
 
Hello, Academia!

From the docs
"DesiredAccess
Windows NT/2000/XP: Specifies desired access rights for a printer. The
OpenPrinter function uses this member to set access rights to the printer.
These rights can affect the operation of the SetPrinter and DeletePrinter
functions..."

DesiredAccess stands for desired privileges when opening printer. If user
has no these privileges then OpenPrinter will fail.

Printers can have access control lists (ACLs). You can set them either
programmatically or manually
(Start->Settings->Printers and Faxes->select printer's
properties->Security).

HTH
--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com

You wrote on Mon, 10 Sep 2007 15:04:31 -0400:

A> I've seen:
A> PRINTER_DEFAULTS pd;

A> pd.pDatatype = null;
A> pd.pDevMode = null;
A> pd.DesiredAccess = PRINTER_ACCESS_ADMINISTER;

A> bResult = OpenPrinter(printerName, &hPrinter, &pd);

A> I looked at what little documentation I could find but can't figure
A> if what
A> DesiredAccess is set to, gives the user that privilege for this Open
A> or if it is saying that the user must have that privilege in order to
A> run this code.

A> I'd like any user to be able to open the printer

A> Can you tell me how to set DesiredAccess so any user can execute the
A> OpenPrinter statement?

A> Is that possible?



A> Thanks
 
Vadym Stetsiak said:
Hello, Academia!

From the docs
"DesiredAccess
Windows NT/2000/XP: Specifies desired access rights for a printer. The
OpenPrinter function uses this member to set access rights to the printer.
These rights can affect the operation of the SetPrinter and DeletePrinter
functions..."

DesiredAccess stands for desired privileges when opening printer. If user
has no these privileges then OpenPrinter will fail.

This is what I didn't know. If it said "Specifies REQUIRED access rights for
a printer" I would have understood.

As I think about it now, it wouldn't make sense that a user without
privleges could gain privledges by running a program unless the program was
some how installed by a privledged user.

I don't even know if XP Pro allows the latter.

BTW, I opened the printer's properties as you suggested below but there was
no "Security" to be found.

Thanks for the help
 
I realize I'm still confused.
What if I set
pd.DesiredAccess =null

or

OpenPrinter(printerName, PrinterHandle, null) //PrinterDefaults)


can anyone execute the OpenPrinter statement?

Is there a way I can use OpenPrinter so anyone can run it?

....
Maybe it's when the code tries to, say, change default orientation, it will
fail if the OpenPrinter did not have the required access. Is that correct?



Thanks
 
Hello, Academia!

Destop application by default will run under user that launched the
application.
If user has no access to the printer then OpenPrinter will fail.

You can include a logic in your code that will determine access rights to
the printer.
See the Remarks section here
http://msdn2.microsoft.com/en-us/library/ms536027.aspx

--
With best regards, Vadym Stetsiak.
Blog: http://vadmyst.blogspot.com

You wrote on Tue, 11 Sep 2007 12:49:09 -0400:

A>
A> This is what I didn't know. If it said "Specifies REQUIRED access
A> rights for a printer" I would have understood.

A> As I think about it now, it wouldn't make sense that a user without
A> privleges could gain privledges by running a program unless the
A> program was some how installed by a privledged user.

A> I don't even know if XP Pro allows the latter.

A> BTW, I opened the printer's properties as you suggested below but
A> there was no "Security" to be found.

A> Thanks for the help


A>>> I've seen:
A>>> PRINTER_DEFAULTS pd;

A>>> pd.pDatatype = null;
A>>> pd.pDevMode = null;
A>>> pd.DesiredAccess = PRINTER_ACCESS_ADMINISTER;

A>>> bResult = OpenPrinter(printerName, &hPrinter, &pd);

A>>> I looked at what little documentation I could find but can't figure
A>>> if what
A>>> DesiredAccess is set to, gives the user that privilege for this
A>>> Open or if it is saying that the user must have that privilege in
A>>> order to run this code.

A>>> I'd like any user to be able to open the printer

A>>> Can you tell me how to set DesiredAccess so any user can execute
A>>> the
A>>> OpenPrinter statement?

A>>> Is that possible?



A>>> Thanks
 
Vadym Stetsiak said:
Hello, Academia!

Destop application by default will run under user that launched the
application.
If user has no access to the printer then OpenPrinter will fail.

Is this correct:

If I open a printer with a desired access and have that privledge the open
will not fail.

But if I then try to perform an operation on the printer that requires a
higher access that operation will fail.

Is that correct?

Thanks for helping
 
Academia said:
I worked it out

thanks

And the answer was?

It is customary, if a person manages to find an answer to their question
on their own, to follow-up their own thread, posting that answer. That
way if others search the archives later with the same question, the
actual answer is already there.

Please post the answer you found out.

Thanks,
Pete
 
my previous post was correct


If I open a printer with a desired access and have that privilege the open
will not fail.

But if I then try to perform an operation on the printer that requires a
higher access that operation will fail.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top