I have an unusual situation when I need a SharePoint timer job to have access rights to local administrators and have SHAREPOINT\System SharePoint privileges.
I can obtain Windows privileges by simply setting up the timer service to use an account that is a member of local administrators. I understand that this is not a very good solution, as it gives the SharePoint timer more rights than anticipated. But this, at least, allows my SharePoint timer job to run stsadm .
Another problem with starting the timer service under the local administrator is that this user does not necessarily have the SHAREPOINT\System SharePoint privileges, which I also need for this SharePoint job. It turns out that SPSecurity.RunWithElevatedPrivileges will not work in this case. The reflector shows that RunWithElevatedPrivileges checks if the current process is owstimer (a service process that runs SharePoint jobs) and does not perform elevations in this case (the rational here, I think, is that the timer service should start under NT AUTHORITY\NetworkService Windows account that has SHAREPOINT\System SharePoint privileges, and therefore there is no need to SHAREPOINT\System privileges to set a timer).
The only possible solution seems to be to start the timer service under your regular Windows NetworkService account and run stsadm as a local administrator, store the administrator credentials somewhere and pass them to System.Diagnostics.Process.Run () crough StarInfo name, domain and password.
Everything seems to work now, but here's another problem I'm stuck with right now. Stsamd does not work with the following error popup (!) (Winternals filemon shows that stsadm is running as an administrator in this case):
The application failed to initialize properly (0x0c0000142).
Click OK to terminate the application.
Event Viewer does not register anything but a popup.
The local administrator is my account, and when I just run stsadm interactively under this account, everything is fine. It also works great when I configure the timer service to run in this account.
Any suggestions are welcome :)
timer sharepoint privileges event-viewer
Aleksey Kudryavtsev
source share