如何检测我的应用程序是作为服务运行还是在交互式会话中运行? [英] How do I detect that my application is running as service or in an interactive session?

查看:28
本文介绍了如何检测我的应用程序是作为服务运行还是在交互式会话中运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个能够作为服务或独立运行的应用程序,但我想检测该应用程序是作为服务还是在普通用户会话中执行的.

I'm writing an application that is able to run as a service or standalone but I want to detect if the application was executed as a service or in a normal user session.

推荐答案

我认为您可以查询流程令牌以获得 Interactive 组的成员资格.

I think you can query the process token for membership in the Interactive group.

来自 http://support.microsoft.com/kb/243330:

SID:S-1-5-4

SID: S-1-5-4

名称:互动

描述:一个包含所有交互登录用户的组.成员资格由操作系统控制.

Description: A group that includes all users that have logged on interactively. Membership is controlled by the operating system.

使用 TokenGroups 调用 GetTokenInformation 以获取与运行进程的帐户关联的组,然后遍历 sid 以查找交互式 sid.

Call GetTokenInformation with TokenGroups to get the groups associated with the account under which the process is running, then iterate over the sids looking for the Interactive sid.

我在 http://marc 找到了一段不错的代码.info/?l=openssl-dev&m=104401851331452&w=2

这篇关于如何检测我的应用程序是作为服务运行还是在交互式会话中运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆