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 
10
  • please put the path to gpg2, like c:\path\to\it\gpg2.exe Commented May 6, 2015 at 0:22
  • sure, will let you know the results in a min Commented May 6, 2015 at 0:24
  • @yagmoth555 still the same error :( Commented May 6, 2015 at 0:26
  • where it's stored ? can you like place the .exe in the c:\test in exemple ? I wonder if the account the task run under got access there Commented May 6, 2015 at 0:33
  • 1. Add echo CD=%CD% to the top of your script and pause to the bottom; 2. Run the script from command line or double click: error? 3. Run the script from Task Scheduler. 4. Compare echo CD=%CD% output... Commented May 6, 2015 at 0:33

2 Answers 2

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.

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.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.