Jump to content











Photo
- - - - -

QuickLaunch


  • Please log in to reply
2 replies to this topic

#1 Brito

Brito

    Platinum Member

  • .script developer
  • 10616 posts
  • Location:boot.wim
  • Interests:I'm just a quiet simple person with a very quiet simple life living one day at a time..
  •  
    European Union

Posted 17 April 2007 - 08:14 PM

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.89KB   531 downloads

Here is the batch file:
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:

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...&...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! :cheers:

#2 thunn

thunn

    Silver Member

  • .script developer
  • 531 posts
  • Location:Brooklyn, New York
  • Interests:computers<br />mechanics<br />distortion<br /><br />
  •  
    United States

Posted 17 April 2007 - 08:41 PM

I'll try compiling the following.. :cheers: :cheers:
If FileExists&#40;&#39;B&#58;\Avast4\Data\dl.exe&#39;&#41; then ShellExecAndWait&#40;&#39;B&#58;\Avast4\Data\dl.exe&#39;,&#39;http&#58;//download4.avast.com/files/latest/400.vps /output&#58;B&#58;\Avast4\Data\400.vps /update&#39;,&#39;minimize&#39;&#41;

	  else

	   begin

		 ShellExecAndWait&#40;&#39;avastav.exe&#39;,&#39;x -y -oB&#58;\Avast4\&#39;, &#39;minimize&#39;&#41;;

		 ShellExecute&#40;Handle, &#39;open&#39;, pChar&#40;&#39;B&#58;\Avast4\ashSimp.exe&#39;&#41;, PChar&#40;&#39;&#39;&#41;, &#39;&#39;, SW_MINIMIZE&#41;;

	   end;


#3 MedEvil

MedEvil

    Platinum Member

  • .script developer
  • 7771 posts

Posted 17 April 2007 - 09:03 PM

:cheers:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users