Windows 2012 Serverで.exeファイルを実行するサービスを作成する方法は?

.netで.exeを作成し、サービスとして使用したいのですが、私のローカルマシンで常時実行されます。私はWindows Server 2012を使用しています。私のローカルコンピュータ上でサービスを設定する方法。

**Windowsのシェルスクリプトを使用して、コマンドでサービスを作成することができます。

sc create コマンドは、CreateService API 関数の操作を実行します。

どうすればいいのでしょう?

  1. "yourapplication.exe "を、お使いのコンピュータの適当な場所にコピーします。 Win2012サーバー(例:C:㊦Windows㊦System32)。

2.sc "を使用して、"srvany "を起動する新しいサービスを作成します(例:sc)。 create "Servicename" binPath= "C:'Windows'System32'srvany.exe" 表示名= "私のカスタムサービス" )

3.RegEditを使用する:サービスのための"Parameters "キーを作成します(例:以下のとおり)。 HKEY_LOCAL_MACHINE⇄CurrentControlSet⇄Services⇄Servicename⇄Paramaters)

4.RegEditを使用し、新しく作成したquot;Parameters "キー内に、以下のように作成します。 という文字列を入力し、「アプリケーション」のフルパスを入力します。 アプリケーションをサービスとして実行したい。 (見積もりなし が必要です)。

構文:ー

sc [] create [] [type= {own | share | kernel | filesys | rec | interact type= {own | share}}] [start= {boot | system | auto | demand | disabled}] [error= {normal | severe | critical | ignore}] [binpath= <BinaryPathName>] [group= ] [tag= {yes | no}] [depend= ] [obj= { | }] [displayname= ] [password= ] [パスワード

詳細...

質問へのコメント (3)

あなたもそうすればいいんです、それもうまくいくようです。 sc create "Servicename" binPath= "PathToyourApp.exe" DisplayName= "My Custom Service".

レジストリを開き、サービス'のレジストリキーにDescriptionという文字列を追加することで、そのサービスについてもう少し説明的な情報を追加することができます。これはservices.mscに表示されます。

解説 (0)

PowerShellを使用することができます。

New-Service -Name "TestService" -BinaryPathName "C:\WINDOWS\System32\svchost.exe -k netsvcs"

参照 - https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-service?view=powershell-3.0

解説 (1)