TimberLandChapel's Tech Blog

TimberLandChapel provide Tips, tech note and scribbling.
Updated my site as English site for APAC users.
TLC.com .Metrix 4.0 Beta1 released

サイトの日本語化方法はこちら

Syndication

News

INETAJ

情報処理関係官公庁

SQL Server

TLC.com

Microsoft

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

http://www3.clustrmaps.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 by timberlandchapel
Filed under: ,

Comments

No Comments