コアダンプの数だけ強くなれるよ

見習いエンジニアの備忘log

コマンドプロンプトの画面ログを取る

仕事でWindowsのコマンドプロンプトを使うときに画面ログを取りたいときがある。
(いままでその都度で表示内容をコピペしたり、PrintScreenを取ったりしており効率が悪かった)

PowerShellを使えばログを取る方法があるっぽいが何かと面倒臭そう…
PsExecを使ってSSHログイン可能にする方法もあるけど勝手にソフトはインストールできなかったりする。

そんな時、Windowsの標準機能にTelnetサーバーがあることを知り、TeratermからループバックでTelnetログインできれば簡単にログが取れるのでは?
と、思いついたのでやってみた。

環境はWindows7 (Home Premium)

Telnetサーバーの有効化

コントロールパネルから辿っていきTelnetサーバー機能を有効化する。

f:id:segmentation-fault:20170724221205p:plain

f:id:segmentation-fault:20170724221309p:plain

f:id:segmentation-fault:20170724221318p:plain

f:id:segmentation-fault:20170724221343p:plain

しばらく待つと有効化される。

Telnetサーバー起動

次にTelnetサーバーを起動する。

[Windowsボタン + R ] で services.mscを実行しサービス管理を開く。

f:id:segmentation-fault:20170724221453p:plain


Telnetを選択してプロパティを開きスタートアップの種類を"手動"に変更する。

f:id:segmentation-fault:20170724221620p:plain

f:id:segmentation-fault:20170724221802p:plain


プロパティ変更後にTelnetを開始する。

f:id:segmentation-fault:20170724221835p:plain


ここでTelnet接続ができるか試してみるが、何やら接続拒否されてしまう。
メッセージの内容を見るとTelnetClientsグループなるものにユーザを追加する必要があるらしい。

f:id:segmentation-fault:20170724221911p:plain

Access Denied: Specified user is not a member of TelnetClients group.
Server administrator must add this user to the above group.

Telnet Server has closed the connection

TelnetClientsグループの設定

コマンドプロンプト or PowerShellを管理者で起動し下記コマンドを打つ。

f:id:segmentation-fault:20170724222606p:plain

# TelnetClientsグループを新規作成
net localgroup TelnetClients /add

# TelnetClientsグループに<ログインユーザ>を追加
net localgroup "TelnetClients" "<ログインユーザ>" /add


これで準備が完了。念のためTelnetサーバーを再起動する。

Telnetログイン

再度、Telnetで接続しログインできれば成功!
文字コードはSJISに設定しておく。

f:id:segmentation-fault:20170724223911p:plain

f:id:segmentation-fault:20170724222915p:plain



Telnetなのでセキュリティ的に外部からの接続は拒否推奨。