Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 1 of 1 total
Thread Workstation: program file or shortcut
Sun, Nov 23 2014 3:06 PMPermanent Link

Aage J.

See the thread "Workstation: program file or shortcut" in
elevatesoft.public.elevatedb.general [started 21.11.2014]

This is an old version but it should do the job.  It is using WinExec,
maybe someone could change that to "CreateProcess" or something more modern.
It will start the newest exe file with filename starting with "QExec".
Rename it to MYPROG.exe and it will start the newest version of
MYPROG*.exe (in the same folder).
I didn't write this code myself, but have since adapted it to also start
*.chm files in the same way (not this version, however).



program QExec;

uses
  Forms, Windows, SysUtils;

{$R *.RES}

  const Null = 0;

  function NewestApplicationFileInCurrentDirectory: TFileName;

  var
    ExtensionLength, PathLength: Cardinal;
    FilePath: TFileName;
    SearchRec: TSearchRec;
    NewestTimeSoFar: Integer;
    ReturnCode: Integer;

  begin
    PathLength:=Length(Application.ExeName);
    ExtensionLength:=Length(ExtractFileExt(Application.ExeName));
    FilePath:=
      Copy(Application.ExeName, 1, PathLength - ExtensionLength) +
           '*'; // Add wild card
    Result:='';
    NewestTimeSoFar:=0;
    if FindFirst(FilePath, faAnyFile, SearchRec) = 0 then
    begin
      if
        (SearchRec.Name <> ExtractFileName(Application.ExeName)) and
        (ExtractFileExt(SearchRec.Name) =
                               ExtractFileExt(Application.ExeName))
      then
      begin
        NewestTimeSoFar:=SearchRec.Time;
        Result:=SearchRec.Name
      end;
      repeat
        ReturnCode:=FindNext(SearchRec);
        if
          (ReturnCode = 0) and
          (SearchRec.Time > NewestTimeSoFar) and
          (SearchRec.Name <> ExtractFileName(Application.ExeName)) and
          (ExtractFileExt(SearchRec.Name) =
                            ExtractFileExt(Application.ExeName))
        then
        begin
          NewestTimeSoFar:=SearchRec.Time;
          Result:=SearchRec.Name
        end
      until ReturnCode <> 0
    end;
    FindClose(SearchRec)
  end;

  var ApplicationToStart: string;

begin
  Application.Initialize;
  ApplicationToStart:='"'+NewestApplicationFileInCurrentDirectory + '"';
  WinExec(PChar(ApplicationToStart), SW_SHOW);
  Application.Run
end.





--
Aage J.
Image