3

I have batch script file, which should encrypt a file with pgp. I have defined a task in task scheduler to do this, but I am keep receiving the error"The system cannot find the file specified".

Interestingly, when I run the same line of script in my powershell , the encrypted file is successfully generated.

I was wondering if anyone knows what can possibly be wrong here?

I tried to give the full path in my batch script , and also added the pass in start in part, when defining the action.

the batch scrip code is here::

rem @echo off 
@set path=c:\test;%path%

@set d=%date:~-4,4%%date:~4,2%%date:~-7,2% 
@set d=%d: =_% 
@set t=%time:~0,2%%time:~3,2%%time:~6,2% @set t=%t: =0%

Rem  Generate PGP encrypted file 
@echo Starting PGP... >> c:\apps\ftpLogs\test.log 
gpg2 --batch --yes -r testkey --output c:\test\foo\test_20150505.pgp --encrypt c:\test\foo\test_20150505.txt >> c:\apps\ftpLogs\test.log

and the script that I ran in my powershell, which works fine, is this line:

gpg2 --batch --yes -r testkey --output c:\test\foo\test_20150505.pgp --encrypt c:\test\foo\test_20150505.txt >> c:\apps\ftpLogs\test.log
user 12321
  • 141
  • 1
  • 1
  • 7

2 Answers2

1

Finally I was able to resolve the issue. The problem was with the user authority. The batch script was suppose to encrypt a file and then ftp the encrypted file to the vendor's ftp server.

Apparently in Windows Server 2012 , the ADMINISTRATORS have the permission to create a file (here the encrypted file) while this user does not have the permission to send it. and SYSTEM user has the permission to send but not to create. (Both of them had this authority back in Win Server 2008).

hence what did I do at the end, was to make two different batch script tasks and schedule them with 10 mins time distance. The first one was running the above code with ADMINISTRATOR privileges and the second one was sending it out with SYSTEMS.

user 12321
  • 141
  • 1
  • 1
  • 7
0

I had this same error, but in my case it only occurred when running the task as a Service account; the task worked fine when running as my domain user. The error was basically a red herring, and instead ended up being due to using the GUI to select an option that may be unsupported. Basically, don't set "If the task is already running..." to "Stop the existing instance". Use any of the other 3 options.

More detailed info here.

TTT
  • 736
  • 4
  • 10