リモートPCにメッセージボックスを表示してみる

テストメッセージ

Windows NT/2000/XPの頃、NET SENDコマンドを使って、簡単に他のPCに対してメッセージボックスを通知することができた。
送られてきた方は、急にメッセージボックスが表示され、結構ビビるのだが。

昔、この仕組みというかサービスを利用したフリーソフトを作ったこともあった。

でも、Windows XPでは、”Messenger”サービスが起動していないと使えなくなり(デフォルトは停止)、更にVista以降では、”Messenger”サービス自体が消え、この方法でメッセージ通知することができなくなった。

 

その代わりに、IP Messengerなどのフリーソフトを使う方法もあるけど、相手側もIP Messengerを起動しておかなければならない。

で、いろいろ調べてみたら、Vista以降では、msgってコマンドってのが使えるらしい。

 
 

試しに、コマンドプロンプトから以下のようなコマンドを打ってみる。

msg.exe (userid) "(message)"

 userid・・・WindowsログインユーザID
 message・・・表示したいメッセージ

 
例)

msg osada "テストメッセージ"

 

すると、指定したユーザー(osada)にメッセージ「テストメッセージ」が通知される。
メッセージボックス「Test Message!」

 
 

でも、このmsgコマンドは、PCにログイン中のユーザーに対して通知するもの、他のPCに対して通知ができない。

どうしても他のPCにメッセージを通知したい。
例えば、Windowsサーバーで実行していたバッチが完了したら、自分のPCにメッセージ通知したい場合など。

 

いろいろ調べてみた。
ID/パスワードが分からないといけないとか、ちょっと苦しいけど以下の2つのツールを組み合わせれば、何とか実現できそうだ。

  • msg.exe
    メッセージボックスを通知
  • psExec.exe
    他のリモートPCのコマンドを実行

 
 
 

まずは、psExec.exeの用意。

  ダウンロード先:
  http://technet.microsoft.com/ja-jp/sysinternals/bb897553

psExec.exeは、通知元のPCだけに必要で、通知先のPCに用意する必要は無い。

psExec初回起動時に以下のダイアログが表示されるので内容を確認し[Agree]する。
PsExec License Agreement

PcExecの使い方はざっくりと、

PsExec.exe \\(computer) -u (userid) -p (password) (command)

 computer・・・コンピュータ名またはIPアドレス
 userid・・・WindowsログインユーザID
 password・・・Windowsログインパスワード
 command・・・実行したいコマンド

 

例えば、リモートのPCに対しメモ帳を起動する場合。

例)

PsExec \\PC1 -u Administrator -p password notepad

メモ帳

 
 

 # このPsExec があれば、ちょっとしたコマンドなら遠隔操作できてしまう。。
 # と、言ってもログインID/PWが分からなければ何もできないし、それを知っているなら
 # リモートデスクトップ接続とかで何とでもなる。(話が脱線してしまった)

 
 
それで、
PsExecコマンドと、msgコマンドを組み合わせれば、リモートPCにメッセージ通知できる。

PsExec.exe \\(computer) -u (userid) -p (password) msg (userid) "(message)"

  computer・・・コンピュータ名またはIPアドレス
  userid・・・WindowsログインユーザID
  password・・・Windowsログインパスワード
  message・・・通知したいメッセージ

 

例)

PsExec.exe \\10.124.xx.xx -u osada -p password msg osada "テストメッセージ"

メッセージボックス「Test Message!」
おぉ!何とかリモートPCにメッセージボックスが表示された。

 
 
 

コマンドの使用方法

コマンドの使い方は以下の通り(Usage)。

 

msgコマンド
msg.exe
ユーザーにメッセージを送信します。

MSG {ユーザー名 | セッション名 | セッション ID | @ファイル名 | *}
    [/SERVER:サーバー名] [/TIME:秒] [/V] [/W] [メッセージ]

  ユーザー名          送信先のユーザー名を指定します。
  セッション名        セッション名を指定します。
  セッションID        セッション ID を指定します。
  @ファイル名         メッセージの送信先一覧のファイル (ユーザー名、
                      セッション名、セッション ID) を指定します。
  *                   指定されたサーバーのすべてのセッションにメッセージを
                      送信します。
  /SERVER:サーバー名  送信先のサーバーを指定します (既定値は現在のサーバー)。
  /TIME:秒            受信者の確認応答までの待ち時間を指定します。
  /V                  実行中に詳細情報を表示します。
  /W                  ユーザーからの応答を待ちます。通常 /V オプションと共に
                      指定します。
  メッセージ          送信するメッセージを指定します。指定しない場合は、入力
                      プロンプトが表示されるか、または stdin から読み取ります。

 
 

PsExecコマンド
PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com

PsExec executes a program on a remote system, where remotely executed console
applications execute interactively.

Usage: psexec [\\computer[,computer2[,...] | @file]][-u user [-p psswd][-n s][-l
][-s|-e][-x][-i [session]][-c [-f|-v]][-w directory][-d][-<priority>][-a n,n,...
] cmd [arguments]
     -a         Separate processors on which the application can run with
                commas where 1 is the lowest numbered CPU. For example,
                to run the application on CPU 2 and CPU 4, enter:
                "-a 2,4"
     -c         Copy the specified program to the remote system for
                execution. If you omit this option the application
                must be in the system path on the remote system.
     -d         Don't wait for process to terminate (non-interactive).
     -e         Does not load the specified account's profile.
     -f         Copy the specified program even if the file already
                exists on the remote system.
     -i         Run the program so that it interacts with the desktop of the
                specified session on the remote system. If no session is
                specified the process runs in the console session.
     -h         If the target system is Vista or higher, has the process
                run with the account's elevated token, if available.
     -l         Run process as limited user (strips the Administrators group
                and allows only privileges assigned to the Users group).
                On Windows Vista the process runs with Low Integrity.
     -n         Specifies timeout in seconds connecting to remote computers.
     -p         Specifies optional password for user name. If you omit this
                you will be prompted to enter a hidden password.
     -s         Run the remote process in the System account.
     -u         Specifies optional user name for login to remote
                computer.
     -v         Copy the specified file only if it has a higher version number
                or is newer on than the one on the remote system.
     -w         Set the working directory of the process (relative to
                remote computer).
     -x         Display the UI on the Winlogon secure desktop (local system
                only).
     -priority  Specifies -low, -belownormal, -abovenormal, -high or
                -realtime to run the process at a different priority. Use
                -background to run at low memory and I/O priority on Vista.
     computer   Direct PsExec to run the application on the remote
                computer or computers specified. If you omit the computer
                name PsExec runs the application on the local system,
                and if you specify a wildcard (\\*), PsExec runs the
                command on all computers in the current domain.
     @file      PsExec will execute the command on each of the computers listed
                in the file.
     program    Name of application to execute.
     arguments  Arguments to pass (note that file paths must be
                absolute paths on the target system).

You can enclose applications that have spaces in their name with
quotation marks e.g. psexec \\marklap "c:\long name app.exe".
Input is only passed to the remote system when you press the enter
key, and typing Ctrl-C terminates the remote process.

If you omit a user name the process will run in the context of your
account on the remote system, but will not have access to network
resources (because it is impersonating). Specify a valid user name
in the Domain\User syntax if the remote process requires access
to network resources or to run in a different account. Note that
the password is transmitted in clear text to the remote system.

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


*