TimberLandChapelのTech Blog

TimberLandChapel が提供する技術Tips,思いつきメモ,雑感ブログです。
Office 互換リボン Release 1.0 をリリースしました。

購読

Books

INETAJ

Microsoft

SQL Server

TLC.com

クリエイティブ・コモンズ

情報処理関係官公庁

今期のアンケート

【WMI】WMI を利用してリモートデスクトップ接続ユーザー名をしゅとくする?
WMI からリモートデスクトップ接続のユーザー名を取得する?

WMI からリモートコンピュータに対話ログインしているユーザー名を取得することができます。

WMI でリモートコンピュータにログインしているユーザー名を取得する
Dim searcher As New Management.ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem")
Dim myScope As New ManagementScope
Dim result As ManagementObjectCollection
myScope.Options.Username = "User"
myScope.Options.Password = "password"
myScope.Path.Server = "Remote"
searcher.Scope = myScope
 
result = searcher.Get
 
For Each this As ManagementObject In result
Debug.WriteLine(this.Item("UserName"))
Next

取得対象のリモートコンピュータにユーザーが対話ログインしていると,ユーザー名を取得できます。

じゃあリモートデスクトップ接続だったらどうなるんだ?

リモートデスクトップ接続してたらどうなんでしょうか?
ちゃんと取得できますか?

とりあえず,うまく取得できませんでした。
どうしてもリモートデスクトップ接続しているユーザーのユーザー名は空文字列で帰ってきてしまいます。
「Win32_LogonSession」を使用すると,リモートデスクトップ接続しているユーザーの「LogonID」を取得することはできます。

「LogonType」が 10 のユーザーが「Remote」,「interactive」なユーザーです。

WMI でリモートデスクトップ接続しているユーザーの情報を取得する
Dim searcher As New Management.ManagementObjectSearcher("SELECT * FROM Win32_LogonSession")
Dim myScope As New ManagementScope
Dim result As ManagementObjectCollection
myScope.Options.Username = "User"
myScope.Options.Password = "password"
myScope.Path.Server = "Remote"
searcher.Scope = myScope
 
result = searcher.Get
 
For Each this As ManagementObject In result
    Debug.WriteLine(this.Item("LogonType"))
    Debug.WriteLine(this.Item("UserName"))
Next

「LogonID」から「Win32_Process」などの情報をとることはできますが,効果的な情報が取得できません。
さて。。。どうしたものか。。。

Published 2005年11月3日 2:39 投稿者 timberlandchapel

コメント

コメントはありません