gpg batch encryption fails if no user session

I need to transfer encrypted and signed files on a fixed schedule. I have created a command line to batch encrypt the file using the Windoes task scheduler using a special account setup for this purpose. The problem is that when the task scheduler executes the command and the special user happens to be logged on to the system where the task scheduler is running, the file gets encrypted properly but if the user is not logged on, the command returns error number 1 with no encrypted file. I have spent an entire day trying to figure out why it is required for the user to logon to to the system for the execution of a batch command.