Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8986653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:36:05+00:00 2026-06-15T21:36:05+00:00

According to undocprint given a job ID it should be possible to retrieve the

  • 0

According to undocprint given a job ID it should be possible to retrieve the spool file for the job using OpenPrinter and ReadPrinter by opening the printer using a string with format “PrinterName,Job xxxx”. The MSDN documentation lists this method as well, though with an additional space after the comma “PrinterName, Job xxxx”.

Whenever I try to call this method from my test application (using either string format) I get ERROR_ACCESS_DENIED (Windows 8 x64). Why is this and what do I need to do to get this working?

I’m running the test app as admin and have no trouble pausing jobs or printers or accessing other information.

I know the ID I’m using is valid because for an invalid ID it returns ERROR_INVALID_PRINTER_NAME instead.

The code I’m using:

public static void OpenPrinter(String printerName,
                               ref IntPtr printerHandle,
                               ref PRINTER_DEFAULTS defaults) {
    if (OpenPrinter(printerName, ref printerHandle, ref defaults) == 0) {
        throw new Win32Exception(Marshal.GetLastWin32Error(),
                                 string.Format("Error getting access to printer: {0}", printerName));
    }
}

[DllImport("winspool.drv", EntryPoint = "OpenPrinterW", SetLastError = true, CharSet = CharSet.Unicode,
    ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
public static extern int OpenPrinter(String pPrinterName, ref IntPtr phPrinter, ref PRINTER_DEFAULTS pDefault);

[StructLayout(LayoutKind.Sequential)]
public struct PRINTER_DEFAULTS {
    public IntPtr pDatatype;
    public IntPtr pDevMode;
    public uint DesiredAccess;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:36:06+00:00Added an answer on June 15, 2026 at 9:36 pm

    Turns out that pDefaults must be passed NULL and then everything works.

    This requires changing the extern definition to take an IntPtr or similar.

    I haven’t seen any documentation about why this might be (in fact the MSDN docs state that this passing NULL should be the same as requesting USE access), but it definitely fixes the issue in our testing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

According to this question and the documentation of attr_readonly the following should be possible:
According to docs at http://code.google.com/p/minify/wiki/UriRewriting $min_serveOptions['rewriteCssUris'] = false; I should be able to add
According to this MSDN article , you should not catch general exceptions. I'm sure
According to bin2hex my PHP is internally using UTF-8: echo bin2hex(ö); -> c3b6 (utf-8)
According to the Doctrine manual I should be able to reference an attribute of
According to an answer in this thread , semicolons are bad and should be
According to msdn it should be in windbase.h but it is not available instead
According to this article from Herb Sutter, one should always pick Class Specializing over
According to Using Rich Edit Controls I use RichEdit in such way: MyControl::OnCreate() {
According to Apple , I can combine UINavigationController and UITabBarController using the code, e.g.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.