VB.NET2005 で、Windowsサービスアプリケーション(WEBでなくEXEのもの)を開発しています。
このサービスは、同じ実行モジュールについてサービス名を分けて登録することを考えています。
(例)コマンドラインから
sc create SVC1 binPath= C:\MODULE.EXE
sc create SVC2 binPath= C:\MODULE.EXE
sc create SVC3 binPath= C:\MODULE.EXE
OnStart()内で、それぞれ自分の登録されたサービス名を取得してきたいのですが(上記の例ですとSVC1 SVC2 SVC3)、
ServiceBase.ServiceNameからは、どのサービスインスタンスにおいても開発時に登録した便宜的な固定のサービス名が入っておりました。
sc createで登録した実際のサービス名(=レジストリのHKLM\SYSTEM\CurrentControlSet\Services内にできるキー名)
を得る方法をご存知の方、是非ご教示ください。
こちらで全く同じ内容の議論がありましたが、結論としては「無理」ということのようです。
How to get the ServiceName(英語)
With SC I can register my service multiple times, ex: sc.exe create ServiceName1 binPath= D:\myservice.exe sc.exe create ServiceName2 binPath= D:\myservice.exe When I start the service "ServiceName1" I would like it to find it's parameters in HKLM\SYSTEM\CurrentControlSet\Services\ServiceName1\Parameters. This way I can register my service as many time I want to, and still each instance can have it's own configuration.
代替策として
が挙げられています。
sc create SVC1 binPath="C:\MODULE.EXE SVC1"
のようにサービス名をコマンドライン引数で渡すようにしてはだめですか?
http://www.atmarkit.co.jp/fdotnet/dotnettips/030cmdargs/cmdargs....