Introduction It can be difficult to configure MS Office and ABCpdf to convert Office documents as part of a Windows Service. This is for the following reasons. - Windows Services do not, by default, have the permissions required to launch MS Office tasks. - The Windows Service and any MS Office task need to run as the same user so that they can communicate correctly. - Microsoft Office is primarily designed to run as an interactive application. - Services run in Session 0 on later versions of Windows and the fact that Session 0 prohibits user interaction makes it difficult to troubleshoot configuration issues. Further, please be aware that there are risks running MS office server side, so please read “Considerations for server-side Automation of Office“ (http://support.microsoft.com/kb/257757). Please ensure that your use of MS Office is in compliance with the MS Office license agreement. Essentials Make sure you are using a recent version of MS Office. We test using Office 2007 and Office 2010. Make sure your MS Office installation is complete and activated. If you try and automate MS Office and the installation is not complete then it may result in an MS Office setup.exe being launched and blocking any conversions. Make sure your server is up-to-date. In particular ensure that you have a recent version of .NET installed. We normally install the .NET 4.0 framework when we test. Deployment Scenarios ASP.NET under IIS7 or later For IIS7 or later, e.g. IIS7 on Win2208 or Vista, you can just set the identity of the application pool to a user that has certain permissions (as explained below), and optionally load the user profile. There is no need to use a COM+ solution as required for pre IIS7 machines. Using a COM+ solution will not hurt but you must ensure that the COM+ identity and the application pool identity are the same. Further, please note that on Win 2008 or later the user profile is no longer loaded for COM+ applications. This means that even if you do use COM+, you still need to set the application identity in the app pool and load the user profile. Otherwise strange things might happen when the user is not logged on, depending on whether there is a service running as the same user or not. Services do have the user profile loaded. Follow these steps to validate office automation on your machine: 1. Unzip the following file: ImportDoc.zip This file contains a simple web site that converts uploaded files either via Microsoft Office or Open Office. This latter is an extra feature and you can ignore it. You don’t have to use this example, by all means use your own web site directly. 2. Install the Web Site in IIS Manager, use a dedicated application pool and make sure all the ABCpdf binaries are in the required locations. See ABCpdf installation below for further details. You may need to copy ABCpdf.dll into the bin folder. 3. Create a dedicated account for running office automation, for example call it OfficeAutomationUser. Assign a password that never expires to it. 4. Add this account to the IIS groups: IIS_IUSRS or IIS_WPG if it exists (basically the IIS group where you find Network Service, which is the default app pool id). 5. Log in using this account and open at least one office document of the type that you intend to convert. Make sure that when opening such a document there are no pop-ups. This means making sure that Office has been activated and all the initial questions Office asks have been answered, e.g. if you are running it with a trial key, etc. 6. Logging in using this account is also necessary to initialize the XPS print driver, otherwise you might get INVALID_PRINTER_NAME (1801) errors. 7. Give this account (or better the IIS group it belongs to) access permissions to the following folders, as indicated on the right. For 64-bit machines: C:\Windows\Temp – Modify C:\Windows\syswow64\config - Read C:\Windows\syswow64\config\systemprofile – Read C:\Windows\syswow64\config\systemprofile\AppData – Modify C:\Windows\syswow64\config\systemprofile\Desktop – Modify (Create it if it does not exist) For 32-bit machines: C:\Windows\Temp – Modify C:\Windows\system32\config - Read C:\Windows\ system32\config\systemprofile – Read C:\Windows\ system32\config\systemprofile\AppData – Modify C:\Windows\ system32\config\systemprofile\Desktop – Modify (Create it if it does not exist) You can assign folder permissions by browsing to such folders in Windows explorer and adding the user in the Security tab of the folder Properties dialog. 8. Give this account (or better the IIS group it belongs to) COM launch and activation permissions. In Component Services (dcomcnfg.exe) go to computers and right click on MyComputer. Launch the properties dialog and go to the COM Security tab. Click on “Edit Default” under “Access Permissions”. Add your user and give it full access. Repeat for “Launch and Activation Permissions”. 9. Set the identity of the application pool to OfficeAutomationUser. Also load the user profile by setting LoadUserProfile to true. You can do so in the application pool advanced settings: 10. You should be done. Check that it works. 11. You can also try to set LoadUserProfile to false, but if you do so then you should do the following: http://support.microsoft.com/kb/184291/EN-US/. This explains how to add the XPS print driver to the default user. 12. You may also want to use Network Service instead of a dedicated user. This might also work provided it has the required permissions (points 7 and 8) and provided you load the user profile (if you have not added the XPS print driver to the default user as explained above). ASP.NET before IIS7 For IIS versions before IIS7, e.g. IIS5.5 or IIS6 on Windows XP or 2003, we were not able to import Microsoft Office files directly from the ASP.NET process. We therefore propose a solution based on COM+ EnterpriseServices. We will therefore rely on a ServicedComponent for performing office automation (a COM+ wrapper basically). Follow these steps for validating office automation on your machine: 13. Unzip the following file: MSOfficeExampleSite.zip This file contains a MS Visual Studio solution with two projects: - PdfEnterpriseServices, the ABCpdf COM+ wrapper. - WebUtilities, a simple web site that uses PdfEnterpriseServices to convert a word document into pdf. The PDF will be displayed directly in the browser. 14. Launch WebUtilities.sln and build it. 15. Install the Web Site in IIS Manager, the web site folder is ExampleSite\WebUtilities. 16. Create a dedicated account for running office automation, for example call it OfficeAutomationUser. 17. Assign a password that never expires to this account and give this account Administrator rights. 18. Log in using this account and open at least one office document of the type that you intend to convert. In this example we will convert a .docx document. Make sure that when opening such a document there are no pop-ups. This means making sure that Office has been activated and all the initial questions Office asks have been answered, e.g. if you are running it with a trial key, etc. 19. Logging in using this account is also necessary to initialize the XPS print driver, otherwise you might get INVALID_PRINTER_NAME (1801) errors. 20. From a MS Visual Studio command prompt register PdfEnterpriseServices: RegSvcs PdfEnterpriseServices.dll On x64 Windows, RegSvcs.exe in %SystemRoot%\Microsoft.NET\Framework\v2.0.50727 is 32-bit and the one in %SystemRoot%\Microsoft.NET\Framework64\v2.0.50727 is 64-bit. The version of RegSvcs.exe determines whether the COM+ Application it registers will run in a 32-bit or 64-bit process. The 32-bit or 64-bit MS Visual Studio command prompt chooses the corresponding framework directory as one of the search paths. You should use the one that matches ABCpdf you plan to use. 21. Set the identity of PdfEnterpriseServices to OfficeAutomationUser. You can do so from Component Services, by running DCOMCNGF: right-click on the COM+ component, select properties and go to the Identity tab. You can also set the identity to the interactive user to start with but you will have to change it later on unless someone will always be logged in. 22. Browse to default.aspx of the example web site. If successful a PDF document containing the word “TEST” will be displayed by the browser. Windows Services Follow these steps to validate office automation in a windows service. We will rely on a COM+ application for performing office automation. On recent Windows versions such as Win 2008 and Vista the COM+ application is probably not necessary but we recommend you start with COM+ at first. 23. Unzip the following file: MSOfficeService.zip This file contains a MS Visual Studio 2005 solution with two projects: - PdfEnterpriseServices, the ABCpdf COM+ wrapper - TestService, a windows test service that uses PdfEnterpriseServices to convert a word document into pdf. 24. Create a folder that is publicly accessible, e.g. C:\services. 25. After building the solution (you may need to change the reference to ABCpdf in PdfEnterpriseServices), copy the content of both projects’ bin\Debug folders - or bin\Release if building in release- to C:\services. Also copy any other DLLs that your projects refer to and that are not in the GAC (for .NET) or in %SystemRoot%\system32 (for native DLLs). 26. Copy the Documents folder that you find in the zip file to C:\Services. 27. Create a dedicated account for running office automation, for example call it OfficeAutomationUser. 28. Assign a password that never expires to this account and give this account Administrator rights. 29. Log in using this account and open at least one office document of the type that you intend to convert. In this example we will convert a .docx document. Make sure that when opening such a document there are no pop-ups. This means making sure that Office has been activated and all the initial questions Office asks have been answered, e.g. if you are running it with a trial key, etc. 30. Logging in using this account is also necessary to initialize the XPS print driver, otherwise you might get INVALID_PRINTER_NAME (1801) errors. 31. From a MS Visual Studio command prompt, in C:\services, register PdfEnterprises: RegSvcs PdfEnterprises.dll On x64 Windows, RegSvcs.exe in %SystemRoot%\Microsoft.NET\Framework\v2.0.50727 is 32-bit and the one in %SystemRoot%\Microsoft.NET\Framework64\v2.0.50727 is 64-bit. The version of RegSvcs.exe determines whether the COM+ Application it registers will run in a 32-bit or 64-bit process. The 32-bit or 64-bit MS Visual Studio command prompt chooses the corresponding framework directory as one of the search paths. You should use the one that matches ABCpdf you plan to use. 32. Set the identity of PdfEnterprises to the OfficeAutomationUser account. You can do so from Component Services (run DCOMCNGF in Vista or go to the Control Panel / Administrative Tools in XP) . Right-click on the COM+ component, select properties and go to the Identity tab. 33. On Windows 2008 and other Windows versions it’s also necessary to set the log-on identity of the service to the same user. This is because COM+ applications no longer have the user profile loaded. 34. Install the service in the usual way, e.g. using installutil –i TestService.exe We tested the service with log-on as “Network Service” or “Local Service” and both scenarios worked. “Local Account” should also work. You should be done. Launch services from the Control Panel / Administrative Tools. The service should appear as ABCpdf test service with log-on set to Network Service and Startup Type manual. Start the service. After the service has started a file called input.pdf should appear in C:\Services\Documents. Any log messages go to C:\Services\abcpdf7.txt. Additional information on configuring Office This is not normally necessary unless the default settings have been changed. We want the Office Application to launch as the “Launching User” when it is activated via DCOM. 1. Launch DCOMCNFG. Note that there are both x86 and x64 versions of DCOMCNFG. By default on x64 versions of Windows the x64 version is launched. To launch the x86 version you will need to perform the following command line operation: C:\WINDOWS\SysWOW64> mmc comexp.msc /32 2. Go to Computers->MyComputer->DCOM Config. 3. Right-click the application that you want to automate. The application names are listed below: Application MS Access 97 MS Access 2000/2002/2003 MS Office Access 2007 MS Excel 97/2000/2002/2003 MS Office Excel 2007 MS Office Excel 2010 MS Word 97 MS Word 2000/2002/2003 MS Office Word 2007 MS Office Word 2010 DCOM Name Microsoft Access Database Microsoft Access Application Microsoft Office Access Application Microsoft Excel Application Microsoft Excel Application Microsoft Excel Application Microsoft Word Basic Microsoft Word Document Microsoft Office Word 97 - 2003 Document Microsoft Word 97 - 2003 Document On some systems Microsoft Word is not displayed and you will have to use {00020906-00000000-C000-000000000046} instead. Click Properties to open the property dialog box for this application. 4. Click the Identity tab. Verify that The Launching User is selected. Lowering Admin Rights We ask that the COM+ account has Administrator rights because it requires permissions that the standard Users group does not normally have. However you can remove your office automation user from the Administrators group as long as you give it the following permissions: It must have access to the following system folders, as indicated on the right. For 64-bit machines: C:\Windows\Temp – Modify C:\Windows\syswow64\config - Read C:\Windows\syswow64\config\systemprofile – Read C:\Windows\syswow64\config\systemprofile\AppData – Modify C:\Windows\syswow64\config\systemprofile\Desktop – Modify (Create it if it does not exist) For 32-bit machines: C:\Windows\Temp – Modify C:\Windows\system32\config - Read C:\Windows\ system32\config\systemprofile – Read C:\Windows\ system32\config\systemprofile\AppData – Modify C:\Windows\ system32\config\systemprofile\Desktop – Modify (Create it if it does not exist) You can assign folder permissions by browsing to such folders in Windows explorer and adding the user in the Security tab of the folder Properties dialog. It must have COM launch and activation permissions. In Component Services (dcomcnfg.exe) go to computers and right click on MyComputer. Launch the properties dialog and go to the COM Security tab. Click on “Edit Default” under “Access Permissions”. Add your user and give it full access. Repeat for “Launch and Activation Permissions”. Important Notes for Windows 2008 / Windows 7 1. Make sure there is a folder called “Desktop” in C:\Windows\SysWOW64\config\systemprofile for Windows 2008 Server x64 or C:\Windows\config\systemprofile for Windows 2008 Server x86. Create the folder if it does not exist. 2. For further information: http://social.msdn.microsoft.com/Forums/en/innovateonoffice/thread/b81a3c4e-62db488b-af06-44421818ef91. 3. Some people have reported that it was necessary to install the MS Office SP2 on Windows Server 2008 R2 or else MS Word would crash. To install the SP2: http://support.microsoft.com/kb/953195. 4. Some people have reported it is necessary to set the Microsoft XPS Document Writer as the default printer. Registry Entries If you are still having problems you may try the following to troubleshoot: 1. Add a DWORD registry entry called PrintHookLog to HKLM\Software\WebSupergoo\ABCpdfNET\7 and set it to one. 2. On 64-bit machine also add it to HKLM\Software\Wow6432Node\WebSupergoo\ABCpdfNET\7. 3. Monitor your windows temp directory, normally C:\Windows\Temp for files called spy_xxxx.log where xxxx is a PID. See if you can work out any possible problem by looking at the content of these files, this is normally a popup that is blocking the Office app, or send them over to us for further analysis. 4. Remember to delete these registry entries or to set them to zero to avoid clogging your temp area with the spy log files. ABCpdf installation If installing ABCpdf manually make sure that: ABCpdf.dll is in the GAC (gacutil –i ABCpdf.dll) or in the same directory as the service executable. ABCpdfCE.dll is in %SystemRoot%\system32. PrintHook32.dll is in %SystemRoot%\system32 for 32-bit machines. For 64-bit machines PrintHook32.dll and PrintHook64.dll should both be in %SystemRoot%\system32 and PrintHook32.dll should also be in %SystemRoot%\SysWOW64.