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」なユーザーです。
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」などの情報をとることはできますが,効果的な情報が取得できません。
さて。。。どうしたものか。。。