如何获得Windows服务的命令行参数?命令行、如何获得、参数、Windows

2023-09-05 22:59:44 作者:被温柔宠坏

我在寻找一种方式来弄清楚任何窗口服务的命令行参数。

I'm looking for a way to figure out the command-line arguments of any windows service.

对于非服务过程中,命令行参数,可以在Windows任务管理器中,或以编程方式使用WMI,如本post.

For a non-service process, the command-line arguments can be found in the Windows Task Manager, or programmatically by using WMI as shown in this post.

不幸的是,这两种解决方案并没有为通过的 ServiceController.Start(字串[] args)方法。他们两人只显示在命令行中的可执行文件的路径,尽管一些论据来传递。

Unfortunately, these two solutions don't work for a windows service that is started by the ServiceController.Start(String[] args) method. Both of them show only the executable file path in the command-line, even though some arguments were passed in.

有人能解释的区别 两者之间的情景(服务V.S. 非服务流程)? 有没有     办法找出的参数     Windows服务? Could someone explain the difference between two scenarios (service v.s. non-service process)? Is there a way to figure out the arguments of the windows service?

更新:

我也尝试创建,用来记录任何命令行参数有到事件日志的简单服务。我开始使用SC.EXE启动<我的服务>< ARG1>并确认< ARG1> 被写入到事件日志。但是,没有一个解决方案已经为我工作。我看到的是依然只是路径的可执行文件。我的操作系统版本为Windows Server 2008 R2 SP1 64位的企业。

I also tried creating a simple service that just logs any command-line arguments it has to the event log. I started it using "sc.exe start <my service> <arg1>" and verified that <arg1> was written to the event log. However, none of the solutions has worked for me. What I saw was still only the path to the executable file. My OS version is Windows Server 2008 R2 SP1 x64 Enterprise.

推荐答案

有两种类型的论据服务

进程启动命令行中被传递的参数。你可以到那些很容易使用进程管理器,等等。 被传递到 ServiceMain函数的参数。这是Windows的API,服务应该实行。在.NET相当于是ServiceBase.OnStart.这是当你做一个SC启动[参数]有什么用。这有没有关系的命令行参数的过程。 arguments that were passed on the process start command line. You can get to those easily using Process Explorer, etc.. arguments that were passed to the ServiceMain function. This is the WIndows API that a service is supposed to implement. The .NET equivalent is ServiceBase.OnStart. This is what is used when you do a SC START [arguments]. This has nothing to do with "command line process arguments".

第二类型的参数是probaly仅由服务本身已知的,如果实现使得任何使用它,这些不是许多服务的情况。我不认为的Windows跟踪这个时候我们看低水平的窗户结构,如PEB:http://msdn.microsoft.com/en-us/library/ms684855(v=VS.85).aspx,它甚至无证零件http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/NT%20Objects/Process/PEB.html

The second type of parameters is probaly only known by the service itself, if the implementation makes any use of it which is not the case for many services. I don't think Windows keep track of this when we look at low level windows structures like the PEB: http://msdn.microsoft.com/en-us/library/ms684855(v=VS.85).aspx, even the undocumented parts of it http://undocumented.ntinternals.net/UserMode/Undocumented%20Functions/NT%20Objects/Process/PEB.html

 
精彩推荐
图片推荐