note 43917 modified in function.exec by danbrown
| From: | danbrown@php.net | Date: | Sun, 04 Jan 2009 16:31:19 +0000 |
| Subject: | note 43917 modified in function.exec by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-148810@lists.php.net to get a copy of this message | ||
I too wrestled with getting a program to run in the background in Windows while the script continues
to execute. This method unlike the other solutions allows you to start any program minimized,
maximized, or with no window at all. llbra@phpbrasil's solution does work but it sometimes
produces an unwanted window on the desktop when you really want the task to run hidden.
start Notepad.exe minimized in the background:
<?php
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("notepad.exe", 7, false);
?>
start a shell command invisible in the background:
<?php
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("cmd /C dir /S %windir%", 0, false);
?>
start MSPaint maximized and wait for you to close it before continuing the script:
<?php
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("mspaint.exe", 3, true);
?>
For more info on the Run() method go to:
http://msdn.microsoft.com/library/en-us/script56/html/wsMthRun.asp
--was--
I too wrestled with getting a program to run in the background in Windows while the script continues
to execute. This method unlike the other solutions allows you to start any program minimized,
maximized, or with no window at all. llbra@phpbrasil's solution does work but it sometimes
produces an unwanted window on the desktop when you really want the task to run hidden.
start Notepad.exe minimized in the background:
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("notepad.exe", 7, false);
start a shell command invisible in the background:
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("cmd /C dir /S %windir%", 0, false);
start MSPaint maximized and wait for you to close it before continuing the script:
$WshShell = new COM("WScript.Shell");
$oExec = $WshShell->Run("mspaint.exe", 3, true);
For more info on the Run() method go to:
http://msdn.microsoft.com/library/en-us/script56/html/wsMthRun.asp
http://php.net/manual/en/function.exec.php