Detect if code is running as a service

前端 未结 9 1409
谎友^
谎友^ 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:53

    You should probably check that you are running in session zero (at least if you are targeting Vista). You can use WTSRegisterSessionNotification, like in this sample:

      [DllImport("kernel32.dll")]
      private static extern int WTSGetActiveConsoleSessionId();
    

提交回复
热议问题