"RunWithElevatedPrivileges" in SharePoint Timer Jobs?
Asked Answered
T

2

6

Can we use SPSecurity.RunWithElevatedPrivileges in SharePoint timer jobs?

Under whose identity will the timer job run under elevated privilegs?

Any gotcha's and must know facts regarding this will also be appreciated.

Tusker answered 27/8, 2009 at 12:31 Comment(0)
W
13

RunWithElevatedPrivileges only works if the current thread is using impersonation, i.e. IIS. Used in other code (timer jobs, console applications, workflow, etc.) it will have no effect. Colin is correct that by default the timer service runs as the farm service account specified in the COnfiguration Wizard. You can verify this in Windows Services.

Wicket answered 27/8, 2009 at 12:42 Comment(4)
I can't speak for timer jobs or workflow, or technically console applications either but I'm developing a winforms application - which should have basically the same execution context as a console app (the user that starts the application) - and it can't do certain things without a RunWithElevatedPrivileges delegate, and then of course getting a new SPSite in the new elevated context. Do you have a source that shows how that's not necessary?Butyrate
To confirm, you're using SharePoint 3.0/2007? Try checking Environment.Username in and out of RWEP to see if there's really a change. (See solutionizing.net/2009/01/06/elegant-spsite-elevation/… and responses for related discussion.)Wicket
Nope - SharePoint 2013 - has the functionality of RunWithElevatedPrivileges() perhaps changed since? or is it slightly different some other way in more recent versions of SP?Butyrate
No idea, honestly - I'm several years out of SharePoint dev. I'd pop open ILSpy/dotPeek/equivalent and see what the implementation looks like now. Did you try checking Environment.Username?Wicket
R
5

They run under the account you used when running the SharePoint Products and Technologies Configuration Wizard for the first time to connect to SQl / run the Central Admin app pool under. i.e. the God account in SharePoint.

Rosannarosanne answered 27/8, 2009 at 12:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.