Jump to content

running pgp from command line works, but not from autoit script


Recommended Posts

I have PGP command line 6.5.8 installed and i'm trying to run a pgp decrypt command from a script. The command is:

pgp filetodecrypt.pgp outputfile.txt -z password

If i run this from the command prompt it runs just fine and successfully decrypts the file. If i try to run it from an autoitscript the command prompt will flash and the script will close without decrypting the file, but a screen capture shows this error:

"File is encrypted. Secret key is required to read it.

You do not have the secret key needed to decrypt this file."

I've tried using runas to run as the local administrator, tried running from @comspec, and tried outputting the command to a batchfile and running the batch file but all with the same result. So what is going on that i can run it directly from the command line but it fails from the script?

Here's the script:

#include <File.au3>
DecryptFiles("D:Payerspgpconvert")
func DecryptFiles($decryptPath)
   $List = _FileListToArray($decryptPath, "*.pgp", 1)
   If @error = 4 Then
        msgbox(0, "", "No .pgp files found")
   ElseIf @error = 0 Then
        For $x = 1 to ubound($List) -1 step 1
             $decryptedName = StringTrimRight($List[$x], 4)
             RunWait("pgp -z password " & $decryptPath & $List[$x] & " " & $decryptPath & $decryptedName)
             FileDelete($decryptPath & $List[$x])
        Next
   EndIf
EndFunc
Edited by benjbong
Link to comment
Share on other sites

  • Developers

Try this version and change the /k to /c when it works.

Run(@ComSpec & " /k " & "pgp -z password " & $decryptPath & $List[$x] & " " & $decryptPath & $decryptedName)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thanks for the suggestions. I got it working - for anybody who might have issues with this program in the future (unlikely) i had to do a few things:

1. manually set the system variable PGPPATH=C:Program FilesNetwork AssociatesPGPcmdln through the system properties GUI, not the set command on the command line. For some reason the set command wasn't working properly.

2. change the trust on the private keys if they were imported from another server through pgp -ke then set the trust level to 4

3. Add C:Program FilesNetwork AssociatesPGPcmdln to the system path

Once everything was set right i was able to run the command using run("pgp ...")

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...