System.ComponentModel.Win32Exception (0x80004005): Access is denied

Lino Jr Asmolo 1 Reputation point
2022-10-21T07:01:27.167+00:00

Hi Everyone.

I would to ask from your expertise on this matter.
I am new in C# development and right now developing C# WinForms application where I implement printing feature. Here's what exception I am facing.

On the parent form, I have a button than will instantiate a form (Receipt) will then will show it. In the Load() event of this form (Receipt), I included a method that will instantiate the PrintDocument() and call it Print() method. A the result when I am clicking the button, it will open up the Save Print Output As if I choose the Microsoft Print to PDF. Normally, i wont have any exception. But, when clicking the print button and then clicking back to the parent form, I am having this Access Denied exception.

Do you know what does it mean. And how can I prevent this exception. I am attaching as well the source code so you can look at it and modify it.
Thanks in advance.

252847-text.jpg
252846-parentform.jpg
252901-exception.jpg

252816-source-code-in-receiptform.txt

Developer technologies Windows Forms
Developer technologies C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2022-10-21T09:11:44.91+00:00

    Hi @Lino Jr Asmolo , Welcome to Microsoft Q&A.

    It should be a user permission issue.

    Try changing the user running the service from the Service Control Manager.

    If it works, you should probably change how the printer is configured so that the user running the service can use,

    Try opening it in administrator mode.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.