Cannot print email to pdf

I am writing a console application which will print .msg file to pdf, i am using code

_PDFCreator.cPrintFile(",msg file format")
```
When i run the application manually it works, but when i run it as a batch
```
using task scheduler/ or any scheduler it does not work, it hangs on the above line.
```
Looks like PDFCreator cannot open the email.
```
Can anyone please help, thanks a lot

i tried printing .txt file and it works fine, running executable as well as in task scheduler

so looks like pdfcreator cannot open the .msg file or some setting in Outlook preventing it.

can anyone comment?