How to Execute GUI Applications from PHP in a Controlled Environment
Running external processes from PHP scripts can be challenging in controlled environments where visible output from GUI programs is not allowed. Despite successful attempts to initiate silent processes using system and exec, difficulties arise when executing programs with GUI interfaces.
To address this issue, it is crucial to enable the "Allow service to interact with desktop" option for the Apache service. Navigate to Services control (e.g., via "services.msc" in Run), locate the Apache service, open its properties, and check this option under the Log On account tab.
Once this setting is configured, PHP scripts can spawn GUI processes effectively. To avoid waiting for application closure, use pclose(popen("start /B notepad.exe", "r")). Alternatively, for blocking execution, employ system('start notepad.exe'). It is worth noting that this method has been verified on Windows XP and may require adjustments for other Windows versions.
Additional Considerations:
If the Apache service is running with domain user credentials, the "Allow service to interact with desktop" option may not be available. In such cases, it is recommended to split the service into two components: one for user privileges and one for desktop interaction. This workaround, though specific to certain use cases, can save considerable frustration in the future.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3