Jump to content

Using system() function with a different shell user.


wesleytabaka

Recommended Posts

Hey guys.  I got a little problem.  I'm trying to set up a PHP script that'll execute an external application, vlc.exe (VideoLAN Player).  Here's what I used:

<?php
$run=`start "VLC" "C:\Program Files\VideoLAN\VLC\vlc.exe"`;
echo $run;
?>

 

My Server Details:

Windows XP SP2 (Win32)

Apache Server 2

PHP 5.0.5

 

 

And it runs it, but with a different user for the process.  If you open up Windows Task Manager, and click the Processes tab, it lists processes by "Image Name", "User Name", "CPU", and "Mem Usage".  The script above executes the vlc.exe, it shows up on Task Manager, but with the User Name "SYSTEM", I guess because PHP ran it.  I need it to run with the User Name "Wesley Tabaka", my User Name.  That's because when it runs on the SYSTEM account, it runs in the background and freezes PHP because PHP is waiting for a response from vlc.exe.

 

So, is there any way to execute something in command prompt/shell using a different User Name?

 

Thanks in Advance! ;D

Link to comment
Share on other sites

Hummm.. first question is why.. the reason i ask is, it maybe a problem.. as you could do this

 

<?php
$run=`runas \user:"Wesley Tabaka" "VLC" "C:\Program Files\VideoLAN\VLC\vlc.exe"`;
echo $run;
?>

 

BUT it requires a password to be entered, and theirs no way to add it onto the CLI.. and blank passwords are not allowed!

 

Other Option..

start->run->services.msc

find apache or wampapache (if using wamp)

double click and select the logon tab

change to this account and enter username and password

Link to comment
Share on other sites

Terrific!  I really appreciate it.  It ran as my username and it starts up and everything!  The only problem is that PHP still freezes because it wants a response from the command prompt.  I tried to set a 5 second timeout, just so it wouldn't hang forever.  I tried doing ini_set("max_execution_time", 5); and I also tried to do set_time_limit(5);

 

Neither of them worked.

 

And it's not like it times out after the default 30 seconds, either.  It goes forever.  Anything I can do?

 

Here's the entire script:

<?php
ini_set("max_execution_time", 5);
error_reporting(E_ALL);
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>[' . $_SERVER["PHP_AUTH_USER"] . '] Webcam Daemon</title>
<link rel="stylesheet" type="text/css" href="style.css.php" />
</head>
<body>
<center>
<br />
<table class="table" cellspacing="0" style="text-align:center;width:300px;height:150px">
<tr><td class="header">Camera Daemon</td></tr>
';
function camera(){
return ($cam=fsockopen("192.168.1.2", 527, $errstr, $errno, "2") ? true : false);
fclose($cam);
}
if(!$_POST){
echo '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
if(camera()){
	//Write Disable button if on...
	echo '<input type="hidden" name="type" value="disable" />
	<tr><td class="cell"><input type="submit" value="Disable Camera" /></td></tr>';
}
else {
	//Write Enable button if off...
	echo '<input type="hidden" name="type" value="enable" />
	<tr><td class="cell"><input type="submit" value="Enable Camera" /></td></tr>';
}
echo '</form>';
}
else {
echo '<tr><td class="cell">';
if($_POST["type"]=="disable"){
	echo '<!--';
	system("kill -f vlc.exe");
	echo '-->Camera Disabled';
}
else {
	//echo '<!--';
	$sys_cmd=`start "title" "C:\Program Files\VideoLAN\VLC\vlc.exe" dshow:// :dshow-vdev="IBM PC Camera" :dshow-adev="none" :dshow-size="" :dshow-caching=200 :dshow-chroma="" :dshow-fps=10.000000 :no-dshow-config :no-dshow-tuner :dshow-tuner-channel=0 :dshow-tuner-country=0 :dshow-tuner-input=0 :dshow-video-input=-1 :dshow-audio-input=-1 :dshow-video-output=-1 :dshow-audio-output=-1 --sout=#transcode{vcodec=DIV3,vb=64,scale=1}:duplicate{dst=display,dst=std{access=http,mux=asf,dst=192.168.1.2:527}}`;
	echo $sys_cmd . '|';
	//system($sys_cmd, $retval);
	echo 'Camera Enabled';
	//print_r($retval);
}
echo '</td></tr>';
}
echo '</form>
</table>
</center>
</body>
</html>';
?>

 

Any obvious errors?  Maybe because PHP flushes output after a command prompt query it takes forever?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.