Сейчас на форуме: (+5 невидимых)

 eXeL@B —› Программирование —› Execute file from CD delphi
Посл.ответ Сообщение

Ранг: 55.1 (постоянный)
Активность: 0.020
Статус: Участник

Создано: 14 октября 2007 22:24
· Личное сообщение · #1

Hi :......
I need some help :
I have executable file “MY.exe” I want if Current drive is hard disk then search all CDROMS for it self “MY.exe” if fined then run “MY.exe” from CD where it is be founded.
Else If Current drive is CDROM then…..Do something).
I write code but when it runs from hard drive and call “MY.exe” from CDROM the executed file behave as it was executed from hard drive and called itself again.( program 'thinks' it is not running from cd-rom)
Here is the code:
//-------------------------------------------------------------------- -----------------------------------------------------------------
procedure check;external 'mydll.dll';
function CurDrv: Char;
var
s1: string;
s2: Char;
begin
GetDir(0,s1);
s2 := s1[1];
CurDrv := s2;
end;
//-------------------------------------------------------------------- ----------
Procedure TForm1.Protect;
var
a: Char;
wOldErrorMode : Word;
begin
wOldErrorMode :=
SetErrorMode(
SEM_FAILCRITICALERRORS ) ;
dcDiskInfo1.Disk:= CurDrv;//(Disk Controls component) i used another function but same result.
if dcDiskInfo1.DriveType=dtCDROM then
begin
check;
Application.Terminate;
end
else begin
if dcDiskInfo1.DriveType<>dtCDROM then
begin
For a := 'A' to 'Z' Do
if GetDriveType(pChar(a + ':\) = DRIVE_CDROM Then
begin
if (FileExists(a+':\BA.exe')<> false)then
begin
ShellExecute(Handle, 'open', Pchar(a+':\BA.exe'), '', '', SW_SHOWNORMAL);
end
else
Showmessage('Please inser disk in drive');
Application.Terminate;
try
finally
SetErrorMode( wOldErrorMode ) ;
end;
end;
end;
end;
end;
Thank you



Ранг: 88.3 (постоянный), 3thx
Активность: 0.040
Статус: Участник

Создано: 14 октября 2007 22:35 · Поправил: Enigma
· Личное сообщение · #2

you have mistaked here (I seem):

if GetDriveType(pChar(a + ':\) = DRIVE_CDROM Then

1. This string is invalid terminated, you have missed ' character
2. Try to eliminate \ symbol on drive name

should be:

if GetDriveType(pChar(a + ':')) = DRIVE_CDROM Then




Ранг: 247.7 (наставник), 3thx
Активность: 0.160
Статус: Участник
Халявщик

Создано: 14 октября 2007 23:02 · Поправил: depler
· Личное сообщение · #3

is it simple a protection like in some games for example?
if it is then make file size checking also.

-----
Лень - это подсознательная мудрость




Ранг: 55.1 (постоянный)
Активность: 0.020
Статус: Участник

Создано: 14 октября 2007 23:07
· Личное сообщение · #4

I write WinExec(a+':BA.exe', SW_SHOWNORMAL);
Bur error message “Can’t found file EBA.exe” so it detects Drive (E) without “:” and didn’t find path at all.



Ранг: 88.3 (постоянный), 3thx
Активность: 0.040
Статус: Участник

Создано: 14 октября 2007 23:30
· Личное сообщение · #5

abatu пишет:
I write WinExec(a+':BA.exe', SW_SHOWNORMAL);


Hey guy, you are misunderstanding, I told you to eliminate splash symbol only in GetDriveType function, other code looks ok!

this string WinExec(a+':BA.exe', SW_SHOWNORMAL); should looks like WinExec(a+':\BA.exe', SW_SHOWNORMAL);



Ранг: 55.1 (постоянный)
Активность: 0.020
Статус: Участник

Создано: 14 октября 2007 23:44
· Личное сообщение · #6

I did but still behave as it was executed from hard drive and called itself again.



Ранг: 55.1 (постоянный)
Активность: 0.020
Статус: Участник

Создано: 14 октября 2007 23:45
· Личное сообщение · #7

depler i want to call the file itself from CDROM so file size is same.



Ранг: 88.3 (постоянный), 3thx
Активность: 0.040
Статус: Участник

Создано: 15 октября 2007 00:04 · Поправил: Enigma
· Личное сообщение · #8

Did you try to debug this code? What string fails?

My advice is to change this string with GetDriveType function.
dcDiskInfo1.Disk:= CurDrv;//(Disk Controls component) i used another function but same result.

Man, for what you use this checkup "if dcDiskInfo1.DriveType<>dtCDROM then" ???
it is always return true in your case!


Amazing :-D what are you trying to handle???

try
finally
SetErrorMode( wOldErrorMode ) ;
end;



Ранг: 55.1 (постоянный)
Активность: 0.020
Статус: Участник

Создано: 15 октября 2007 00:36
· Личное сообщение · #9

Procedure TForm1.Protect;
var
a: Char;
wOldErrorMode : Word;
begin
wOldErrorMode :=
SetErrorMode(
SEM_FAILCRITICALERRORS ) ;
dcDiskInfo1.Disk:= CurDrv;
if dcDiskInfo1.DriveType=dtCDROM then
begin
check;
Application.Terminate;
end
else begin
try
For a := 'A' to 'Z' Do
begin
if GetDriveType(pChar(a + ':') = DRIVE_CDROM Then
begin
if (FileExists(a+':\BA.exe')<> false)then
begin
ShellExecute(0, 'open', Pchar(a+':\BA.exe'), '', '', SW_SHOWNORMAL);
end
else
Showmessage('Please inser disk in drive');
Application.Terminate;
finally
SetErrorMode( wOldErrorMode ) ;
end;
end;
end;
end;
end;
I got creazy what's wrong now?DIDN'T WORK still calling itself.




Ранг: 44.2 (посетитель), 69thx
Активность: 0.140.02
Статус: Участник

Создано: 15 октября 2007 02:53
· Личное сообщение · #10

And what is the point for that protection, it will be cracked less in 1 min imo..



Ранг: 129.7 (ветеран), 2thx
Активность: 0.070
Статус: Участник

Создано: 15 октября 2007 08:01
· Личное сообщение · #11

var
S:string;
I:integer;
begin
S:='S';
if GetDriveType(PChar(ExtractFileDrive(Application.ExeName)))<>DRIVE_CDRO M then
begin
for I:=67 to 90 do
begin
S[1]:=Char(I);
if GetDriveType(PChar(S+':'))=DRIVE_CDROM then
begin
If FileExists(S+':\MyFile.exe') then
begin
WinExec(PChar(S+':\MyFile.exe'),SW_SHOWNORMAL);
application.Terminate;
end;
end;
end;
end;
ShowMessage('Insert correct CD-ROM!');



Ранг: 55.1 (постоянный)
Активность: 0.020
Статус: Участник

Создано: 15 октября 2007 16:11
· Личное сообщение · #12

Thank you Azur1d it's working...


 eXeL@B —› Программирование —› Execute file from CD delphi
Эта тема закрыта. Ответы больше не принимаются.
   Для печати Для печати