Custom SPJobDefinition and "Access denied" error

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 Responses to “Custom SPJobDefinition and "Access denied" error”

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

    […] found Stef Van Hooijdonk’s post when trying to install a custom timer job and having the “Access denied” -issue. I […]

  2. Juha Says:

    Thanks for your post, you helped me:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: