开发者

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.

The following command line argument needs to run after the service installation:

httpcfg set urlacl -u http://+:8开发者_如何学Python080/ -a "D:(A;;GX;;;S-1-5-21-490459244-4280451753-3120260354-1829)"

We need to pass this argument via installer using C#

That is via service controller after installer event. How would I do the same in C# using ServiceController?


I can think of two approaches:

  • Just run httpcfg.exe using System.Diagnostics.Process
  • Use PInvoke to access the underlying Win32 API HttpSetServiceConfiguration

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: httpsetserviceconfiguration (httpapi)

EDIT: Some notes about cleanup issues inspired by Rob's comment. 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.

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).

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜