C#Windows服务 - 上安装的默认参数 [英] C# Windows Service - Default Arguments on Install

查看:375
本文介绍了C#Windows服务 - 上安装的默认参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序(这是一个窗口服务)需要一个命令行参数,它是一个配置文件的位置。

My application (which is a windows service) needs one command line argument which is the location of a config file.

我希望该服务能够自动启动。填写启动参数值仅适用于手动启动它,这值不结转该服务停止后,

I want the service to be able to start automatically. Filling in the 'Startup parameters' value only applies to manually starting it and that value does not carry over after the service is stopped.

我试图手工编辑路径到可执行在注册表但达网络服务不regocnise它,就好像它是一个命令行(走的路径作为参数的第二部分)

I tried manually editing the "Path to executable" in the registry but the .net service doesn't regocnise it as if it were a command line (taking the 2nd section of the path as the arguments)

有没有办法设置在默认的参数设置(使用InstallUtil或任何其他方式)?

Is there a way to setup a default argument on install (either using InstallUtil or any other way)?

感谢

推荐答案

您可以通过将其追加到中发现的的ImagePath参数值添加命令行参数为您服务:

You can add command line parameters to your service by appending them to the ImagePath parameter value found in :

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\<your service>\

使用 Environment.GetCommandLineArgs方法可以阅读他们在您的服务时,它就会被启动。

Using the Environment.GetCommandLineArgs Method you can read them in your service when it gets started.

这篇关于C#Windows服务 - 上安装的默认参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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