Hi All,
I am trying to start a custom timer job programmatically on click of a button in my custom web part(see the below code).The code works fine if run using a farm admin account, but get access denied issue otherwise.
How do I impersonate the code as a farm admin account? Is there a better workaround?
SPWeb web =SPContext.Current.Web;
SPSite curSite = newSPSite(web.Url);
SPWebApplication MainWebApp = SPWebApplication.Lookup(new Uri(web.Url));
var traceJob = (from jobDefinitionin MainWebApp.JobDefinitions
where jobDefinition.DisplayName == "Custom Timer Job"
select jobDefinition).SingleOrDefault();
if (traceJob != null)
traceJob.RunNow();
}
Regards,
Ameya