Running this bit of PowerShell from C#:
import-module ServerManager ; Get-WindowsFeature | Where-Object {$_.Installed -eq 'True'} | Select Name,DisplayName,FeatureType
It’s running as a service user, runs fine from command line as that user, but when running in the context of a service it fails miserably.
Does the service user need particular permissions or configuration to be able to do this when running as a service?
Error from the ServiceManager.log is this:
3440: 2014-12-05 09:10:34.607 [ExceptionHandler] Error (Id=0) An unexpected exception was found:
System.UnauthorizedAccessException: Retrieving the COM class factory for component with CLSID {BA126AD1-2166-11D1-B1D0-00805FC1270E} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
at Microsoft.Windows.ServerManager.DirectResult.GetLocalNetworkAdapterInfo()
at Microsoft.Windows.ServerManager.DirectResult.InitializeNetworkAdapterInfo()
at Microsoft.Windows.ServerManager.DirectResult.PopulateData()
at Microsoft.Windows.ServerManager.ServerManagerModel.InternalRefreshDirectResult(Object state)