1

I want to change focus window from browser to another app using PHP, on Windows local machine.

I want to make a scenario, like: User will access via browser, input some code. If the code is correct then PHP will change focus window from browser to Microsoft Word (for example). Only change the focus window, Ms Word already started.

Thinking of using system(), exec(), or shell_exec() in php to run a .bat file, but still didn't work.

swith-to-word.bat

echo new ActiveXObject("WScript.Shell").AppActivate("Microsoft Word"); > tmp.js
cscript //nologo tmp.js & del tmp.js

php

system('cmd /c C:\Users\User\Sites\admin\public\commands\swith-to-word.bat');

I want to run this scenario only in server locally, won't be accessed by another client.

Anyone has suggestions to this scenario? Thank you in advance

brobrobrobrobro
  • 315
  • 4
  • 18
  • 1
    Nope, there should be no way to do that without exploiting a zero-day. – Martheen Jul 06 '22 at 02:25
  • what do you mean by exploiting zero-day? – brobrobrobrobro Jul 08 '22 at 03:06
  • https://en.wikipedia.org/wiki/Zero-day_(computing) A webpage launching an arbitrary process in the user system is a massive security hole, it could tell the system to download malware, stole user files etc. – Martheen Jul 08 '22 at 03:14
  • https://stackoverflow.com/questions/80650/how-do-i-register-a-custom-url-protocol-in-windows would work but the user must explicitly install your app first – Martheen Jul 08 '22 at 03:17
  • maybe there is a misunderstanding, this command will run only in server locally – brobrobrobrobro Jul 08 '22 at 03:22
  • As in, both the browser and the server is running in the same server? In that case, you need to modify the account for the IIS/XAMPP running the server because the batch file is run under that account and the default account doesn't have enough permission to interact – Martheen Jul 08 '22 at 03:35
  • Yes, both will running on server. I'm using Laravel Valet on windows, Valet utilizes Nginx, so something has to do with Nginx. Am I right? – brobrobrobrobro Jul 08 '22 at 04:38
  • 1
    Yep, Nginx is configured to use the default service account by default. – Martheen Jul 08 '22 at 04:40

0 Answers0