1

I am developing a web interface that will take care of changing colors in several Excel files.

For this, I try to run a .bat script that launches a .vbs script. I do all this server side (on an intranet machine so total access) that I configured with wamp (Apache 2.4.37 and PHP 7.2.14).

The problem is that the php page does not execute the script and run the browser in a infinite loop. My line for the script:

exec ('launch_vbs.bat');

I tried :

  • with system () and passthru (), no change.

  • to put the whole way, no change.

  • to specify chmod to 777 on my launch_vbs.bat file, no change

  • to add 2> & 1 at the end, no change.

  • to launch my file launch_vbs.bat in command line on the server, everything is done correctly, it modifies the colors of my excel files

  • to launch the php page containing the exec () in the command prompt of my server, the exec () is done correctly and the colors are modified in excels

My .bat and .vbs files (and even .php) are all in the same directory in the wamp server folder (C:/wamp64/www/MyProject/)

In short, I hold a little and I do not know what to do ... If anyone has an idea it would be great!

Thank you in advance !

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Yeloda
  • 21
  • 5
  • What's the exec errno? ([How can I debug exec() problems?](//stackoverflow.com/q/12199353)) – mario Mar 18 '19 at 14:55
  • Also, if launch_vbs tries to interface with Excel COM, you might have more substantive problems. – mario Mar 18 '19 at 15:00
  • I don't have any return from the output since the command exec() is running in an infinite loop – Yeloda Mar 18 '19 at 15:05
  • my .vbs script read every Excel file in a directory, and change the color of a cell depending on his value – Yeloda Mar 18 '19 at 15:21
  • PD of [Application throws an error when launched from task scheduler](//stackoverflow.com/q/23290512) (check the eventvwr, UAC account, use tasksched for invocation, possibly port to Powershell, etc.) – mario Mar 18 '19 at 15:30
  • OMG ! It worked ! By just creating the folder Desktop in C:\Windows\SysWOW64\config\systemprofile\, the command is running perfectly ! And the best thing is, i have no idea why ! thank you very much for your help ! – Yeloda Mar 18 '19 at 15:43

1 Answers1

0

Did you try to actually give the exact same command that you give in cmd like:

exec('start launch_vbs.bat');

Or using system:

  system('cmd /c launch_vbs.bat');

note that cmd is the one running inside system32 of windows. That means that if you replace cmd with "C:\Windows\System32\cmd.exe" it should work as well. Source!!!

Edit:

Your bat file should trigger the execution of your vbs script. So it should look similar to:

@echo off 
start C:\wamp64\www\ODR\change_color.vbs
pr1nc3
  • 8,108
  • 3
  • 23
  • 36
  • Yes, it doesn't change anything. I wonder if the username can cause this problem. I assume exec() is trying to run my bat file with the www username, whereas with the cmd, i launch it with the admin username. That's the only reason i can think of – Yeloda Mar 18 '19 at 15:05
  • Yes you need to run it as admin. If you try to add the user that tries to execute the script as administrator that would give a great insight of where the problem is. – pr1nc3 Mar 18 '19 at 15:06
  • Ok so how do i do that ? i tried to add runas /user:administrator but didn't seem to change anything. – Yeloda Mar 18 '19 at 15:15
  • exec("whoami"); Try this command just to be sure that you are not running as admin – pr1nc3 Mar 18 '19 at 15:21
  • This is what i got : Array ( [0] => nt authority\system ) – Yeloda Mar 18 '19 at 15:24
  • Then you run the script as an admin. This is the top privilege for your local environment. – pr1nc3 Mar 18 '19 at 15:25
  • exec('start /launch_vbs.bat') doesn't even launch the bat file, and system is running an infinite loop. – Yeloda Mar 18 '19 at 15:33
  • Then that means that the previous one was launching the bat file. Maybe the error is IN the bat file itself? – pr1nc3 Mar 18 '19 at 15:34
  • Well, it's just calling my .vbs file like : C:\wamp64\www\ODR\change_color.vbs – Yeloda Mar 18 '19 at 15:36
  • But how are you trying to run it? There should be a command inside the bat file that actually runs the vbs script. Edited my answer. – pr1nc3 Mar 18 '19 at 15:39
  • @mario found the solution (Well, showed me where to look), i had to create a folder Desktop in C:\Windows\SysWOW64\config\systemprofile\ and now the program is running correctly. Thank you anyway for your time and help ! – Yeloda Mar 18 '19 at 15:46
  • Glad you got it working :) – pr1nc3 Mar 18 '19 at 15:47