ExecuteFile isn't working with DOS programs

ExecuteFile isn't working with DOS programs living in CD

Help!, I'm making a install program that runs from a CD, all is working fine in the Hard Disk, but not in the CD...

I have:

 ExecuteFile(game.run, '', game.dir + '\', SW_SHOW);

{  ExecuteFile(game.run, '', getCurrentDir + '\' + game.dir + '\', SW_SHOW); <- this was the original, but it dosen't work either}

When is a win95/98 program it works ok, but when is a DOS program puts an error saying that cannot find the file, (the path and the file name is ok), when I click the program directly in the CD it runs.

also when I use:

   SetCurrentDir(sdir);
   SetCurrentDir(editPath.text);
   CopyDirectory(sdir + '\' + game.dir + '\*.*', editPath.text);

an error ocurrs: "cannot copy file: File System Error (1026)"

like I said all works fine in my Hard Drive!!!! HELP!


I'm using Win98/Delphi 3
-----------------------------------------------
procedure CopyDirectory(const Source, Destination:string);
var
  MyStruct: TSHFileOpStruct;
  Src, Dst : array[0..256] of byte;
begin
   if not(DirectoryExists(Destination)) then
      ForceDirectories(Destination);
   FillChar(src, SizeOf(src), 0);
   FillChar(dst, SizeOf(dst), 0);
   StrPCopy(@Src, Source + #0 + #0);
   StrPCopy(@Dst, Destination + #0 + #0);
   with MyStruct do begin
      pFrom := pchar(@Src);
//      pFrom := pchar(Source + #0 + #0);
      Wnd := 0;
      wFunc := FO_COPY;
//      fFlags := FOF_ALLOWUNDO;
      fFlags := FOF_SIMPLEPROGRESS or FOF_RENAMEONCOLLISION or FOF_NOCONFIRMMKDIR;
      pTo := pchar(@Dst);
//      pTo := pchar(destination + #0 + #0);
   end;
   SHFileOperation(MyStruct);
end;
------------------------------------
function ExecuteFile(const FileName, Params, DefaultDir: string;
  ShowCmd: Integer): THandle;
var
  zFileName, zParams, zDir: array[0..79] of Char;
begin
  Result := ShellExecute(Application.MainForm.Handle, nil,
    StrPCopy(zFileName, FileName), StrPCopy(zParams, Params),
    StrPCopy(zDir, DefaultDir), ShowCmd);
end;

thanks in advance

Cesar
cesarrdzAsked:
Who is Participating?
 
simonetConnect With a Mentor Commented:
>I can't use the cd drive letter in the
>directory

That's why it's not working. You must first detect the letter of the CD drive and append it to the beggining of the executable filename.

Luckyly it's easy to detect the letter of the CD-ROm drive when the app is started from it:

var
 CDRomDrive : string;
begin
 CDRomDrive := Copy(ExpandFileName(application.exename), 1, 2);
 { The above will return something like "E:" or "F:" or whatever }

Try appending that to the parameter passed to Madshi's ExecuteFile procedure.

Yours,

Alex
0
 
rwilson032697Commented:
You will need to run command.com like this in the argument to ExecuteFile:

command.com /C z:\myprog.exe

Where z: is your CDRom drive

Not sure about the copy directory.

Cheers,

Raymond.
0
 
MadshiCommented:
Try this:

function ExecuteFile(const FileName, Params, DefaultDir: string;
  ShowCmd: Integer): THandle;
begin
  Result := ShellExecute(Application.MainForm.Handle, nil,
    pchar(FileName), pchar(Params),
    pchar(DefaultDir), ShowCmd);
end;

Easier, faster and has no restriction to 79 (or whatever) characters.

Doesn't that work either?

How does FileName look like? Please give us the parameters of the failing ExecuteFile in detail.

Regards, Madshi.
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
simonetCommented:
You must remember that, in order to use these Win32 API calls, you must be in a DOS Prompt box, not in DOS without having Windows running in the background (even "Restart in MS-DOS" mode won't work).

Alex
0
 
cesarrdzAuthor Commented:
Thanks...
Raymond I used the command.com /c but it doesn't work...

ExecuteFile('command.com /c ' + game.ejecuta, '', game.dir + '\', SW_SHOW);

and

ExecuteFile('command.com /c h:\' + game.ejecuta, '', 'h:\'+game.dir + '\', SW_SHOW);


Madshi, I used your function but it doesn't work either... the parameters of executefile are for example:

ExecuteFile('bs_aog.exe', '', 'blake\', SW_SHOW);

I can't use the cd drive letter in the directory because I want that works in every cd drive...

I used the getCurrentDir:

ExecuteFile('bs_aog.exe', '', GetCurrentDir + 'blake\', SW_SHOW);


Alex, the program is working in Windows, is a little browser that I need to run from a CD, and when the user clicks in a program name just run it, with the windows programs it runs ok, but no with the Dos programs (old  dos programs)


0
 
cesarrdzAuthor Commented:
Edited text of question.
0
 
cesarrdzAuthor Commented:
Adjusted points to 250
0
 
MadshiCommented:
Yes, Alex is right.

You should not use GetCurrentDir. That's not a good idea.
I think "ExtractFilePath(Application.ExeName)" should give you what you wanted to have from GetCurrentDir.

Regards, Madshi.
0
 
cesarrdzAuthor Commented:
Thank you very much!
0
All Courses

From novice to tech pro — start learning today.