Working off Peter's answer I came up with a more hacky solution that will do for the time being. The better solution will be Peter's above, but it requires a lot more expertise to setup.
In your post-receive batch file, call eventcreate to create an event on the windows event log, like so:
call eventcreate /S MACHINE_NAME /u Administrator /p password /t information /id 500 /d "A git post-receive hook has updated site code"
Where MACHINE_NAME is your server's machine name. It is important to include this as EVENTCREATE requires admin rights. It just so happens that it has the ability to remotely create events by supplying a username and password as a parameter. Including the machine name seems to put it in remote mode, which is required to supply the user/pass.
So this allows you to create an event with admin credentials from any source.
What you can then do is create a task in Task Scheduler which listens for this event. Open it up, create a task and make the trigger listen for an event with "EventCreate" as a source and the event id you supplied in the command above (500 in the example above, but you can use any number). Make sure to set the task to run as admin and let it run with elevated permissions.
Have the task run a batch with this included:
call %systemroot%\system32\inetsrv\appcmd.exe recycle apppool /apppool.name:APPPOOLNAME
replace only the capitalized APPPOOLNAME with the name of the pool you want to recycle.
The disadvantages this over creating a real service as Peter suggested are:
- You need to write the admin's password in plain-text in the batch file, so make sure nobody else gets their hands on this file.
- in theory there is potential for another app to create an event with the same ID and cause your app pool to recycle. (eventcreate seems to fail if I supply a custom source name, which would remove this issue)
- it has a lot more moving parts that complicate setup