0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Firefox で telnet プロトコルを Teraterm で開く方法

Last updated at Posted at 2025-02-21

前提

EVE-NG でルーターのアイコンをクリックすると telnet クライアントを起動するが、端末制御が駄目すぎるので Teraterm にしたい。
でも、直接 Firefox で ttermpro.exe を起動しようとしたら引数が指定できない。
では、バッチファイルで作ろうかと思ったらバッチファイルを指定できない。
実行形式のファイルしか設定できないので、引数を処理できる実行ファイルが要るらしい。
と言うことで Copilot で作成した。以降、簡単に使えるようにメモメモ。

プログラムの中で変更するところ

  • Teraterm のファイルの場所は以下の部分を書き換える
    filePath = @"C:\Program Files (x86)\teraterm5\ttermpro.exe";

  • Traterm を起動するコマンド
    ttermpro.exe /T=1 /nossh <引数> で起動
    ポート番号があっても : で区切られているため、引数としては 1つで問題ない。
    必要があれば arguments = string.Format("/T=1 /nossh {0}", args[0]); 部分を書き換える事で引数の形式を変えることができる。

  • コンパイラは Windows に入っている .Net の C# を利用
    "C:\Windows\Microsoft.NET\Framework\<バージョン番号>\csc.exe"
    バージョンによって場所が変わるので場所を確認しておくこと。(v4.0.30319 以外は試していないのでご了承ください)

生成されたプログラム

Teraterm_telnet.cs
// & "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" -nologo "Teraterm_telnet.cs"

using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;

// アセンブリに関する一般情報は、以下の属性セットを通じて制御されます。
// アセンブリに関連付けられている情報を変更するには、これらの属性値を変更します。
[assembly: AssemblyTitle("Teraterm launcher for Telnet")]
[assembly: AssemblyDescription("telnet 接続に Teraterm を使用")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("1円切手")]
[assembly: AssemblyProduct("Teraterm Launcher (Telnet)")]
[assembly: AssemblyCopyright("Copyright © 2025 jp_yen")]
[assembly: AssemblyTrademark("no reserved")]
[assembly: AssemblyCulture("")]

// ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから参照できなくなります。
// COM からこのアセンブリ内の型にアクセスする必要がある場合、その型の ComVisible 属性を true に設定してください。
[assembly: ComVisible(false)]

// 次の GUID は、このプロジェクトが COM に公開される場合の typelib の ID です。
[assembly: Guid("400F845C-4BD8-4FAE-8D4C-C6D003C1D8AE")]

// アセンブリのバージョン情報は、以下の 4 つの値で構成されています:
// 
//      メジャー バージョン
//      マイナー バージョン 
//      ビルド番号
//      リビジョン
// 
// すべての値を指定するか、既定値を使用することができます。
// ビルド番号およびリビジョン番号を既定値にするには、'*' を使用します。
[assembly: AssemblyVersion("0.0.0.1")]
[assembly: AssemblyFileVersion("0.0.0.1")]

class Program
{
    static void Main(string[] args)
    {
        if (args.Length == 0)
        {
            Console.WriteLine("引数を指定してください。");
            return;
        }

        string arguments = string.Format("/T=1 /nossh {0}", args[0]);
        string filePath = @"C:\Program Files (x86)\teraterm5\ttermpro.exe";

        ProcessStartInfo startInfo = new ProcessStartInfo
        {
            FileName = filePath,
            Arguments = arguments,
            UseShellExecute = false,
            CreateNoWindow = true
        };

        Process.Start(startInfo);
    }
}

PowerShell 上でコンパイルする

PS C:\Users\abc123\Desktop> & "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" "Teraterm_telnet.cs"
Microsoft (R) Visual C# Compiler version 4.8.9232.0
for C# 5
Copyright (C) Microsoft Corporation. All rights reserved.

This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240

PS C:\Users\abc123\Desktop> ls .\Teraterm_telnet*


    ディレクトリ: C:\Users\abc123\Desktop


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----        2025/02/21     15:56           2733 Teraterm_telnet.cs
-a----        2025/02/21     15:56           5120 Teraterm_telnet.exe


PS C:\Users\abc123\Desktop>

exe ファイルができたので、Teraterm のフォルダへコピーする。

Firefox の設定

Firefox の 設定 > 一般 > プログラム から telnet プロトコルで先程コピーした Teraterm_telnet.exe を選択
image.png

ここで Teraterm launcher for Telnet と表示させるために [assembly: の行があります。此処にプログラム名を表示させなくて良い場合は行数が半分ぐらいになります。

公式の詳細な手順 → ファイル読み込み時の動作設定

EVE-NG でルータのアイコンをクリックすると...Teraterm が起動した。すばらしい!

※ 参考
【EVE-NG】ノードをクリックするとTeraTermが起動するようにしたい

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?