Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

saving password in exe

Status
Not open for further replies.

AbbasAkhtar

Programmer
Dec 16, 2002
25
GB
can someone please check this code out,

it works for me, but there is something strange going on,
when i compile the exe, it saves and reads from itself, and the app doesnt need to shutdown, and when u open the exe in wordpad, and go to find and look for the ini settings u saved in the document u opened (exe file), it will find it, but its strange, i cant explain it

when i encrypt the exe using neolite pro, it still works saves and reads to itself, but when u open using wordpad, everything looks encrypted, and u cant find the data that ur saving anymore ?

does this method save external ini file, or actually inside the exe file ? could someone explain this, look below for source code.

does this actually save inside the exe ? and can i add encryption, and will it work ?

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Inifiles;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
MyAppini : TIniFile;
begin
try
MyAppini := TIniFile.Create(ExtractFileName(Application.ExeName));
Left := MyAppini.ReadInteger(Caption,'Left',Left);
Top := MyAppini.ReadInteger(Caption,'Top',Top);
Width := MyAppini.ReadInteger(Caption,'Width',Width);
Height := MyAppini.ReadInteger(Caption,'Height',Height);
finally
MyAppini.Free;
end;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
var
MyAppini : TIniFile;
begin
try
MyAppini := TIniFile.Create(ExtractFileName(Application.ExeName));
MyAppini.WriteInteger(Caption,'Top',Top);
MyAppini.WriteInteger(Caption,'Left',Left);
MyAppini.WriteInteger(Caption,'Width',Width);
MyAppini.WriteInteger(Caption,'Height',Height);
finally
MyAppini.Free;
end;
end;
end.
 
may be wrong but you might want to use something like
MyAppini := TIniFile.Create(ExtractFilePath(Paramstr(0)) + '\' + ExtractFileName(Application.ExeName));

Otherwise I think the ini file would be saved in whatever the current path may be which may not be local to where the EXE is running.

Bit confused anyway, you can't save this info inside the EXE file can you?? you could add something to the end if you were carefull like winzip does with self extract. Don't think you can use the EXE as an ini file though, never tried...

If this is of no help then not sure I understand what you are trying to do.

Good luck!
Justin Willis.
 
It is not that simple to modify an EXE file while it is running.
The operating system does not allow this.

My guess is the INI routines are failing silently, without generating an error.
Even if they did succeed, it would probably just corrupt the EXE.

I have seen some assembler routines that use raw disk I/O to modify a
running EXE, but the person who wrote them said she trashed several
hard drives in the process of getting it to work :-o

The simplest (but ugly) way to do this is to modify a copy of the EXE,
and then ShellExecute() a batch file to rename the copy when the program
exits.

But even that would probably involve using a FileStream, and getting an
offset to the spot where the password is stored in the EXE.

Storing your password in the registry seems like a lot better solution.
 
Agreed, if encryption is the only thing stopping you from using the registry or an external ini file there are some free encryption components that do this job brilliantly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top