I am developing a custom Windows Service. Within this Windows Service, I need to loop through all web applications. So I need to use SPFarm.Local from Administration namespace. My intent is to use least privileges. So, can anyone please tell me, which user should the Windows Service run under? If the Windows Service runs as Local System, it was failing when it was trying to access SPFarm. Please help.

Also, can a farm admin account access SPFarm.Local or only the setup / install account can access this?

1 Answer 1


As we know that SP rely on farm admin account. If you go to your IIS and see the identity of your Central Admin web application then it should be your farm account you can use this account and in code you can use spsecurity.runwithelevatedprivileges so your code will always execute with application pool account.

  • I used an Impersonator class in my Windows Service running as Local System Account. This class was found in Code Project in the link below. codeproject.com/Articles/10090/… Then I used the following code construct, but still no luck. using(new Impersonator("userName","DomainName","password")) { SPFarm.Local //returns null }
    – Ven
    Commented Sep 2, 2016 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.