Recent

Author Topic: [SOLVED] application + CMD  (Read 2654 times)

scons

  • Full Member
  • ***
  • Posts: 141
[SOLVED] application + CMD
« on: July 27, 2017, 04:34:30 pm »
Hi all,

I wrote a small application to encrypt files being part of another proces. It is not for real security reasons but more so that users cannot change things in case they open the file.

I would like to "automate" this encryption by adding an extra batch line in another batch file which is already part of the process.

So I would like the application to accept input from a CMD window. Something like this :

Code: Text  [Select][+][-]
  1. START "" encrypt.exe  %cd%\lists\file.txt
or
Code: Text  [Select][+][-]
  1. START C:\Program Location\encrypt.exe  file.txt

So in my application I would like the "Readln" to accept the above command and file being 'file.txt'. Or implement something similar that can do this.

This is my working code:

Code: Pascal  [Select][+][-]
  1. program encrypt;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   {$IFDEF UNIX}{$IFDEF UseCThreads}
  7.   cthreads,
  8.   {$ENDIF}{$ENDIF}
  9.   Classes,
  10.   { you can add units after this }
  11.   FileUtil, SysUtils, DCPrc4, DCPsha1;
  12.  
  13. var
  14.   Cipher: TDCP_rc4;
  15.   Source, Dest: TFileStream;
  16.   Filename, Filepart1, Filepart2: string;
  17.  
  18. {$R *.res}
  19.  
  20. begin
  21.   Readln(FileName);   //<- change or replace this with ...?
  22.   if FileExists(ExtractFilePath(ParamStr(0)) + FileName) then
  23.   try
  24.     Filepart1 := ExtractFileNameWithoutExt(Filename);
  25.     Filepart2 := ExtractFileExt(Filename);
  26.     Source := TFileStream.Create(ExtractFilePath(ParamStr(0)) + FileName, fmOpenRead);
  27.     Dest := TFileStream.Create(ExtractFilePath(ParamStr(0)) + Filepart1 + '1' + Filepart2, fmCreate);
  28.     Cipher := TDCP_rc4.Create(nil);
  29.     Cipher.InitStr('password', TDCP_sha1);
  30.     Cipher.EncryptStream(Source, Dest, Source.Size);
  31.     Cipher.Burn;
  32.     Cipher.Free;
  33.     Dest.Free;
  34.     Source.Free;
  35.     writeln('File encrypted');
  36.     DeleteFile(ExtractFilePath(ParamStr(0)) + FileName);
  37.   except
  38.     writeln('File IO error');
  39.   end else
  40.   writeln('file not found');
  41.   sleep(1000);
  42. end.
  43.  

I could not seem to find any on this in the Wiki, or I have missed it.

Is this possible ?

I also could hardcode the filename (which is always the same), copy the file to the place where the encrypt.exe is located, run encrypt.exe and then copy the encrypted file back but this gives more changes on (possible) errors and of course takes longer.

Thanks
« Last Edit: July 27, 2017, 08:38:28 pm by scons »
Windows 10-64bit Lazarus 2.0.12 + FPC 3.2.0

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: application + CMD
« Reply #1 on: July 27, 2017, 05:33:50 pm »
I'm not sure what it is you actually want. Are you talking about parameter parsing using ParamStr and ParamCount ?

Thaddy

  • Hero Member
  • *****
  • Posts: 14159
  • Probably until I exterminate Putin.
Re: application + CMD
« Reply #2 on: July 27, 2017, 05:48:09 pm »
I'm not sure what it is you actually want. Are you talking about parameter parsing using ParamStr and ParamCount ?

No, he's trying to try a bit along the lines of encryption scams...<sigh>  At least the one's who do that have a little skill. But maybe you are right... %)

Although many on this forum would be very capable to do just that. We just don't.
« Last Edit: July 27, 2017, 05:50:36 pm by Thaddy »
Specialize a type, not a var.

scons

  • Full Member
  • ***
  • Posts: 141
Re: application + CMD
« Reply #3 on: July 27, 2017, 08:38:08 pm »
Windows 10-64bit Lazarus 2.0.12 + FPC 3.2.0

 

TinyPortal © 2005-2018