|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-12-05 18:14 UTC] bvandermerwe at kbcat dot com
Description:
------------
com_get_active_object always returns "Operation Unavailable " even when it should work for sure. Let me demonstrate:
Start up Microsoft Word (for example) on the server machine where Apache and PHP are running. Then put the following text in a file called x.vbs:
Dim app
Set app = GetObject(,"Word.Application")
if app is nothing then
wscript.echo "Got nothing"
else
wscript.echo "Got it!"
end if
Execute it by typing: cscript x.vbs.
Note that it works fine. Yet the following line in a PHP script always returns "Operation Unavailable ":
$obj = com_get_active_object("Word.Application");
Using: $obj = new COM("Word.Application") works (meaning PHP COM is working).
I just upgraded Apache to 2.2.6 and PHP 5.2.5 (using the Windows installation executable binaries with pretty much default settings, except PHP is in c:\PHP525 and I checked the options for MS and MYSQL databases). Bugzilla and several PHP applications all work fine.
But it seems com_get_active_object *always* fails. I have Googled and I can not find any examples of it out there or any security or other settings related to it.
If it just calls GetObject, then how come calling GetObject from VBScript works but in PHP does not? I did discover that some GetObject calls are disabled under IIS for security reasons, but I am using Apache and there is no reference to any setting that needs to be turned on before this will work.
Reproduce code:
---------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Test</title>
</head>
<body>
<?php
echo("<p>Attempting to retrieve COM Object</p>");
$obj = com_get_active_object("Word.Application"); //Fails! if ($obj) {
echo("<p>Object Found</p>");
} else {
echo("<p>Object NOT Found</p>");
}
?>
</body>
</html>
Expected result:
----------------
No error. You should see:
Attempting to retrieve COM Object
Object Found
Actual result:
--------------
You see:
Attempting to retrieve COM Object
If PHP error tracing is enabled you also see:
Fatal error: Uncaught exception 'com_exception' with message 'Operation unavailable ' in C:\ApacheDocumentRoot\test_com.php:10 Stack trace: #0 C:\ApacheDocumentRoot\test_com.php(10): com_get_active_object('Word.Application') #1 {main} thrown in C:\ApacheDocumentRoot\test_com.php on line 10
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 23 08:00:02 2025 UTC |
I think the documentation[1] is (at least nowadays) pretty clear on that: | com_get_active_object() is similar to creating a new instance of | a COM object, except that it will only return an object to your | script if the object is already running. OLE applications use | something known as the "Running Object Table" to allow well-known | applications to be launched only once; this function exposes the | COM library function GetActiveObject() to get a handle on a | running instance. > Rather something like "Unable to instantiation COM Object due to > insufficient user permission" would help? That would be guesswork on behalf of PHP, though. You get exactly the same result from GetActiveObject() if you have permission to create a new Word.Application, but no instance of Word.Application is running. So, unless you are sure that a Word.Application is running, use something like the following: <?php try { $obj = com_get_active_object("Word.Application"); } catch (com_exception $ex) { // perhaps no Word.Application running? $obj = new COM("Word.Application"); } ?> [1] <https://www.php.net/com_get_active_object>