简体   繁体   English

使用模拟以编程方式启动Windows Service

[英]Starting windows service programatically using impersonation

I've been searching for an answer for my problem for hours but after trying lots of suggestion I'm still stuck. 数小时以来,我一直在寻找问题的答案,但是在尝试了很多建议后,我仍然陷入困境。

I have a C# Windows form based application I work on and I have to launch a windows service (also part of the solution) programatically (when the user clicks the appropriate button). 我有一个基于C#Windows窗体的应用程序,并且必须以编程方式(当用户单击适当的按钮时)启动Windows服务(也是解决方案的一部分)。 This part is already in place - I can launch the service but... I have some problems in Windows 7 and 2008 Server. 这部分已经到位-我可以启动该服务,但是... Windows 7和2008 Server中存在一些问题。

The problem is that I can't do it as my application is loaded by the machine administrator but as a filtered standard and not as full administrator ( more info here ). 问题是我无法执行此操作,因为我的应用程序是由计算机管理员加载的,但是作为过滤的标准而不是完全管理员的身份( 此处提供更多信息 )。 If we launch the application as Administrator it works fine, but I don't want to bother the user to do it every time. 如果我们以管理员身份启动该应用程序,则可以正常运行,但我不想每次都打扰用户。

I would like to know if it is possible to pop the Windows confirmation screen when the user enters the form where he can start the service - as a full administrator. 我想知道当用户输入可以启动该服务的表单时,是否可以弹出Windows确认屏幕-作为正式管理员。

Any ideas? 有任何想法吗?

Thanks 谢谢

IIRC - you can't elevate an existing processes privileges, you would need to spawn a new process to perform the operation which requires it. IIRC-您无法提升现有进程的特权,需要生成一个新进程来执行需要该进程的操作。

Found a previous question which further explains this. 找到了一个先前的问题 ,这进一步解释了这一点。

You can either launch another application thorugh ShellExecute (using the runas verb) so Windows would prompt the user or use the COM Elevation Moniker (both when the user clicks on the button). 您可以通过ShellExecute启动另一个应用程序(使用runas谓词),以便Windows提示用户或使用COM Elevation Moniker (均在用户单击按钮时)。

If you are targeting Windows Server 2008 R2/Windows 7 maybe you can use Service Trigger Events . 如果您的目标是Windows Server 2008 R2 / Windows 7,则可以使用服务触发事件

Best 最好

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM