Jump to content

Having issues with running CMD script

Hi, 

I'm building a Web application for personal use to administer my CSGO server remotely.

 

So far i've got it working. However there's a small problem.

Here's how it works:

1. The user logs into the web app.

2. The user clicks an operation for instance "Start Server".

3. The php script will launch the following function: exec("cmd /c $dir" . "start.bat");

The start.bat file contains the following: start C:\Users\jeroen\Desktop\srcds.lnk

(That's a link to the srcds software with proper launch options included).

4. The server executes the command and it works.

 

Here's the issue. Only when the script is ran by the php function, it'll run the server in session 0 isolation.

This is what it looks like:

7651a860331eae087f623dfd234fb4b3.png

However, when the .bat file is run manually, it opens the server in a normal cmd window.

 

Here's what i need to know

1. What's causing the php function to open the cmd shell in session 0 isolation? And how can i prevent it from doing so?

2. Is there a better/more efficient way to obtain the same result?

 

CPU:

Intel Core i5 2500k - Motherboard: Asus maximus iv gene-z - RAM: 2x Corsair Vengeance Blue 4GB DDR3-1600 CL9 - GPU: ASUS GTX 770 DirectCU II
Case: Coolermaster Centurion 5 II - Storage: Crucial M4 128GB, Seagate barracuda 3TB PSU: XFX 650W XXX Edition Modular PSU - Keyboard: Ducky Shine 2 Pro
Mouse: Razer Deathadder 2013 - Sound: Razer Characias
Link to comment
https://linustechtips.com/topic/311681-having-issues-with-running-cmd-script/
Share on other sites

Link to post
Share on other sites

Since exec doesn't return input you should try to use system() and then echo the output it gives you to debug.

I don't actually need output in my browser. Maybe I should have clarified that more.

When i mstsc into my server i want to be able to see the cmd shell. So i can see what's going on.

CPU:

Intel Core i5 2500k - Motherboard: Asus maximus iv gene-z - RAM: 2x Corsair Vengeance Blue 4GB DDR3-1600 CL9 - GPU: ASUS GTX 770 DirectCU II
Case: Coolermaster Centurion 5 II - Storage: Crucial M4 128GB, Seagate barracuda 3TB PSU: XFX 650W XXX Edition Modular PSU - Keyboard: Ducky Shine 2 Pro
Mouse: Razer Deathadder 2013 - Sound: Razer Characias
Link to post
Share on other sites

I don't actually need output in my browser. Maybe I should have clarified that more.

When i mstsc into my server i want to be able to see the cmd shell. So i can see what's going on.

Wait are you trying to execute a batch file from php and get the visual terminal to open or what? If so you're not going to really be able to do that with a system call.

i want to die

Link to post
Share on other sites

Wait are you trying to execute a batch file from php and get the visual terminal to open or what? If so you're not going to really be able to do that with a system call.

Yes I'm trying to do that. And is there a suitable way with for instance AJAX or something to get live output in the browser instead?

CPU:

Intel Core i5 2500k - Motherboard: Asus maximus iv gene-z - RAM: 2x Corsair Vengeance Blue 4GB DDR3-1600 CL9 - GPU: ASUS GTX 770 DirectCU II
Case: Coolermaster Centurion 5 II - Storage: Crucial M4 128GB, Seagate barracuda 3TB PSU: XFX 650W XXX Edition Modular PSU - Keyboard: Ducky Shine 2 Pro
Mouse: Razer Deathadder 2013 - Sound: Razer Characias
Link to post
Share on other sites

Yes I'm trying to do that. And is there a suitable way with for instance AJAX or something to get live output in the browser instead?

You'd be better off using linux as a platform for something like this because then you could more easily make a tcp server or something and send commands to it and receive live output with ajax more easily.

i want to die

Link to post
Share on other sites

You'd be better off using linux as a platform for something like this because then you could more easily make a tcp server or something and send commands to it and receive live output with ajax more easily.

Decisions were made in the past ;)

When I bought the server there were issues with the LAN adapter drivers. So i temporarely installed windows on it, since driver issues are more easily resolved. 

 

But then i went on installing more and more and now we've come to this point.

 

I guess i can reinstall everything all over again on linux but that'd take too long for too little functionality.

 

I guess i'll have to do with this then.

CPU:

Intel Core i5 2500k - Motherboard: Asus maximus iv gene-z - RAM: 2x Corsair Vengeance Blue 4GB DDR3-1600 CL9 - GPU: ASUS GTX 770 DirectCU II
Case: Coolermaster Centurion 5 II - Storage: Crucial M4 128GB, Seagate barracuda 3TB PSU: XFX 650W XXX Edition Modular PSU - Keyboard: Ducky Shine 2 Pro
Mouse: Razer Deathadder 2013 - Sound: Razer Characias
Link to post
Share on other sites

You'd be better off using linux as a platform for something like this because then you could more easily make a tcp server or something and send commands to it and receive live output with ajax more easily.

Actually, it stuck with me on the bus ride. And it isn't actually as much work as I initially thought. So right now I'm going to backup any necessary data and migrate to Ubuntu Server.

CPU:

Intel Core i5 2500k - Motherboard: Asus maximus iv gene-z - RAM: 2x Corsair Vengeance Blue 4GB DDR3-1600 CL9 - GPU: ASUS GTX 770 DirectCU II
Case: Coolermaster Centurion 5 II - Storage: Crucial M4 128GB, Seagate barracuda 3TB PSU: XFX 650W XXX Edition Modular PSU - Keyboard: Ducky Shine 2 Pro
Mouse: Razer Deathadder 2013 - Sound: Razer Characias
Link to post
Share on other sites

Actually, it stuck with me on the bus ride. And it isn't actually as much work as I initially thought. So right now I'm going to backup any necessary data and migrate to Ubuntu Server.

PURE DEBIAN MASTER RACE

If you need any help with linux feel free to let me know.

i want to die

Link to post
Share on other sites

PURE DEBIAN MASTER RACE

If you need any help with linux feel free to let me know.

I got the linux server up and running at around 7 last night. 

Only thing i don't know anything about is AJAX. So I either need to learn AJAX or some pre-configured script.

CPU:

Intel Core i5 2500k - Motherboard: Asus maximus iv gene-z - RAM: 2x Corsair Vengeance Blue 4GB DDR3-1600 CL9 - GPU: ASUS GTX 770 DirectCU II
Case: Coolermaster Centurion 5 II - Storage: Crucial M4 128GB, Seagate barracuda 3TB PSU: XFX 650W XXX Edition Modular PSU - Keyboard: Ducky Shine 2 Pro
Mouse: Razer Deathadder 2013 - Sound: Razer Characias
Link to post
Share on other sites

I got the linux server up and running at around 7 last night. 

Only thing i don't know anything about is AJAX. So I either need to learn AJAX or some pre-configured script.

ajax is used to post / get php.

just google how to post PHP with ajax.

i want to die

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×