3

Can anyone provide a code example, or some information on how to use the ServiceControllerPermission class? The best I can find is a very short example on this site, which demonstrates use of the Assert() method, but there is little explanation, and the same goes for MSDN. I am studying for 70-536 so really looking for understanding more than anything.

Thanks

Ronnie
  • 1,059
  • 14
  • 27

1 Answers1

3

You can find example in the answer here.

Community
  • 1
  • 1
Alex Aza
  • 76,499
  • 26
  • 155
  • 134
  • That's the post I refer to in my question. Can you explain what the code using this class is doing? And is the Assert method the only real use for this class? Thanks – Ronnie May 15 '11 at 17:07
  • 1
    @Ronnie - Sure. This is imperative way to check if whoever runs your code has permission to control the service. So it will fail on Assert line if user doesn't have permission to control the service. You can do the same using attributes, which would be a declarative way to do it. – Alex Aza May 15 '11 at 17:17
  • 1
    @Ronnie - `ServiceControllerPermission` is inherited from `CodeAccessPermission` and has other methods. For example another popular method is `Demand()`. You need to read Code Access Security topic to understand it better. – Alex Aza May 15 '11 at 17:21
  • @Ronnie - I would appreciate if you mark my answer as an answer, if it helped. Up vote would also be great. Thanks. – Alex Aza May 15 '11 at 17:45