How to Run Windows Services using VBScript from PHP on IIS – Complete Step-by-Step Guide
- Gajendra Rathod
- Apr 9
- 3 min read
In this guide, we’ll set up IIS to run PHP and execute VBScript from a PHP page. By the end, you can run background processes like launching applications or starting Windows services using PHP.
🛠 Step 1: Install IIS on Windows
Press Win + R, type appwiz.cpl, and press Enter.
Click Turn Windows features on or off.
Check Internet Information Services (IIS) and CGI (under Application Development Features).
Click OK and wait for the installation to complete.
🐘 Step 2: Install PHP on IIS
Download PHP from the official website: 🔗 PHP for Windows
Extract the ZIP file to C:\PHP.
Rename php.ini-production to php.ini and open it in Notepad.
Find and uncomment (remove ; from the beginning) the following lines:
extension_dir = "C:\PHP\ext"
fastcgi.impersonate = 1
cgi.fix_pathinfo = 1🛠️Set Environment Variables
Add C:\PHP to the system environment Path:
Right-click This PC → Properties → Advanced system settings.
Click Environment Variables.
Under System variables, select Path and click Edit.
Click New, type C:\PHP, and click OK.
⚙️ Step 3: Configure IIS for PHP
Open IIS Manager (Win + R, type inetmgr, press Enter).
Click Handler Mappings → Add Module Mapping.
Click OK, then Yes to confirm.
Restart IIS: Open Command Prompt (cmd) and run:
iisreset📜 Step 4: Enable Execution of .VBS Scripts
Open IIS Manager, select your website, and click Handler Mappings.
Click Add Script Map:
Request path: *.vbs
Executable: C:\Windows\System32\cscript.exe //NOLOGO %s %s
Name: VBScript
Click OK, then Yes to enable the script.
Step 5: Install Microsoft Visual C++ Redistributable
Download and install the latest Microsoft Visual C++ Redistributable:
Run the installer (vc_redist.x64.exe for 64-bit systems).
If prompted, click Repair or Install.
🔑 Step 6: Set IIS Application Pool to Run as Administrator
Open IIS Manager (Win + R, type inetmgr, press Enter).
Click Application Pools.
Find your website’s Application Pool (e.g., DefaultAppPool).
Right-click → Advanced Settings.
Under Process Model, find Identity and click ... (ellipsis button).
Select Custom account, click Set, and enter an Administrator username and password.
Click OK, then Apply.
Restart IIS:
iisreset🔹 Additional Step: Connect IIS Site as Administrator
Open IIS Manager, select your site.
Click Basic Settings → Connect as → Set.
Use an Administrator account.
🔓 Step 7: Enable shell_exec in PHP
Open php.ini (C:\PHP\php.ini or C:\Program Files\PHP\php.ini).
Find:
disable_functions = ...3. Save the file and restart IIS:
iisreset✅ Step 8: Verify If shell_exec Works
Create a test PHP file (C:\inetpub\wwwroot\test.php):
Open a browser and visit:
If you see the username (e.g., Administrator), shell_exec() is working.
⚡ Step 9: Run Windows Services and Applications from PHP
Example 1: Start a Windows Service
<?php
shell_exec("start /B cmd.exe /c net start AppIDSvc > nul 2>&1");
?>Example 2: Run Calculator in the Background Using VBScript
Create calc.vbs in C:\inetpub\wwwroot\:
Dim objShell
Set objShell = CreateObject("WScript.Shell")
' Open Calculator
objShell.Run "calc.exe", 1, False
Set objShell = Nothing2. Run the VBScript from PHP:
<?php
shell_exec("start /B wscript.exe C:\\inetpub\\wwwroot\\calc.vbs");
?>Note: The calculator will not be visible but will run in the background (check Task Manager).
🎯 Conclusion
By following these steps, you can:
✅ Install IIS and PHP.
✅ Execute VBScript from a PHP page.
✅ Run Windows Services from PHP.
✅ Automate background tasks securely.
💡 What’s next? You can use this method to automate server-side tasks, such as starting services, launching applications, or even triggering scheduled jobs from a web interface! 🚀









Comments