> For the complete documentation index, see [llms.txt](https://docs.nexthink.com/platform/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.nexthink.com/platform/ja/user-guide/remote-actions/remote-actions-in-finder-classic/example-of-self-healing-scenario-in-finder-classic.md).

# Finder（クラシック）での自己修復シナリオの例

{% hint style="info" %}
Nexthink FinderはWindows専用のデスクトップアプリケーションで、その機能は現在Nexthinkのwebインターフェースで利用可能です。 Nexthinkは現在ブラウザから直接使用でき、ほとんどの機能は追加のデスクトップアプリケーションを必要としなくなりました。
{% endhint %}

ある公共企業のデバイスは、日常運用のために`MustRun`というエンタープライズアプリケーションを継続的に実行しなければなりません。 しかし、このアプリケーションはあまり安定しておらず、断続的にクラッシュします。 `mustrun.exe`がクラッシュすると、正常にシャットダウンすることができません。 その結果、アプリケーションは通常、ログファイルの一つを不整合な状態のままにします。 このログファイルの破損により、ファイルが削除されるまで`MustRun`は再起動できません。

従業員が`MustRun`がデバイス上で動作していないことに気づいたら、破損したログファイルを削除してから`mustrun.exe`を再起動することでアプリケーションを再開する必要があります。 この手順は従業員にとって不便であり、生産性に悪影響を及ぼします。 加えて、この問題にまだ慣れていない未経験の従業員は、問題を解決するためにヘルプデスクからのサポートを必要とする可能性が非常に高いです。

この例では、Nexthink Remote Actionsを活用して`mustrun.exe`のクラッシュを自動検出し、ログファイルを削除してアプリケーションを再起動する方法を学びます。 このプロセスを自動化することで、従業員の生産性が向上し、報告されるインシデントの数が減少します。

## リモートアクションの作成 <a href="#exampleofself-healingscenarioinfinder-classic-creatingtheremoteaction" id="exampleofself-healingscenarioinfinder-classic-creatingtheremoteaction"></a>

Remote Actionsを使用して`MustRun`アプリケーションの問題を修正するには、リモートアクションを作成し、スケジュールします。 リモートアクションには以下が含まれます：

* `MustRun`が最近クラッシュしたデバイスを選択する調査。
* 破損したログファイルを削除し、選択されたデバイスでアプリケーションを再起動するPowerShellスクリプト。

### ターゲット調査の定義 <a href="#exampleofself-healingscenarioinfinder-classic-definingthetargetinvestigation" id="exampleofself-healingscenarioinfinder-classic-definingthetargetinvestigation"></a>

[調査を作成する](/platform/ja/user-guide/investigations/creating-an-investigation-with-finder-classic.md)ことから始めて、`mustrun.exe`の実行ファイルのクラッシュを検出し、それが発生したデバイスを返します。 調査の時間枠を過去30分間に設定します。 リモートアクションの適切なスケジューリングと組み合わせることで、この時間枠は報告されたアプリケーションクラッシュを見逃さないようにします。 これは非常に保守的な選択です。 Collectorがアプリケーションクラッシュイベントを報告する速度のため、10分程度の時間枠も同じくらい有効です。

<figure><img src="/files/z4VCvAX7OhMqhERzBOZU" alt=""><figcaption></figcaption></figure>

Nexthinkはアプリケーションのクラッシュを検出するため、この例のリモートアクションにおける調査は、問題が発生した特定のデバイスをすでに返すことができます。 一方で、Nexthinkがデフォルトで問題を検出するために必要な情報を取得しない場合、例えばレジストリキーの値の変化など、リモートアクションのスクリプト内で誤った状況を確認してください。 スクリプトが問題の発生を確認する場合、関連する調査は影響を受ける可能性のあるすべてのデバイスを対象にする必要があります。

したがって、リモートアクションの問題検出メカニズムは次のいずれかに分類できます：

* 調査ベース。
* スクリプトベース。

### リモートアクションのスケジューリング <a href="#exampleofself-healingscenarioinfinder-classic-schedulingtheremoteaction" id="exampleofself-healingscenarioinfinder-classic-schedulingtheremoteaction"></a>

調査を保存した後に、選択されたデバイスに在する調査を定期的に評価して修復スクリプトを実行するリモートアクションを作成します。

リモートアクションを適切にスケジュールするためには、2つの期間を設定します：

### 評価期間

関連する調査の2回の評価間の時間間隔。 この値は、リモートアクションが`MustRun`のクラッシュをどのくらいの頻度でチェックするかを示します。 この期間は、関連する調査の時間枠と同等以下でなければならず、アプリケーションクラッシュイベントを見逃さないようにします。 評価期間が短ければ短いほど、リモートアクションはより迅速に反応し、その代わりにシステムにより多くの負荷がかかります。 アプリケーションクラッシュを検出するため、10分の評価期間で十分に反応します。 重要なアプリケーションには、1分の高速評価期間を選択してください。

### トリガー期間

リモートアクションの2回の連続トリガーの時間間隔。 アプリケーションのクラッシュなど、イベントに関する調査によって問題を検出するリモートアクションの場合、トリガー期間を調査の時間枠（例では30分）と等しく設定します。 これにより、同じイベントに対してスクリプトの実行が複数回トリガーされることがないようにします。

作成した調査をリモートアクションに関連付けるために、調査をリモートアクションのエディタ内の適切なエリアにドラッグアンドドロップしてください。

<figure><img src="/files/kc4pDlElfbyVCVCKL5OM" alt=""><figcaption></figcaption></figure>

### PowerShellスクリプトの追加 <a href="#exampleofself-healingscenarioinfinder-classic-addingthepowershellscript" id="exampleofself-healingscenarioinfinder-classic-addingthepowershellscript"></a>

お使いの好きなテキストエディタを開き、修復スクリプトを入力してください。 ファイルを保存する際には、スクリプトのテキストをUTF-8でBOM付きでエンコードすることを忘れないでください。

スクリプトが行うことは以下のとおりです：

1. Add-Typeコマンドレットを使用して、リモートアクションを扱うNexthinkの動的ライブラリ（`nxtremoteactions.dll`）を追加します。
2. スクリプトの結果を空文字列に初期化します。
3. 次のもので変数を初期化します：
   * 実行可能ファイル`mustrun.exe`のパス。
   * 削除する破損したログファイルのパス。
4. Remove-itemコマンドレットを使用してログファイルを削除し、結果を設定します。
5. Start-Processコマンドレットを使用して`MustRun`アプリケーションを再起動します。
6. リモートアクションライブラリからインポートされた**NXT**オブジェクトのWriteOutputStringメソッドを使用して、エンジンに結果を送信します。

```
  Add-Type -Path $env:NEXTHINK\RemoteActions\nxtremoteactions.dll

  [string] $result = ""

  # The paths to the MustRun application and its log file
  $mrexe = "$env:ProgramFiles\MustRun\mustrun.exe"
  $logfile = "$env:ProgramFiles\MustRun\log.txt"

  # Delete the log file if it is present
 try {
    Remove-item $logfile -ErrorAction Stop
    $result = "The corrupted log file was deleted"
  } catch {
    $result = "The log file does not exist"
  }

  # Restart the application
  Start-Process -FilePath $mrexe

  [NXT]::WriteOutputString("Result", $result)
```

セキュリティ上の理由から、Nexthinkはスクリプトに署名することを推奨しています。 テスト目的で、事前検証環境のみで未署名のスクリプトを使用することが安全です。

リモートアクションのエディタで、「インポート...」をクリックしてスクリプトをリモートアクションにリンクします。 Finderはスクリプトのソースを解釈し、出力セクションの下に**結果**出力をリストします。

リモートアクションの自己修復機能を利用するために、前のスクリプトを自分の使用ケースに合わせて調整してください。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.nexthink.com/platform/ja/user-guide/remote-actions/remote-actions-in-finder-classic/example-of-self-healing-scenario-in-finder-classic.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
