PHP Classes

PHP Wscript.shell Exec: Run commands using Windows WScript object

Recommend this page to a friend!
  Info   View files Example   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum (2)   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 79%Total: 417 All time: 6,403 This week: 202Up
Version License PHP version Categories
wshell 2.0.2BSD License5.6PHP 5, Windows
Description 

Author

This class can run commands using Windows WScript object.

It encapsulates the WShell.Script Windows object to execute several types of operations:

- Run a command in synchronous or asynchronous mode
- Activate an already opened application to bring it the focus
- Send keys to the active application as if a use has types the letters in the keyboard
- Perform basic operations on registry keys

Innovation Award
PHP Programming Innovation award nominee
April 2017
Number 5
WScript is an environment for executing scripts that takes advantage of objects running on Windows that provide several types of services.

This class provides means to execute actions from PHP using WScript that can be useful, like for instance running Windows applications and simulating keyboard typing events.

Manuel Lemos
Picture of Christian Vigh
  Performance   Level  
Name: Christian Vigh <contact>
Classes: 32 packages by
Country: France France
Age: 57
All time rank: 13810 in France France
Week rank: 10 Up1 in France France Up
Innovation award
Innovation award
Nominee: 20x

Winner: 3x

Example

<?php
   
/****************************************************************************************************

        A demonstration of the WShell class capabilities.

        NOTE : this example should be better run as a command-line script (in CLI mode).

        It opens the NOTEPAD.EXE application, writes the string "Hello world" and saves the result
        to file "example.txt" (well, in order not to pollute your own drive, you will have to click
        yourself on the "Save" button).

     ****************************************************************************************************/

   
require_once ( 'WShell.phpclass' ) ;

   
$wshell = new WShell ( ) ;

   
// Launch NOTEPAD and let time for it for startup
   
$wshell -> Exec ( "NOTEPAD.EXE" ) ;
   
sleep ( 2 ) ;

   
// NOTEPAD is launched : write the string "Hello world" in the document
   
$wshell -> SendKeys ( "Hello world" ) ;

   
// We will save this new file :
    // Type Alt+F, then DOWN key 3 times, press ENTER and type "example.txt" as the output filename.
    // After that, you just need to click on the "Save" button to save the file.
    // Note that we have to specify some delay between keystrokes (100ms in this example), because
    // a few operations might need a delay to operate (for example, opening the "Save as" dialog box.
    // Without this delay, a few characters may be missed from the filename "example.txt"
   
$wshell -> SendKeys ( "%(F){DOWN 3}{ENTER}example.txt", 100 ) ;


  Files folder image Files  
File Role Description
Accessible without login Plain text file example.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file NOTICE Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation
Plain text file WShell.phpclass Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:417
This week:0
All time:6,403
This week:202Up
User Ratings User Comments (1)
 All time
Utility:100%StarStarStarStarStarStar
Consistency:91%StarStarStarStarStar
Documentation:100%StarStarStarStarStarStar
Examples:100%StarStarStarStarStarStar
Tests:-
Videos:-
Overall:79%StarStarStarStar
Rank:41
 
Nice.
5 years ago (Alekos Psimikakis)
77%StarStarStarStar