Word 自动化仅适用于管理员,或者在创建 word.application 后会出现延迟
我们有一个用 Borland Delphi 编写的程序,它使用 Word 自动化来创建文档。 在安装(终端服务器)上,我们只能以本地管理员身份运行时才能使 Word 自动化工作。
当以另一个用户身份运行时,我们收到一条错误消息“Opdracht Mislukt -2146824090”(其荷兰语版本的 Office),我猜它被翻译为“操作失败”或“命令失败”。
用户对程序尝试放置新文档的文件夹具有读/写访问权限。
Office 2010
64 位 Windows Server 2008 R2 标准
该应用程序是 32 位 Windows 应用程序。
如果我在创建 word.application 后添加延迟(500ms),则一切正常。
WordApp := CreateOleObject('Word.Application');
sleep(500);
Doc := WordApp.documents.Open(sFile,EmptyParam,true);
有人知道为什么 CreateOleObject 命令现在在 Word 应用程序可以使用之前返回吗?
We have a program made in Borland Delphi that uses Word automation to create documents.
On an installation (terminal server) we are only able to get the Word automation to work when running as local administrator.
When runnnig as anoter user we get an error message "Opdracht mislukt -2146824090" (its dutch version of Office), wich I guess is translated to "Operation failed" or "Command failed".
The user has read/write access to the folder where the program try to put the new document.
Office 2010
64bits Windows server 2008 R2 standard
The applicaion is 32bit windows application.
If I add a delay (500ms) after the word.application is created, everything works as normall.
WordApp := CreateOleObject('Word.Application');
sleep(500);
Doc := WordApp.documents.Open(sFile,EmptyParam,true);
Anybody knows why the CreateOleObject command now returns before the Word application can be used?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您想跟踪这一点,您可以使用 ProcessMonitor 之类的工具来跟踪 Word 自动化执行,直到您可以使用该应用程序。
似乎正在进行某种权限检查 - 但仅仅半秒似乎时间太多了。
If you want to track out that, you could use a tool like ProcessMonitor to trace the Word automation executions till the point which you can use the app.
Seems some kind of rights check is taking place - but half a second seems too much time just for this.
您可以尝试打开文档几次,或者Word在出现错误后完全无法运行?
编辑:
请参阅我的回答它提供了更好的解决方案并解释了为什么会发生这种情况。
You could try to open the Document a few times, or is Word totally borked after it gave the error?
Edit:
Please see my answer here which provides a better solution and an explanation why this happens.
管理员帐户工作没有延迟,似乎没有任何权限可以执行任何操作,但 Word 恰好使用此帐户启动比普通域用户帐户快得多。
我可以接受延迟解决方法,但如果有人知道更好的方法,请告诉我。
The administrator account working wihtout delay, seems not to have anything with rights to do, but that Word happens to start much faster with this account than the normal domain user accounts.
I can live with the delay workaround, but if anyone knows a better way please let me know.
我意识到这个线程已经很老了,但是我通过确保在退出之前关闭文档(oleDocument.Close)解决了这个问题。通过这样做,不需要任何类型的延迟等。请参阅下面的 Delphi 代码片段。
例子:
I realize this thread is quite old, but I solved this issue by making sure to close the document before quitting (oleDocument.Close). By doing so there is no need for any type of delays, etc. See Delphi code snippet below.
Example: