Detect if code is running as a service

前端 未结 9 1373
谎友^
谎友^ 2020-12-10 16:30

Is there a way for an .NET library to detect whether or not it is being run as a service?

My library can be run either way. But when its run as a service, developer

9条回答
  •  無奈伤痛
    2020-12-10 16:44

    One way is to have a look at the user context of your application. If you see that it is running as the "SYSTEM" user, then you are running as a service (or at least with service-level permissions).

提交回复
热议问题