Forum > Beginners

[SOLVED] application + CMD

(1/1)

scons:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---START "" encrypt.exe  %cd%\lists\file.txtor

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program encrypt; {$mode objfpc}{$H+} uses  {$IFDEF UNIX}{$IFDEF UseCThreads}  cthreads,  {$ENDIF}{$ENDIF}  Classes,  { you can add units after this }  FileUtil, SysUtils, DCPrc4, DCPsha1; var  Cipher: TDCP_rc4;  Source, Dest: TFileStream;  Filename, Filepart1, Filepart2: string; {$R *.res} begin  Readln(FileName);   //<- change or replace this with ...?  if FileExists(ExtractFilePath(ParamStr(0)) + FileName) then  try    Filepart1 := ExtractFileNameWithoutExt(Filename);    Filepart2 := ExtractFileExt(Filename);    Source := TFileStream.Create(ExtractFilePath(ParamStr(0)) + FileName, fmOpenRead);    Dest := TFileStream.Create(ExtractFilePath(ParamStr(0)) + Filepart1 + '1' + Filepart2, fmCreate);    Cipher := TDCP_rc4.Create(nil);    Cipher.InitStr('password', TDCP_sha1);    Cipher.EncryptStream(Source, Dest, Source.Size);    Cipher.Burn;    Cipher.Free;    Dest.Free;    Source.Free;    writeln('File encrypted');    DeleteFile(ExtractFilePath(ParamStr(0)) + FileName);  except    writeln('File IO error');  end else  writeln('file not found');  sleep(1000);end.  
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

molly:
I'm not sure what it is you actually want. Are you talking about parameter parsing using ParamStr and ParamCount ?

Thaddy:

--- Quote from: molly 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 ?

--- End quote ---

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.

scons:

--- Quote from: molly on July 27, 2017, 05:33:50 pm ---ParamCount ?

--- End quote ---

Yes that one, thanks

Navigation

[0] Message Index

Go to full version