Reputation: 568
I'd like to start an MS Outlook for automation. So I type:
$Outlook = New-Object -ComObject Outlook.Application
However sometimes process starts but PowerShell throws an error:
New-Object : Creating an instance of the COM component with CLSID {0006F03A-0000-0000-C000-000000000046} from the IClassFactory failed due to the following error: 800100
01 Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)).
At line:1 char:12
+ $Outlook = New-Object -ComObject Outlook.Application
What does it mean? How to create com object consistently without an error? This line is always works:
Start-Process "C:\Program Files (x86)\Microsoft Office\root\Office16\OUTLOOK.EXE"
But then there is a problem with connecting to it:
#sleep 30
$Outlook = [Runtime.InteropServices.Marshal]::GetActiveObject("Outlook.Application")
I need to put sleep in the code to wait for MS Outlook to get up and running. Or else PowerShell throws error again.
Upvotes: 1
Views: 458
Reputation: 66286
RPC_E_CALL_REJECTED
most likely means one of the processes is running with elevated privileges (Run As Administrator). COM system refuses to marshal calls between processes running in different security contexts.
Make sure neither app or both are elevated.
Upvotes: 1
Reputation: 49435
It is not clear where and when the code is run. MS states the following:
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.
Read more about that in the Considerations for server-side Automation of Office article. If you deal only with Exchange accounts, you may consider using Exchange web services, see Start using web services in Exchange for more information.
Also Office application may give exceptions when you try to deal with OOM objects from a secondary thread. You may find the RPC_E_CALL_REJECTED 0x80010001 on Outlook new Mail creation from Thread post helpful.
Upvotes: 2