Restarting IIS programmatically

后端 未结 5 1141
闹比i
闹比i 2020-12-30 18:04

I need to restart IIS from a C#/.NET application. This seems like a trivial issue, but I haven\'t had success thus far, and none of the answers from this question have worke

5条回答
  •  悲&欢浪女
    2020-12-30 18:39

    Alternatively (and cleaner) you could just use the ServiceController class to subsequently stop and start the iis service.
    You'll probably still need elevated privileges though... Impersonation might solve this; "impersonate an account with higher privileges." for restarting the service.

    A good example of how to start/stop (and restart) a windows service can be found here: Start, Stop and Restart Windows Service (C#)

提交回复
热议问题