Custom SPJobDefinition and “Access denied” error

By | 2010-08-02

If you create a custom SPJobDefinition and use a Feature Event Receiver to deploy and install this (Timer) SPJobDefinition you receive an error when you call the Update() method:

“Access Denied”

How to code and install a SPJobDefinition

Paul Kotlyar found this on the subject:

“Upon detailed investigation of Microsoft.SharePoint.dll  I discovered that SharePoint guys added a new security feature to all objects inheriting from SPPersistedObject in the Microsoft.SharePoint.Administration namespace. This feature explicitly disallows modification of the above stated objects from content web applications, which is where our web part is running. The error message thrown is therefore very misleading. After some more tracing through the code I found a property in SharePoint API which controls this behavior: SPWebService.ContentService.RemoteAdministratorAccessDenied

Here is how to fix this Access Denied (through powershell):

if (get-pssnapin $snapin -ea "silentlycontinue") {
  write-host -f Green "PSsnapin $snapin is loaded"
elseif (get-pssnapin $snapin -registered -ea "silentlycontinue") {
  write-host -f Green "PSsnapin $snapin is registered"
  Add-PSSnapin $snapin
  write-host -f Green "PSsnapin $snapin is loaded"
else {
  write-host -f Red "PSSnapin $snapin not found"
# get content web service
$contentService = [Microsoft.SharePoint.Administration.SPWebService]::ContentService
# turn off remote administration security
$contentService.RemoteAdministratorAccessDenied = $false
# update the web service

2 thoughts on “Custom SPJobDefinition and “Access denied” error

  1. Pingback: Custom SPJobDefinition and “Access denied” error | SharePoint Blues

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.