简体   繁体   English

使用 c# 安装服务后传递命令行参数

[英]Passing commandline argument after service installation using c#

We had a problem with WCF hosting on service in Windows 2003. We found a command line tool (httpcfg) which helped us to resolve the issue temporarily. WCF 在 Windows 2003 中托管服务时遇到问题。我们找到了一个命令行工具 (httpcfg),它可以帮助我们暂时解决问题。

The following command line argument needs to run after the service installation:以下命令行参数需要在服务安装后运行:

httpcfg set urlacl -u http://+:8080/ -a "D:(A;;GX;;;S-1-5-21-490459244-4280451753-3120260354-1829)"

We need to pass this argument via installer using C#我们需要使用 C# 通过安装程序传递这个参数

That is via service controller after installer event.那是在安装程序事件之后通过服务 controller。 How would I do the same in C# using ServiceController ?我将如何使用ServiceController在 C# 中做同样的事情?

I can think of two approaches:我可以想到两种方法:

The second approach is a little messy but not that hard.第二种方法有点混乱,但并不难。 The PInvoke.net page describes the call and even gives a working example: PInvoke.net 页面描述了调用,甚至给出了一个工作示例:

EDIT: Some notes about cleanup issues inspired by Rob's comment.编辑:关于受 Rob 评论启发的清理问题的一些注释。 I put them here in this existing answer, because they don't make a good one on their own.我把它们放在这个现有的答案中,因为他们自己做的不好。

Please note, that whatever approach you take (httpcfg.exe or direct use of the HTTP-API), make really sure that you unregister the URLs in your uninstall process.请注意,无论您采用何种方法(httpcfg.exe 或直接使用 HTTP-API),请务必确保在卸载过程中取消注册 URL。

The reason is, that HTTP.SYS (which actually is a kernel component) has only so much (nonpaged) memory available for managing URL reservations. The reason is, that HTTP.SYS (which actually is a kernel component) has only so much (nonpaged) memory available for managing URL reservations. If you exceed this, by having to many (possibly stale / left-over) registrations, you get errors and cannot register any new URLs (see http://support.microsoft.com/kb/824033 ).如果超出此范围,则必须进行许多(可能是陈旧/遗留)注册,您会收到错误并且无法注册任何新 URL(请参阅http://support.microsoft.com/kb/824033 )。

While this is "solvable" by manually using httpcfg.exe to cleanup registrations you think(,) are orphaned (or allowing more memory - careful.) it is a royal pain and totally unnecessary, if uninstallers work as suggested.虽然通过手动使用 httpcfg.exe 来清理您认为是孤立的注册(或允许更多 memory - 小心。)这是“可以解决的”,但如果卸载程序按照建议工作,这是一个皇家痛苦并且完全没有必要。

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

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