If you have ever written some code that uses one of the Microsoft Office products and intended to run it on a server without user interaction using the builtin SYSTEM account you may very well have discovered that it just does not work and troubleshooting why is difficult.
According to this extremely helpful Microsoft article doing this is basically considered a no no. What would have been even better is if they said ‘hey, we don’t support this but here is how to make it work’, especially considering how ridiculously simple the solution is.
Credit to this post that finally gave me the answer which is to create the SYSTEM accounts Desktop folder.
32 bit Office: C:\Windows\System32\config\systemprofile\Desktop 64 bit Office: C:\Windows\SysWOW64\config\systemprofile\Desktop
Note: This has been tested on Office 2010 and Office 2013
A little more information for those who are interested and some basic troubleshooting for those who do run applications as SYSTEM in general.
Firstly if you are troubleshooting running applications as SYSTEM go and grab PSEXEC.EXE from here. Put the PSEXEC.EXE file somewhere on your machine that you are testing from and then launch either a command prompt or PowerShell and change directory to the path where you placed the EXE. Now we can run powershell.exe (or cmd.exe if you prefer) as SYSTEM by using the command,
psexec.exe /i /s powershell.exe
This will load up another window which is running under the SYSTEM credentials which we can confirm in PowerShell with the following command,
which should give us the response,
PS C:\> [Environment]::UserName SYSTEM
From here you can run, for example, Excel (change directory to the office folder and run using the command ‘.\EXCEL.EXE’ in PowerShell).
Using Office 2010 in this way will show you that Excel will launch and you can create a new document as normal but then when you click on the save button, or even ‘save as’, the application simply does nothing without that ‘Desktop’ folder created. Using Office 2013 in this same way shows that Microsoft have done some improvements as the application actually creates the missing folder and continues to work perfectly fine. Unfortunately the folder is still required to be created manually if you simply try to run your code as SYSTEM.
Using PSEXEC.EXE in this way is also required if you plan on generating any password hashes for PowerShell code that will run under the SYSTEM account. But more on that in another post.