我需要知道会话是否属于当前用户。我以为我会做这样的事情:
Public Function SessionID()
Dim session_id = 0
Dim user As System.Security.Principal.WindowsIdentity
user = System.Security.Principal.WindowsIdentity.GetCurrent()
Dim selectQuery As SelectQuery = New SelectQuery("Win32_LogonSession")
Dim searcher As New ManagementObjectSearcher(selectQuery)
For Each session As ManagementObject In searcher.Get
If session("LogonID") = user.Name Then
session_id = Convert.ToInt32(session("LogonID"))
End If
Next
Return session_id
End Function
SelectQuery
返回当前会话列表但我找不到当前用户的登录ID以进行比较