Autor Beitrag
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Mo 17.02.03 22:43 
Kann ich ein Programm, oder genauer seine *.exe Datei, während der Laufzeit in einen anderen Ordner kopieren? Ich habe das mit CopyToFile(Application.ExeName, 'C:\Programme\Bla\Programm.exe'); versucht, hatte aber keinen Erfolg.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 17.02.03 22:51 
CopyToFile kenne ich nicht. Aber wie wäre es mit CopyFile?
DaFox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 189



BeitragVerfasst: Mo 17.02.03 22:54 
Hi.

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.Button1Click(Sender: TObject);
var
  Source, Target: TFileStream;
begin
  Source := TFilestream.Create(Application.Exename, fmOpenRead or fmShareDenyNone);
  try
    Target := TFileStream.Create('C:\copy.exe', fmCreate);
    try
      Target.CopyFrom(source, 0);
    finally
      Target.Free
    end;
  finally
    Source.Free
  end;
end;


Gruß,
Markus
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 17.02.03 22:56 
Stimmt. Warum einfach, wenn es kompliziert geht. :roll:
ausblenden Quelltext
1:
2:
3:
4:
procedure TForm1.Button2Click(Sender: TObject);
begin
  CopyFile(PChar(ParamStr(0)), 'c:\test.exe', TRUE);
end;
Popov
Gast
Erhaltene Danke: 1



BeitragVerfasst: Mo 17.02.03 23:05 
Ich leg noch einen drauf:

ausblenden Quelltext
1:
2:
3:
4:
procedure CopyToFile(ExistingFileName, NewFileName: String);
begin 
  CopyFile(PChar(ExistingFileName), PChar(NewFileName), TRUE); 
end;


Und schon kann derDoc sein CopyToFile benutzen ;)

ausblenden Quelltext
1:
CopyToFile(Application.ExeName, 'C:\Programme\Bla\Programm.exe');					
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 17.02.03 23:07 
Also den Schritt, das jetzt in eine Prozedur zu verpacken, hätte ich ihm jetzt aber zugetraut. :roll:
DaRkFiRe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 526

WinXP Home & Professional
C, C++, Delphi
BeitragVerfasst: Mo 17.02.03 23:42 
Also - das kann er doch nicht machen!!! *schreck*
Das kann er doch nicht... argh!

_________________
Lang ist der Weg durch Lehren - kurz und wirksam durch Beispiele! Seneca
derDoc Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Di 18.02.03 15:51 
Also erstmal danke an all die, die mir hier konstruktiv halfen.

Besonderen Dank an Popov, der mir endlich beibrachte, wie man Proceduren selbstschreibt. :wink:

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Popov
Gast
Erhaltene Danke: 1



BeitragVerfasst: Di 18.02.03 20:40 
Hab ich gerne getan.
ShadowCaster
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 312



BeitragVerfasst: Fr 21.03.03 10:46 
naja, der copyfile-befehl dürfte nicht sehr schnell sein. Ich hab es mit einem BlockRead und einem 2MB PChar-Buffer gemacht. Damit hab ich Dateien auf der Platte doppelt so schnell hin und her kopiert wie der Windows-Explorer (der die Windows-Api benutzt wie auch der copyfile-befehl vermutlich).

Wenn ich was falsches sage, korrigiert mich. Aber eine Exe ist ja nicht so groß und da kommt es ja sicher nicht auf Speed an, es sei denn man will einen Exe-Worm schreiben, der 2000 Kopien von sich auf der Platte in 2-3 Minuten erstellt. :twisted: