简体   繁体   English

从C#访问注册表中的Windows服务参数

[英]Access Windows Service Parameters in Registry from C#

Windows Services can have parameters in the registry like in Windows服务可以在注册表中具有参数,例如

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BITS\Parameters

I want to access the parameters of my own service written in C#. 我想访问用C#编写的我自己的服务的参数。 Is there an official way (eg via the ServiceBase class) to do that or do I have to hard-code the registry path, which I want to avoid? 是否有官方方法(例如通过ServiceBase类)来执行此操作,或者我必须对注册表路径进行硬编码,这是我想避免的方法?

Are you looking for the paramenters the server WAS started with, or what the registry is saying it should be started with? 您是在寻找服务器启动的参数,还是注册表说应该启动的参数?

If your looking for the parameters that was used to start your app you can use Environment.CommandLine or make surge your main function is declaired like 如果您在寻找用于启动应用程序的参数,则可以使用Environment.CommandLine或使浪涌您的主要功能像这样

[STAThread]
        static void Main(string[] args)
        {
            // Do something with args array, but il make sure its not null first.
        }

If your are looking for what args it should be started with i see no problem reading that registry setting. 如果您正在寻找应该使用什么args,那么我看不到读取该注册表设置的问题。

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

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