PHP – System program execution on Windows (XP, VISTA, 7)


(Maksud tulisan dibawah, Loe bakal punya masalah kalo nge execute application pake exec() / system() punya PHP  di win vista dan win 7 ane udah coba ga, misal ane nge execute notepad di windows dan ternyata ga jalan supaya jalan copiin httpd.exe  ke start up folder trus restart pc agan lalu coba script buat ngejalanin. .exe berikut (pastiin si httpd.exe nyala waktu start up okeh ):

/////code // jangan lupa gan pake jquery

<?php
if (isset($_POST[‘request’])) {
if ($_POST[‘act’] == ‘1’) {
echo $_POST[‘request’].”<br>”;
$output = system($_POST[‘request’]);
die(“<pre>$output</pre>”);
}
} else {
?>
<div id=”mainbox” style=”background:black;color:white;”></div>
<pre><div id=”pwd”></div> &nbsp; <input type=”text” id=”input1″></pre>
<script src=”jquery.js” type=”text/javascript”></script>
<script type=”text/javascript”>
$(‘input#input1’).keypress(function(e) {
if(e.which == 13) {
input = $(“input#input1”).val();
$.post(‘#’,{request:input,act:’1′}, function(data) {
$(“div#mainbox”).html(”);
$(“div#mainbox”).html(‘<h3>Execute Server</h3>’ + data);
$(“input#input1”).val(“”);
$(“input#input1”).focus();
});
}

});
</script>

<?php
}
?>

////end of code

)

User Contributed Notes Program execution
Joe Engel 31-Dec-2008 10:46
If you try to launch GUI apps from a service in Vista, you’ll have lots of trouble.  As a security feature, Vista mediates the interaction of services with the desktop using ‘Interactive Services Detection’.

That means, if you are running PHP as a module of an Apache service, you won’t be able to launch GUI apps using any method.  This kind of thing just won’t work:

$WshShell = new COM(“WScript.Shell”);
$oExec = $WshShell->Run(“notepad.exe”, 7, false);

So, if you want to use Apache/PHP as a proxy for launching GUI apps, you’ll need to run Apache as a console application.

First, if Apache is already installed as a service, you’ll need to set it’s startup type to “manual” using the services snap-in.  (%SystemRoot%\system32\services.msc)  Search for Services in the start menu search box.

Then add a shortcut to C:\apache\bin\httpd.exe (or wherever Apache is installed) to your Startup folder, and set that shortcut to start minimized. You can use an app like TrayIt! to force Apache down into the system tray.

Then use any of the methods outlined on the PHP website and you will be able to open a Windows application from PHP and see it’s GUI.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s