[英]How to install Windows Service from C# code (Winforms)
I have a Windows service developed in C# and I would like to install this service from a Winforms application in C# but not in a DOS command: 我有一个用C#开发的Windows服务,我想从C#中的Winforms应用程序安装此服务,但不能在DOS命令中安装:
installutil \i ..
Is it possible? 可能吗?
Installing a Windows Service requires admin privileges so the winforms app would need to be running with elevated privileges. 安装Windows服务需要管理员权限,因此winforms应用程序需要以提升的权限运行。 If this is ok, then you could use
Process.Start
to invoke the installutil.exe
. 如果可以,则可以使用
Process.Start
调用installutil.exe
。 Process.Start
also allows you to pass in a username and password so that is another option if the winforms app does not have elevated permissions. Process.Start
还允许您传递用户名和密码,因此,如果winforms应用程序没有提升的权限,则这是另一种选择。
Have a look at this article which has more information https://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.createnowindow%28v=vs.110%29.aspx 看看这篇文章,了解更多信息https://msdn.microsoft.com/zh-cn/library/system.diagnostics.processstartinfo.createnowindow%28v=vs.110%29.aspx
Installing a service requires you to excute two steps: 安装服务需要您执行两个步骤:
installutil.exe /i filename.exe
installutil.exe /i filename.exe
安装它们 services.msc
service starter. services.msc
服务启动器启动它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.