win32程序如何检测它作为应用程序或服务运行? [英] How can a win32 program detect it's running as an application or service?

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

问题描述

大家好。

我创建了一个应该作为服务和应用程序运行的应用程序。

当我点击并运行它时,它应该运行为一个应用程序。当从服务控制器调用时,它应该检测到它并且分支作为服务运行。如何在不传递参数的情况下检测到这一点?

mr.abzadeh

编辑:我的应用程序是一个win32应用程序。

编辑:问题标题因为不清楚而改变了。之前的标题是:如何检测进程是否作为服务安装

Hello guys.
I have created an application that should be run as a service and as an application.
When I click and run it, It should run as an application. when called from service controller, It should detect being it and branch to run as a service. How do I detect this, without passing arguments?
mr.abzadeh
My application is a win32 application.
Question title changed because it wasn't clear. The previous title was: How to detect if a process is being installed as a service

推荐答案

您需要实现 OnStart OnStop ServiceBase 继承而且只是实现 Main 方法。请查看链接以获取示例:

http:/ /einaregilsson.com/run-windows-service-as-a-console-program/ [ ^ ]



祝你好运!
You need to implement the OnStart and OnStop as you inherit from ServiceBase and also just implement a Main method. Have a look at the link for an example:
http://einaregilsson.com/run-windows-service-as-a-console-program/[^]

Good luck!


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

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