简体   繁体   English

Xampp PHP创建没有任何信息的COM对象致命错误

[英]Xampp PHP Create COM Object Fatal Error without any info

I'm running into a problem with my php application. 我的php应用程序遇到了问题。 I'm building up a service application which should be connected to our ERP ( selectline ). 我正在构建一个服务应用程序,该应用程序应连接到我们的ERP(selectline)。

But I can't get to create a COM Object. 但是我无法创建一个COM对象。 This code: 这段代码:

<?PHP
error_reporting(E_ALL);
session_start();
date_default_timezone_set('Europe/Zurich');
echo time();
$obj = new COM("fd6c8b29-e936-4a61-8da6-b0c12ad3ba00") or die("Unable to instantiate Word");
echo "Loaded Word, version {$word->Version}\n";
?>

Returns me: 返回我:

Fatal error: in C:\\xampp\\htdocs\\com.php on line 21 致命错误:在第21行的C:\\ xampp \\ htdocs \\ com.php中

I got two environments: 我有两种环境:

Server 2008 R2 + Xampp v3.1.0 |PHP 5.4.7 Server 2008 R2 + Xampp v3.1.0 | PHP 5.4.7

Server 2012 R2 + Xampp v3.1.0 | Server 2012 R2 + Xampp v3.1.0 | PHP 5.4.7 PHP 5.4.7

I had to add the php_com_dotnet.dll in the php.ini because I had COM class not found before. 我必须在php.ini中添加php_com_dotnet.dll,因为以前没有找到COM类。

Due to the fact I'm complete new to COM I have no idea where to search for the failure. 由于我是COM的新手,所以我不知道在哪里搜索失败。

May you guys can help me out. 希望你们能帮助我。

Thanks in advance 提前致谢

I changed my code a bit: 我对代码做了一些更改:

try {
$obj = new COM("word.application") or die("Unable to instantiate Word");
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}

Now I get: 现在我得到:

Failed to create COM object `word.application': Invalid Syntax 无法创建COM对象`word.application':无效的语法

I don't get what is wrong. 我不明白有什么问题。 According to this article http://www.php.net/manual/en/class.com.php there is no need for additional parameters, right? 根据本文http://www.php.net/manual/zh/class.com.php ,不需要其他参数,对吗?

Make sure to set the correct COM permission to "This User". 确保将正确的COM权限设置为“此用户”。

  • Run: "dcomcnfg" 运行:“ dcomcnfg”
  • Expand: Component Services > Computers > My Computer > DCOM Config. 展开:组件服务>计算机>我的电脑> DCOM配置。
  • Select: "Microsoft Word 97-2003 Document" 选择:“ Microsoft Word 97-2003文档”
  • Right-Click on it and open the properties 右键单击它并打开属性
  • Click the Identity tab. 单击身份选项卡。
  • Select "This User" and type the username and password for the (Administrator) user. 选择“此用户”,然后输入(管理员)用户的用户名和密码。
  • Apply these new settings and test your COM application. 应用这些新设置并测试您的COM应用程序。 It should work fine now. 现在应该可以正常工作了。

I hope I save lots and lots of hours of headaches to some of you :) 我希望我为你们中的许多人省去了很多麻烦的时间:)

PHP Setup PHP设置

  • Enable the COM extension in php.ini 在php.ini中启用COM扩展

extension=php_com_dotnet.dll 扩展名= php_com_dotnet.dll

  • Restart Apache 重新启动Apache

Usage 用法

<?php

try {
    $word = new COM("word.application");
} catch (Exception $ex) {
    echo $ex->getMessage();
    exit;
}

$word->Screenupdating = true;
$word->WindowState = 2;
$word->Visible = 0;
$word->CheckLanguage = false;
$word->Options->Overtype = false;
$word->Options->SaveInterval = 0;
$word->Assistant->Visible = false;
$word->DisplayAlerts = false;

// Do fancy stuff...

// Close word
$word->Quit();
$word = null;

Have you tried giving Apache service admin rights in services.msc ? 您是否尝试过在services.msc中Apache服务管理员权限?
It will require that you have a password on the account you're using to run it, though. 不过,这将要求您在用于运行该帐户的帐户上输入密码。 Hope that helps.. 希望有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决致命错误:未捕获到com_exception:无法创建COM对象“ TSCActiveX.TSCLIB”:未在C:\\ xampp \\ htdocs中注册的类 - how to solve Fatal error: Uncaught com_exception: Failed to create COM object `TSCActiveX.TSCLIB': Class not registered in C:\xampp\htdocs 致命错误php XAMPP - Fatal error php XAMPP 创建Com对象时发生PHP致命错误 - PHP fatal error on creating Com Object PHP MySQL Xampp致命错误 - PHP mySQL xampp fatal error 致命错误:在第43行的C:\\ xampp \\ htdocs \\ Joomla15 \\ components \\ com_onlinetraining \\ onlinetraining.php中的非对象上调用成员函数load() - Fatal error: Call to a member function load() on a non-object in C:\xampp\htdocs\Joomla15\components\com_onlinetraining\onlinetraining.php on line 43 XAMPP和PHP 5.4.4的Normalizer致命错误 - Normalizer fatal error with XAMPP and PHP 5.4.4 如何使用xampp修复php中的致命错误 - how to fix fatal error in php using xampp PHP致命错误:如果不在第9行的C:/xampp/htdocs/oops/1.php中的对象上下文中,则使用$ this? - PHP Fatal error: Using $this when not in object context in C:/xampp/htdocs/oops/1.php on line 9? PHP 致命错误:未捕获的错误:在 Windows 中的 XAMPP v3.3.0 中调用未定义的函数 socket_create() - PHP Fatal error: Uncaught Error: Call to undefined function socket_create() in XAMPP v3.3.0 in windows xampp和PHP致命错误:未捕获的错误:未找到类“ DOMDocument” - xampp and PHP Fatal error: Uncaught Error: Class 'DOMDocument' not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM