ShellExecuteEx()创建在不同帐户下运行的服务的两个实例 [英] ShellExecuteEx() creating two instances of a service which run under different accounts

查看:50
本文介绍了ShellExecuteEx()创建在不同帐户下运行的服务的两个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

调用服务时遇到问题.我正在使用ShellExecuteEx()创建服务. ShellExecuteEx()正在创建服务的两个实例.一个实例正在SYSTEM下运行.第二个实例正在登录帐户下运行.我可以在任务管理器中看到它们.
预期的行为是:ShellExecuteEx()应该只创建一个服务实例.

谁能为我提供一些解决方案?任何帮助将不胜感激.

谢谢,Sunil

I am getting a problem while invoking a service. I am using ShellExecuteEx() to create a service. ShellExecuteEx() is creating two instances of service. One instance is running under SYSTEM. 2nd instance is running under login account. I can see them in task manager.
Expected behaviour is : ShellExecuteEx() should create only one instance of service.

Can anyone provide me some solution for this? Any help would be appreciated.

Thanks, Sunil

推荐答案

不,您期望的是不是期望的行为.
您观察到的是预期的行为.

无论您使用ShellExecuteEx开始什么,都如同从shell启动应用程序一样.在始终处创建新的应用程序实例.如果只需要一个实例,则设计应用程序是一种特殊的方法.有很多方法.这个想法是:一个应用程序应该启动并检测到第一个实例已经启动.如果第一个实例正在运行,则第二个实例向第一个实例发送一些消息以将其激活,接受一些命令行参数等.自然,应该使用一个或多个IPC对象,例如SharedMemory,Mutex,Socket,命名管道等.

问题确实不同.如果使用ShellExecuteEx运行某些内容,则它永远不会是服务,或者可能不是服务未在服务模式下运行.要提供真实的服务,您应该开发一个窗口服务.有使用它的特殊Visual Studio模板.如果您开发Window Service并希望将其作为此类Service运行,则只能通过Service Manager或使用Service Management API遍历代码来启动它.

尝试从此处开始: http://msdn.microsoft.com/zh-CN -us/library/40xe80wx(v = vs.80).aspx [
No, what you expect is not the expected behavior.
What you observe is quite the expected behavior.

Whatever you start using ShellExecuteEx acts as if you started an application from shell. At always creates new instances of application. If you need only one instance, you should design your application is a special way. There are many methods. The idea is: an application should start and detects is first instance is already started. If first instance is running, the second instance sends some message to the first instance to activate it, accept some command line parameters and the like. Naturally, one or more IPC objects should be used, like SharedMemory, Mutex, Socket, Named pipe, etc.

The problem is really different. If you run something using ShellExecuteEx it is never a service or maybe a service not running in the service mode. To make a real service you should develop a Window Service. There are special Visual Studio templates using it. If you develop a Window Service and want to run it as such Service, it can be started only through the Service Manager or throug the code using Service Management API.

Try to start from here: http://msdn.microsoft.com/en-us/library/40xe80wx(v=vs.80).aspx[^].

—SA


谢谢.您给了我正确的指导.
Thanks. You gave me right direction to work on.


这篇关于ShellExecuteEx()创建在不同帐户下运行的服务的两个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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