SharePoint Internals – Hristo Pavlov’s Blog

27 February, 2009

Running execadmsvcjobs through code

Filed under: SharePoint — Tags: , , , , , , , — hristopavlov @ 4:50 am

Well there are many ways you could achieve this and this is just one of  them. It simply creates a new instance of the SPExecuteAdministrationServiceJobs class and calls its Run method. This will start and wait for all currently registered and/or running timer jobs to finish. The code is below:

string stsadmPath = SPUtility.GetGenericSetupPath(“BIN”);

Assembly stsadmAsm = Assembly.LoadFile(Path.GetFullPath(stsadmPath + “\\STSADM.EXE”));

Type admSvcJobType = stsadmAsm.GetType(“Microsoft.SharePoint.StsAdmin.SPExecuteAdministrationServiceJobs”);

ConstructorInfo ci = admSvcJobType.GetConstructor(new Type[] { typeof(SPGlobalAdmin) });

using (SPGlobalAdmin admin = new SPGlobalAdmin())


    object svcjobs = ci.Invoke(new object[] { admin });

    MethodInfo runMi = admSvcJobType.GetMethod(“Run”, BindingFlags.Instance | BindingFlags.Public);


    runMi.Invoke(svcjobs, new object[] { new StringDictionary() });


One place this could be handy is when you provision a web application on multiple front ends using SPWebApplication.ProvisionGlobaly(). This method creates a timer job and returns immediately. However if you need the web application to be created before you continue you need to wait for the timer job(s) to finish. One way to do this programmatically is using the code above.



  1. Just passing by.Btw, you website have great content!

    Making Money $150 An Hour

    Comment by Mike — 1 March, 2009 @ 9:45 am

  2. […] Running execadmsvcjobs through code […]

    Pingback by Links (3/1/2009) « Steve Pietrek - Everything SharePoint — 1 March, 2009 @ 11:05 pm

RSS feed for comments on this post. TrackBack URI

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

Create a free website or blog at

%d bloggers like this: