Resolved How to get privilege to change default printer orientation.

aaaron

Well-known member
Joined
Jan 23, 2011
Messages
219
Programming Experience
10+
I created a program many years ago that includes the statements:

Dim printerDefaults As WinspoolH.PRINTER_DEFAULTS
printerDefaults.desiredAccess = WinspoolH.PRINTER_ALL_ACCESS
ret = OpenPrinter(printerName, printerHandle, printerDefaults)

I have an administrator signin account and this use to let me open OK.

Now it fails as if I do not have the correct privileges.

I'm guessing the code should say the privilege is needed and ask me if I want to continue. The same way Windows ask before it will do some things that require elevated privileges.

I have no idea how to do that. Can you show me how to get privilege to change default printer orientation?

Or if I'm wrong above, what to do?




.
 
Last edited:
If you start VS as administrator then you will be debugging your app as administrator (elevated) as well, no additional steps required.

To change requested execution level of app when started standalone and ask for elevation:
View Windows Settings
Click this button to generate and open the app.manifest file. Visual Studio uses this file to generate manifest data for the application. Then set the UAC requested execution level by modifying the <requestedExecutionLevel> tag in app.manifest as follows:
Set requireAdministrator.
 
I think I was not clear in my post. What I think I need is that when the program is running outside the ID that it should allow a privileged user to continue.
I have to admit that I looked at the reference and only got more bewildered (i.e., I'm not absolutely sure it does not apply to what I just wrote.)
I'm confused, I think maybe that is what you may have meant about standalone, but I just can't find out how to proceed.

Windows at run time seems to sense the user needs to allow the application to use a privilege the user has, and asks if t should. I believe that is what I'm looking for (without any good luck.)


Thanks
 
Last edited:
To do something that requires admin privilegies the process/application must be elevated when it is started. That's what happens when you "run as administrator", and that is what 'requireAdministrator' does. A regular user can't run such app.
 
I'm not sure about the below, but I'm quite sure something like this happens.
Seems, if your not signed in as Administrator, but have the correct privilege to do do something that the app does not have the privileges to do, it asks if you want to elevate, and if you click Continue it continues. I guess it gives the app the privileges then that you could have given to the app. What do you think. Am I completely off base?

If I am I suppose I should simply tell the user to rerun as administrator.

Thanks for putting up with this, I know I'm being pretty vague.
 
Even when logged in with an administrator account the process must be elevated when started to perform tasks that require administator privilegies. Also a regular user can start an elevated process if they have admin credentials to input when asked for it. Only way to do that is manually with "run as administrator", automatically with requireAdministrator in manifest, or programmatically with Process class and runas verb.
 
'or programmatically with Process class and runas verb. "

Thanks, that is, I think, what I was looking for. Now all I have to do is figure out how to convert:
"with Process class and runas verb"
to code!
 
VB.NET:
Process.Start(New ProcessStartInfo("notepad.exe") With {.Verb = "runas"})
 

Latest posts

Back
Top