Step-by-Step Guide: Running VBScript from PHP on IIS Windows Server

Step-by-Step Guide: Running VBScript from PHP on IIS Windows Server

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

  1. Press Win + R, type appwiz.cpl, and press Enter.
  2. Click Turn Windows features on or off.
  3. Check Internet Information Services (IIS) and CGI (under Application Development Features).
  4. Click OK and wait for the installation to complete.


🐘 Step 2: Install PHP on IIS

  1. Download PHP from the official website: 🔗 PHP for Windows
  2. Extract the ZIP file to C:\PHP.
  3. Rename php.ini-production to php.ini and open it in Notepad.
  4. 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

  1. Add C:\PHP to the system environment Path:
  2. Right-click This PCPropertiesAdvanced system settings.
  3. Click Environment Variables.
  4. Under System variables, select Path and click Edit.
  5. Click New, type C:\PHP, and click OK.


⚙️ Step 3: Configure IIS for PHP

  1. Open IIS Manager (Win + R, type inetmgr, press Enter).
  2. Click Handler MappingsAdd Module Mapping.
  3. Click OK, then Yes to confirm.
  4. Restart IIS: Open Command Prompt (cmd) and run:

iisreset        

📜 Step 4: Enable Execution of .VBS Scripts

  1. Open IIS Manager, select your website, and click Handler Mappings.
  2. Click Add Script Map:
  3. Request path: *.vbs
  4. Executable: C:\Windows\System32\cscript.exe //NOLOGO %s %s
  5. Name: VBScript
  6. Click OK, then Yes to enable the script.


Step 5: Install Microsoft Visual C++ Redistributable

  1. Download and install the latest Microsoft Visual C++ Redistributable:
  2. Run the installer (vc_redist.x64.exe for 64-bit systems).
  3. If prompted, click Repair or Install.


🔑 Step 6: Set IIS Application Pool to Run as Administrator

  1. Open IIS Manager (Win + R, type inetmgr, press Enter).
  2. Click Application Pools.
  3. Find your website’s Application Pool (e.g., DefaultAppPool).
  4. Right-click → Advanced Settings.
  5. Under Process Model, find Identity and click ... (ellipsis button).
  6. Select Custom account, click Set, and enter an Administrator username and password.
  7. Click OK, then Apply.
  8. Restart IIS:

iisreset        

🔹 Additional Step: Connect IIS Site as Administrator

  1. Open IIS Manager, select your site.
  2. Click Basic SettingsConnect asSet.
  3. Use an Administrator account.


🔓 Step 7: Enable shell_exec in PHP

  1. Open php.ini (C:\PHP\php.ini or C:\Program Files\PHP\php.ini).
  2. Find:

disable_functions = ...        

3. Save the file and restart IIS:

iisreset        

✅ Step 8: Verify If shell_exec Works

  1. Create a test PHP file (C:\inetpub\wwwroot\test.php):
  2. Open a browser and visit:
  3. 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


  1. Create calc.vbs in C:\inetpub\wwwroot\:

Dim objShell
Set objShell = CreateObject("WScript.Shell")

' Open Calculator
objShell.Run "calc.exe", 1, False

Set objShell = Nothing        

2. 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! 🚀

This is a highly relevant breakdown—especially for developers managing legacy systems or enterprise environments where PHP runs on Windows servers. Configuring FastCGI with custom handler mappings isn’t straightforward, so a detailed guide like this is extremely valuable. We've seen similar challenges when automating Windows-based workflows with PHP, and security configurations around shell_exec() always require extra caution. Thanks for sharing such a well-structured approach!

Gajendra Rathod Insightful article with detailed explaination....keep it up🤝🏻

To view or add a comment, sign in

Others also viewed

Explore content categories