none
vbs encyption scripts

    Question

  • I am newbie when it comes to scripting. I have the below scripts. I want to loop as many times as there is a file in input folder. But it is not working. it is only creating 1 and then freeze or get blocked. Can someone take a look at the below script and advice what I am doing wrong.


    sInPath = "E:\Put\"
    sBatPath ="C:\GNU\GnuPG\Batch.bat"

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(sInPath )
    Set colFiles = objFolder.Files
    Set WshShell = WScript.CreateObject("WScript.Shell")


    For Each objFile in colFiles
      sCommand = "C:\GNU\GnuPG\gpg -a -r " & Chr(34) & "name" & chr(34) &  " --output " & Chr(34) & "E:\output\" & objFile.Name & ".asc" & Chr(34) & " -e " & Chr(34) & "E:\inPut\" & objFile.Name
      set ts = objfso.CreateTextFile(sBatPath,True )
      ts.WriteLine sCommand
      ts.Close
      WshShell.Run sBatPath
      WScript.Sleep 10000
      objFile.Delete
     
    Next

    msgbox "Done"

    Batch.bat

    C:\GNU\GnuPG\gpg -a -r "name" --output "E:\output\filename.txt.asc" --e "E:\inPut\filename.txt

    Wednesday, February 20, 2013 4:41 PM

Answers

All replies

  • Sorry but the symptom you describe can only happen if there is something wrong with your system.  Try running this on a different system.

    You sshould not nee the sleep command.


    ¯\_(ツ)_/¯

    Wednesday, February 20, 2013 4:51 PM
  • I removed the sleep command and it is still doing it. is there another way to write this script to loop
    Wednesday, February 20, 2013 4:55 PM
  • Why create a text file to create a shell script to run the command when you can simply run the command directly?

    Also, make sure you tell the Run method to wait for the program to complete before continuing.

    Bill

    Wednesday, February 20, 2013 4:57 PM
    Moderator
  • I removed the sleep command and it is still doing it. is there another way to write this script to loop

    It doesn't matter how you write it.  What error are you getting?


    ¯\_(ツ)_/¯

    Wednesday, February 20, 2013 4:57 PM
  • This is closer to what you are trying to do but you will have to fix the command so it parses correctly.

    sInPath = "E:\Put\" 
    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objFolder = objFSO.GetFolder(sInPath ) 
    For Each objFile In objFolder.Files
         sCommand = "C:\GNU\GnuPG\gpg -a -r " & Chr(34) & "name" & chr(34) &  " --output " & Chr(34) & "E:\output\" & objFile.Name & ".asc" & Chr(34) & " -e " & Chr(34) & "E:\inPut\" & objFile.Name
         WScript.Echo "COMMAND:" & sCommand
         WshShell.Run sCommand,1 , True
    Next 
    msgbox "Done"


    ¯\_(ツ)_/¯



    Wednesday, February 20, 2013 5:24 PM
  • Thank you all jrv your script is what worked for me. except now i need

    help with AbqBill suggestion. "make sure you tell the Run method to wait for the program to complete before continuing"

    and delete after is completed.

    As you can see I was using WScript.Sleep 10000
      objFile.Delete but they are not doing the work is delaying and deleting too quick

    Wednesday, February 20, 2013 8:07 PM
  • Thank you all jrv your script is what worked for me. except now i need

    help with AbqBill suggestion. "make sure you tell the Run method to wait for the program to complete before continuing"

    and delete after is completed.

    As you can see I was using WScript.Sleep 10000
      objFile.Delete but they are not doing the work is delaying and deleting too quick


    The script I posted does all of that.  It does not use delete.  I think you need to go back and read al of this again then carefully try the solution.

    ¯\_(ツ)_/¯

    Wednesday, February 20, 2013 8:36 PM
  • yea that did not work to delete the files. Thanks anyway
    • Marked as answer by Giss68 Wednesday, February 27, 2013 8:59 PM
    Wednesday, February 27, 2013 8:59 PM
  • When you say that something didn't work, you have to say how it didn't work.

    Bill

    Wednesday, February 27, 2013 9:14 PM
    Moderator
  • yea that did not work to delete the files. Thanks anyway

    Just add objFile.Delete to the loop.  It will delete the files.


    ¯\_(ツ)_/¯

    Wednesday, February 27, 2013 9:46 PM
  • hi AbqBill I have some few question about regex do you have a blog or a forum i can ask question.

    i have a database that I use, and some columns are in regex. I need some few syntax like maxfile_*.txt =^(?i)maxfile_*.txt but is not working. [A-Za-z].

    If i say it does not work, the program just stall after it moves it, the encryption does not take place nor does the delete take place.

    Thanks

    Thursday, February 28, 2013 2:03 AM
  • the objFile.Delete delete the files before it even arrives to the destination folder.

    My problem here is I have several files and i want the script to loop through them and delete as they are being encrypted.

    Thursday, February 28, 2013 2:06 AM
  • the objFile.Delete delete the files before it even arrives to the destination folder.

    My problem here is I have several files and i want the script to loop through them and delete as they are being encrypted.

    You must post the script you are referring to.  None of what you say matches any of the scripts that I have posted so you are not copying them correctly.


    ¯\_(ツ)_/¯

    Thursday, February 28, 2013 2:10 AM
  • Also I want to add a prefix to the file name  like "E:\output\" "PREFIX_" & objFile.Name & ".asc"  but is not working anyhelp
    Thursday, February 28, 2013 2:12 AM
  • sInPath = "E:\Put\"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set WshShell = WScript.CreateObject("WScript.Shell")
    Set objFolder = objFSO.GetFolder(sInPath )
    For Each objFile In objFolder.Files
         sCommand = "C:\GNU\GnuPG\gpg -a -r " & Chr(34) & "name" & chr(34) &  " --output " & Chr(34) & "E:\output\" & objFile.Name & ".asc" & Chr(34) & " -e " & Chr(34) & "E:\inPut\" & objFile.Name
         
         WshShell.Run sCommand
      objFile.Delete
    Next
    msgbox "Done"
    Thursday, February 28, 2013 8:08 PM
  • You need to read the documentation for the Run method. Pay particular attention to how you can run a program and wait for it to complete before continuing to the next line of your script (bWaitOnReturn).

    Bill

    • Marked as answer by Giss68 Friday, June 07, 2013 1:48 PM
    Thursday, February 28, 2013 8:21 PM
    Moderator