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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

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
simonetCommented:
>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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.