execute .bat file using php on web
sorry for not writing in dutch. the reason I am in this forum is purely that I live in holland :-)
expecting some help from PHP experts.
started my first task in php.
1. i have a simple web application which must execute a .bat file.
2. when execution finished it shall display the results to users
i am using
xampp on windows 10.
the main issue is, due to system policy, i can only execute a .bat file in administrator mode.
Below code works:
=================
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
echo
exec('whoami');
exec('cd C:\softwares && dir >> temp.log');
//exec('dir');
$file = 'C:\softwares\temp.log';
$orig = file_get_contents($file);
$a = htmlentities($orig);
echo '<code>';
echo '<pre>';
echo $a;
echo '</pre>';
echo '</code>';
//echo file_get_contents( "c:\softwares\temp.log" );
?>
echo
exec('whoami');
exec('cd C:\softwares && dir >> temp.log');
//exec('dir');
$file = 'C:\softwares\temp.log';
$orig = file_get_contents($file);
$a = htmlentities($orig);
echo '<code>';
echo '<pre>';
echo $a;
echo '</pre>';
echo '</code>';
//echo file_get_contents( "c:\softwares\temp.log" );
?>
below code do not work :
========================
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
echo
exec('whoami');
exec('cd C:\softwares && testMyNameExists.bat >> temp.log');
//exec('dir');
$file = 'C:\softwares\temp.log';
$orig = file_get_contents($file);
$a = htmlentities($orig);
echo '<code>';
echo '<pre>';
echo $a;
echo '</pre>';
echo '</code>';
//echo file_get_contents( "c:\softwares\temp.log" );
?>
echo
exec('whoami');
exec('cd C:\softwares && testMyNameExists.bat >> temp.log');
//exec('dir');
$file = 'C:\softwares\temp.log';
$orig = file_get_contents($file);
$a = htmlentities($orig);
echo '<code>';
echo '<pre>';
echo $a;
echo '</pre>';
echo '</code>';
//echo file_get_contents( "c:\softwares\temp.log" );
?>
I understand that 'web user' should be run in Administrator mode. But i dont get which files has to be modified..
anyhelp is appreiciated. Thanks.
And on that note, what are you trying to achieve through this .bat file. Perhaps there is another / better way to achieve whatever it is you are trying to do with said file.
Also (first Google result) have you tried to run a .bat file like this?
Gewijzigd op 04/01/2019 19:24:52 door Thomas van den Heuvel
Also, paths need to have \\ instead of \, otherwise the \ won't even show up.
Thanks for your tips.
the link has helped a little but I landed again at same situation as where I started. It executed the .bat file but i have issue with my system policy. I must run the bat file in 'admin' mode otherwise I am seeing following message.
"This program is blocked by group policy. For more information, contact your system administrator."
>what is the necessity to use a .bat file specifically?
mainly because It is a application from oracle and I am used to running it always on commandLine.
Now I want to let other users run the .bat and execute it too remotely. thus web application.
>Perhaps there is another / better way to achieve whatever
This may be a good idea but it shall test my newbie php skills :-)
by the way, >Also, paths need to have \\ instead of \, otherwise the \ won't even show up.
the double or single did not made difference in my tests.
Shanker somanchi op 05/01/2019 13:53:35:
This is due to the (interactive use) architecture of windows. Run this on a unix or Linux system and you can control the proper rights for execution. You where saying: It is an application from oracle or something like that but Oracle has left windows many years ago so are you still running Oracle on windows??the link has helped a little but I landed again at same situation as where I started. It executed the .bat file but i have issue with my system policy. I must run the bat file in 'admin' mode otherwise I am seeing following message.
"This program is blocked by group policy. For more information, contact your system administrator."
"This program is blocked by group policy. For more information, contact your system administrator."
However may be you will find some answers here:
https://stackoverflow.com/questions/18755553/automatically-running-a-batch-file-as-an-administrator using Powershell on windows
Gewijzigd op 05/01/2019 16:43:22 door Aad B