Fixing pdf2txtocr.exe Crashes When Launched by Windows Service on x64 Systems

Fixing pdf2txtocr.exe Crashes When Launched by Windows Service on x64 Systems

Customer Question:

I am experiencing an issue with the pdf2txtocr.exe utility. The application crashes when launched from a Windows service on Windows Server 2008 x64 or Windows 7 x64. The error message displayed is:

Exception code: C0000005 ACCESS_VIOLATION

However, pdf2txtocr.exe works correctly under Windows Server 2003 x86 in the same conditions—when launched from a Windows service.

I tested the solution described on your website, "Call PDF to Text OCR from Web or Windows Service," but the issue persists. Could you please help me identify the cause of this failure and provide a solution?

Thank you.

https://www.verypdf.com/app/pdf-to-text-ocr-converter/index.html

PDF to Text OCR Converter Command Line


Answer:

This issue is primarily caused by Windows Service account permissions on newer x64 systems. When a Windows service launches pdf2txtocr.exe, it runs under a limited user account that lacks the necessary permissions to execute certain processes properly.

Solution: Use CmdAsUser to Launch pdf2txtocr.exe

To resolve this issue, you should use cmdasuser.exe to run pdf2txtocr.exe as an interactive user account instead of the restricted service account.

Steps to Use CmdAsUser.exe:
  1. Download cmdasuser.exe from the following link:

    http://www.verydoc.com/exeshell.html

  2. Run the following command in Command Prompt (CMD):

    CmdAsUser Administrator . /p Password /c "C:\VeryPDF\pdf2txtocr.exe C:\VeryPDF\test.pdf C:\VeryPDF\out.txt"

    Replace Administrator with the actual interactive user account, and Password with the corresponding password.

  3. If this command executes successfully in CMD, then running it from the Windows Service should work without issues.

Fixing Error 1314 (A Required Privilege Is Not Held by the Client)

In some Windows systems, switching between user accounts while launching an application may result in Error 1314:

1314 A required privilege is not held by the client. ERROR_PRIVILEGE_NOT_HELD

To resolve this issue, follow these steps:

Grant "Replace a Process Level Token" Privilege
  1. Click Start, then Run, and type secpol.msc, then press Enter.

  2. Navigate to Local Policies > User Rights Assignment.

  3. Double-click Replace a process level token.

  4. Click Add, then select Everyone.

  5. Click OK, then Apply.

  6. Log out or restart the system to apply the changes.

For additional reference, please check these screenshots:

For more details, visit: http://www.verydoc.com/exeshell.html


Why This Happens on x64 Systems?
  1. Increased Security Restrictions: Windows Server 2008 x64 and Windows 7 x64 impose stricter security policies on services compared to Windows Server 2003 x86.

  2. Session 0 Isolation: Windows services run in Session 0, whereas interactive user sessions run separately. This isolation prevents services from interacting with GUI-based applications without proper permissions.

  3. UAC Restrictions: Even administrator accounts have restricted permissions unless explicitly elevated.

Conclusion

To prevent pdf2txtocr.exe from crashing when launched by a Windows Service on x64 systems:

  • Use cmdasuser.exe to run the application as an interactive user.

  • Ensure necessary privileges are assigned to the service account.

  • Modify Local Security Policies to allow Replace a process level token.

  • Restart the server for changes to take effect.

By following these steps, pdf2txtocr.exe should function correctly without encountering ACCESS_VIOLATION (C0000005) errors.

Related Posts