如何创建C ++ Windows服务 [英] How to create C++ windows service

查看:176
本文介绍了如何创建C ++ Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建c ++ windows服务



我尝试过:



我想在 C ++中编写服务
服务 C ++ 命令不使用.net.\
服务需要在指定的时间间隔后运行批处理文件。
告诉我如何这样的一些很好的链接?
我编写的c ++代码可以在
截图中看到
https: // lh3.googleusercontent.com/-3JVSaVqXedQ/V_pX6Kkh8fI/AAAAAAAADr8/2JQ3fjglipA/s0/screenshot %2525202016-10-09%252520016.jpg
按命令安装exe as 服务
Sc create MyService binPath = C:\\ \\ .exe DisplayName =我的新服务类型=拥有start = auto
当我尝试启动服务时出现错误。
错误 1053 服务未及时回复

p>

解决方案

您的代码 - 如屏幕截图所示(下次最好将其粘贴作为问题的一部分) - 与服务无关。 ..

Windows服务有明确的规则,必须根据它们编写......

在您的情况下,您没有服务入口点,因此您的代码无法安装为服务......



你有几个选择:

https://msdn.microsoft.com/en-us/library/ms686953(v = vs.85)的.aspx [ ^ ]

一个简单的C ++ Cl服务框架 [ ^ ]



您还可以使用Visual Studio中的ATL模板向导来创建服务的骨架......

how to create c++ windows service

What I have tried:

I want to write a service in C++ .
Service is needed in C++ in order to not use .net.\
The service needs to run a batch file after a specified time interval.
Tell me some good link on how to do such?
I wrote c++ code that can see in the screenshot.
https://lh3.googleusercontent.com/-3JVSaVqXedQ/V_pX6Kkh8fI/AAAAAAAADr8/2JQ3fjglipA/s0/screenshot%2525202016-10-09%252520016.jpg
install exe as service by command
Sc create MyService binPath=C:\s.exe DisplayName=″My New Service″ type=own start=auto
When I tried to start the service I got an error.
error 1053 service did not respond in timely fashion

解决方案

Your code - as it shown in the screenshot (and next time it will be better to copy paste it as part of the question) - has nothing to do with services...
Windows services have definite rules and must be written according them...
In your case you have no service entry point, so your code can not be installed as service...

You have several options to start with:
https://msdn.microsoft.com/en-us/library/ms686953(v=vs.85).aspx[^]
A Simple C++ Class Framework for Services[^]

You also can use the ATL template wizard in Visual Studio to create a skeleton of a service...


这篇关于如何创建C ++ Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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