DCOM

An extension to COM is Distributed COM (DCOM), Microsoft's competitor to the Common Object Request Broker Architecture (CORBA). DCOM allows you, once the correct permissions have been worked out, to create and use COM objects on other machines, as if they were local. As DCOM is just COM done remotely, it is very easy to make use of, but first you need to make sure you have DCOM support enabled in your php.ini file.

If you used the default php.ini, you probably have DCOM support disabled. Open up your php.ini file, search for "com.allow_dcom", and make sure the line is not commented out with a semi-colon, and has its value set to true. Once this is done, restart your web server so that it reloads the modified php.ini file, and you are all set to use COM.

To create a remote COM object, all you need to do is change your call to the COM constructor. Right now we just pass in the name of the object to create, but to create a remote object, you need to pass in the name of the server as the second parameter. Otherwise, everything is the same - once the COM object is created, it does not matter whether it is local or remote, which is one of the advantages of the COM system.

So, to create a WScript.Shell component on server "moggieboo", you would use code like this:

$shell = new COM("WScript.Shell", "moggieboo");

Note that DCOM has very strict security procedures behind it, because it is obviously quite dangerous to allow remote users to execute arbitrary code on a local machine. You will need to refer to your system administrator / favourite Windows technical site for information on DCOM permissions, however a good place to start is in the "dcomcnfg" program, as that allows you to enable DCOM permissions for various users.

 

Want to learn PHP 7?

Hacking with PHP has been fully updated for PHP 7, and is now available as a downloadable PDF. Get over 1200 pages of hands-on PHP learning today!

If this was helpful, please take a moment to tell others about Hacking with PHP by tweeting about it!

Next chapter: Microsoft .NET >>

Previous chapter: The possibilities of COM

Jump to:

 

Home: Table of Contents

Copyright ©2015 Paul Hudson. Follow me: @twostraws.