以非管理员身份启动/停止远程服务器上的服务(需要gui界面) [英] Start/stop Service on remote server as non-admin (need gui interface)

查看:84
本文介绍了以非管理员身份启动/停止远程服务器上的服务(需要gui界面)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个非常简单的GUI.一个开始按钮,用于停止远程PC上的服务. (这意味着我需要将域帐户硬编码为权限代码),然后只需要一个开始"按钮即可将其备份.我正在与你们联系,因为我不知道从哪里开始,并且希望至少您可以提供一些简单的方法 为我编码.预先感谢.

I need to create a gui that should be pretty simple. One start button to stop a service on a remote pc. (meaning I'll need to hard code the domain account into the code for rights), then I just need a start button to start it back up. I am reaching out to you guys, because I have no clue on where to start and was hoping at least you could provide some simple code for me. Thanks in advance.

推荐答案

没有管理员权限就无法启动/停止服务.具体来说,您需要启动/停止服务的权利,这是管理员权限的一部分,但也可以授予其他用户.如果运行该应用程序的用户没有权限,那么您就是 将不得不模拟一个这样做的用户(通过代码或通过运行方式).我也不同意将帐户硬编码到您的代码中.大多数IT部门都有密码政策,要求定期更改密码.不会的 由于密码更改而不得不重新编译代码是很有意义的.此外,这是一个很大的安全漏洞.如果生气的员工可以访问该应用程序怎么办?他们将能够远程停止服务器上的服务,审核将 所有都指向您硬编码的帐户.这对安全性非常不利.

You cannot start/stop services without admin rights.  Specifically you need the right to start/stop services which is part of admin rights but can be given to other users as well.  If the user running the app doesn't have the rights then you're going to have to impersonate a user (in code or via Run As) that does.  I also disagree with hard coding an account into your code.  Most IT departments have password policies that require the password to be changed periodically.  It wouldn't make sense to have to recompile your code because of a password change.  Additionally it is a big security hole.  What if an angry employee gets access to the app?  They will be able to remotely stop services on a server and the audits will all point to the account you hard coded.  This is very bad for security.

Windows无需编写任何代码就可以远程管理服务.您是否需要自定义此功能的特定原因?我建议您只使用Powershell(假设远程计算机可以处理它).如果 您确实需要编写自己的应用,那么我不建议您对任何用户ID进行硬编码.正常创建该应用,并让运行中的用户运行身份"使用其重新启动服务所需的帐户.这是最安全的方法,可确保 审核日志是正确的.如果您需要在批处理过程中运行开始/停止,请考虑使用计划任务"来代替,它可以将进程配置为以特定用户身份运行.

Windows can already remotely manage services without you writing any code.  Is there a specific reason you need this functionality customized?  I would recommend that you just use Powershell (assuming the remote machine can handle it).  If you do need to write your own app then I don't recommend that you hard code any user ID.  Create the app as normal and have the running user Run As to the account they need to restart the service.  This is the most secure approach and ensures the audit logs are correct.  If you need to run start/stop as part of a batch process then consider using Scheduled Tasks instead which allows you to configure a process to run as a specific user.

要启动/停止.NET中的服务,您将使用 ServiceController.GetServices 来获取远程计算机上的服务.然后,您可以使用开始/停止"方法进行控制.

To start/stop a service in .NET you'll use ServiceController.GetServices to get the service on the remote machine.  Then you can use the Start/Stop methods to control it. 

迈克尔·泰勒
http://msmvps.com/blogs/p3net

Michael Taylor
http://msmvps.com/blogs/p3net


这篇关于以非管理员身份启动/停止远程服务器上的服务(需要gui界面)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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