如何判断当前进程是否是服务(C ++,Win32)? [英] How can I tell if the current process is a service or not (C++, Win32)?

查看:346
本文介绍了如何判断当前进程是否是服务(C ++,Win32)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定我的代码在其中运行的应用程序,是在服务中还是在应用程序中?为什么我想知道这一点-我正在编写一些注入到目标应用程序中的代码,而这些代码无法预先知道这些信息,因此必须自己解决。

How can I tell if the application my code is running in, is it in a service or an application? Why do I want to know this - I'm writing some code that is injected into the target application and that code has no way of knowing this information up front, so it has to work it out itself.

我不能依靠从服务控制管理器,启动,停止或命令行参数调用的任何代码。

I cannot rely on any code being called from the service control manager, start, stop, or command line parameters.

我目前正在查看 GetConsoleWindow(),希望它会返回 NULL 用于服务(无控制台)和任何应用程序的窗口句柄(具有控制台)。不确定这个假设的有效性。

I'm currently looking at GetConsoleWindow() which I hope will return NULL for a service (no console) and a window handle for any application (has a console). Not sure how valid this assumption is.

有更好的解决方案的想法吗?

Any ideas for a better solution?

推荐答案

从所有正在运行的服务( EnumServicesStatusEx )列表中搜索当前进程ID( GetCurrentProcessId )吗?

Search the current process id (GetCurrentProcessId) from the list of all running services (EnumServicesStatusEx)?

这篇关于如何判断当前进程是否是服务(C ++,Win32)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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