Digg this topic Add to my del.icio.us Submit to SlashDot  
Reply to this topicStart new topic
> QuickLaunch, Smallish console app to launch programs
Nuno Brito
post Apr 17 2007, 08:14 PM
Post #1


Advanced Member
***

Group: .script developer
Posts: 4,280
Joined: 13-July 06
From: Azores
Member No.: 1


Portugal


Thunn has requested a small application to replace some of the actions done by a batch file when the disk is booting.

Attached File  Project___2007___QuickLaunch.7z ( 22.89K ) Number of downloads: 32


Here is the batch file:
CODE
if exist B:\Avast4\Data\dl.exe goto run
               start /min /wait avastav.exe x -y -oB:\Avast4\
               ::primer
               start B:\Avast4\ashSimp.exe
               :run
               start /min /wait B:\Avast4\Data\dl.exe http://download4.avast.com/files/latest/400.vps /output:B:\Avast4\Data\400.vps /update
               start B:\Avast4\ashSimp.exe
               exit



And the respective delphi source code:

CODE
program QuickLaunch;

//{$APPTYPE CONSOLE} - this way we make this app invisible..

uses

  ShellApi,
  Windows,
  SysUtils;


var
    Handle     : THandle;
    i          : Integer;
    Parameters : String;


Procedure ShellExecAndWait(Filename, Parameters, Action : String);
// this procedure will run an application and will only continue after
// if finishes - just like "start /wait myApp.exe"
Var
   exInfo: TShellExecuteInfo;
   exitcode: DWORD;
   aAction : String;
Begin
   FillChar( exInfo, Sizeof(exInfo), 0 );
   With exInfo Do Begin
     cbSize:= Sizeof( exInfo ); // required!
     fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT;
     Wnd   := Handle;  // forms handle

     lpFile:= Pchar( Filename );
     lpParameters:= Pchar(  Parameters );

     aAction:=LowerCase(Action);

     if aAction = 'hide' then nShow := SW_HIDE else
     if aAction = 'minimize'then nShow := SW_MINIMIZE
                 else
                   nShow := SW_SHOWNORMAL;

     lpVerb    := 'open';

   End;
   If ShellExecuteEx( @exInfo ) Then Begin
      While GetExitCodeProcess( exinfo.hProcess, exitcode )
            and (exitcode = STILL_ACTIVE) // loop while process is active..
      Do begin
        sleep(100);
         end;

      CloseHandle( exinfo.hProcess );
   End;

      end; // shellexecute and wait


Label
  primer, run;


begin

// If you have at least one parameter - run it in hidden mode (like cmdow)
  if paramCount > 1 then  
  begin
       for i:=2 to paramcount do parameters := parameters + paramStr(i);
       ShellExecute(Handle, 'open', pChar(paramStr(1)), Pchar(parameters), '', SW_HIDE); // run hidden
       exit;
  end;

  // Otherwise let's do the quicklaunch imitating the following batch file code:

             { if exist B:\Avast4\Data\dl.exe goto run
               start /min /wait avastav.exe x -y -oB:\Avast4\
               ::primer
               start B:\Avast4\ashSimp.exe
               :run
               start /min /wait B:\Avast4\Data\dl.exe http://download4.avast.com/files/latest/400.vps /output:B:\Avast4\Data\400.vps /update
               start B:\Avast4\ashSimp.exe
               exit }

    If FileExists('B:\Avast4\Data\dl.exe')then goto run;

    ShellExecAndWait('avastav.exe','x -y -oB:\Avast4\', 'minimize');

    primer:
    ShellExecute(Handle, 'open', pChar('B:\Avast4\ashSimp.exe'), PChar(''), '', SW_MINIMIZE);


    run:
    ShellExecAndWait('B:\Avast4\Data\dl.exe','http://download4.avast.com/files/latest/400.vps /output:B:\Avast4\Data\400.vps /update','minimize');

{
The above code will mimic the batch file, but it can also be replaced this way to be more efficient:


    If FileExists('B:\Avast4\Data\dl.exe') then ShellExecAndWait('B:\Avast4\Data\dl.exe','http://download4.avast.com/files/latest/400.vps /output:B:\Avast4\Data\400.vps /update','minimize')
      else
       begin
         ShellExecAndWait('avastav.exe','x -y -oB:\Avast4\', 'minimize');
         ShellExecute(Handle, 'open', pChar('B:\Avast4\ashSimp.exe'), PChar(''), '', SW_MINIMIZE);
       end;

}
end.


{
Usefull info about shellexecute

Value               Meaning
SW_HIDE               Hides the window and activates another window.
SW_MAXIMIZE           Maximizes the specified window.
SW_MINIMIZE           Minimizes the specified window and activates the next  top-level window in the Z order.
SW_RESTORE            Activates and displays the window. If the window is  minimized or maximized, Windows restores it to its original  size and position. An application should specify this flag  when restoring a minimized window.
SW_SHOW               Activates the window and displays it in its current size and  position.
SW_SHOWDEFAULT        Sets the show state based on the SW_ flag specified in the  STARTUPINFO  structure passed to the  CreateProcess   function by the program that started the application. An  application should call  ShowWindow  with this flag to set the  initial show state of its main window.
SW_SHOWMAXIMIZED      Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED      Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE    Displays the window as a minimized window. The active  window remains active.
SW_SHOWNA             Displays the window in its current state. The active window  remains active.
SW_SHOWNOACTIVATE     Displays a window in its most recent size and position. The  active window remains active.
SW_SHOWNORMAL         Activates and displays a window. If the window is minimized  or maximized, Windows restores it to its original size and  position. An application should specify this flag when  displaying the window for the first time.
}


This code was based on a previous app found here:
http://www.911cd.net/forums//index.php?s=&...st&p=113007

This app also doubles as a way to launch programs in hidden mode, just add any other program as parameter and it will be executed.

Hope this helps! (IMG:http://www.boot-land.net/forums/style_emoticons/default/smile.gif)
Go to the top of the page
 
+Quote Post
thunn
post Apr 17 2007, 08:41 PM
Post #2


Advanced Member
***

Group: .script developer
Posts: 374
Joined: 27-July 06
From: Queens, New York
Member No.: 75


United States


I'll try compiling the following.. (IMG:http://www.boot-land.net/forums/style_emoticons/default/smile.gif) (IMG:http://www.boot-land.net/forums/style_emoticons/default/thumbsup.gif)
CODE
    If FileExists('B:\Avast4\Data\dl.exe') then ShellExecAndWait('B:\Avast4\Data\dl.exe','http://download4.avast.com/files/latest/400.vps /output:B:\Avast4\Data\400.vps /update','minimize')
      else
       begin
         ShellExecAndWait('avastav.exe','x -y -oB:\Avast4\', 'minimize');
         ShellExecute(Handle, 'open', pChar('B:\Avast4\ashSimp.exe'), PChar(''), '', SW_MINIMIZE);
       end;
Go to the top of the page
 
+Quote Post
MedEvil
post Apr 17 2007, 09:03 PM
Post #3


Advanced Member
***

Group: .script developer
Posts: 1,314
Joined: 29-December 06
Member No.: 2,192



(IMG:http://www.boot-land.net/forums/style_emoticons/default/laugh.gif)
Go to the top of the page
 
+Quote Post
« Next Oldest · Submit your program · Next Newest »
 

Fast ReplyReply to this topicStart new topic

Members Who Viewed Topic Today ()

 

Display Mode: Standard · Switch to: Linear+ · Switch to: Outline

Track this topic · Email this topic · Print this topic · Subscribe to this forum

RSS Lo-Fi Version Time is now: 2nd November 2007 - 11:20 PM

MKPortal ©2003-2006 mkportal.it