chadmanvb
asked on
Any way to tell is somone is remoted into a computer using XP with .net 2.0?
I'm working on a script that users would log into a terminal server. From there they will see test workstations that are available for them to remote desktop to. I need to know how to tell if there is a remote desktop connection available or if someone else is using it for these test workstations. Any ideas how I can check for an active remote desktop session running on XP with .net 2.0? Thanks, Chad
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great! I will give it a shot tomorrow at work. Would you happen to know how to change this from c# to vb easily? Thanks again, Chad
ASKER
I just tried it, but I guess I am not sure how to get this working in VB. I imported System.Management. Any help would be great. Chad
ASKER
Was anyone able to change this from C# to vb? Thanks, Chad
ASKER
Ok, I have half of it working, but not sure why the other part is not working. Below is what I have and the first part works great.
Dim managementScope As New ManagementScope("\\" & TextBox1.Text & "\root\cimv2")
Dim ojectQuery As New ObjectQuery("Select * from Win32_LogonSession Where LogonType = 2 OR LogonType = 10")
Dim sessionObjectSearcher As New ManagementObjectSearcher(m anagementS cope, ojectQuery)
Dim sessionObjectCollection As ManagementObjectCollection = Nothing
sessionObjectSearcher.Opti ons.Timeou t = New System.TimeSpan(0, 0, 5)
sessionObjectSearcher.Opti ons.Return Immediatel y = True
sessionObjectCollection = sessionObjectSearcher.Get( )
Dim ManagementObject As ManagementObject
Dim loginType As String = ""
Dim strDomain As String = ""
For Each ManagementObject In sessionObjectCollection
loginType = ManagementObject("LogonTyp e")
If loginType = "2" Then
loginType = "Console"
Else
loginType = "Remote Desktop"
End If
Exit For
Next
MessageBox.Show(loginType)
'*****************everythi ng above here works!!!****************** ********** ******
'create a new query to get the user information for the selected session
'ObjectQuery associatorQuery = new ObjectQuery(string.Concat( "Associato rs of {Win32_LogonSession.LogonI d=", logonId, "} Where AssocClass=Win32_LoggedOnU ser Role=Dependent"));
Dim associatorQuery As New ObjectQuery(String.Concat( "Associato rs of {Win32_LogonSession.LogonI d=", logonId, "} Where AssocClass=Win32_LoggedOnU ser Role=Dependent"))
'????????????????????????? ?????????? ?????????? ??????
'ObjectQuery(associatorQue ry = New ObjectQuery(String.Concat( "Associato rs of {Win32_LogonSession.LogonI d=", logonId, "} Where AssocClass=Win32_LoggedOnU ser Role=Dependent")))
'execute the query
Dim associatorObjectSearcher As ManagementObjectSearcher = New ManagementObjectSearcher(m anagementS cope, associatorQuery)
Dim associatorObjectCollection As ManagementObjectCollection = Nothing
associatorObjectCollection = associatorObjectSearcher.G et()
Dim user As String = ""
Dim name As String = ""
Dim domain As String = ""
'iterate through all users (should only be one result per session)
For Each ManagementObject In associatorObjectCollection
'determine properties and output the result
user = associatorObjectItem("Name ")
name = associatorObjectItem("Full Name")
domain = associatorObjectItem("Doma in")
'?????????????????still have errors for these 3 items.
Exit For
Next
Dim managementScope As New ManagementScope("\\" & TextBox1.Text & "\root\cimv2")
Dim ojectQuery As New ObjectQuery("Select * from Win32_LogonSession Where LogonType = 2 OR LogonType = 10")
Dim sessionObjectSearcher As New ManagementObjectSearcher(m
Dim sessionObjectCollection As ManagementObjectCollection
sessionObjectSearcher.Opti
sessionObjectSearcher.Opti
sessionObjectCollection = sessionObjectSearcher.Get(
Dim ManagementObject As ManagementObject
Dim loginType As String = ""
Dim strDomain As String = ""
For Each ManagementObject In sessionObjectCollection
loginType = ManagementObject("LogonTyp
If loginType = "2" Then
loginType = "Console"
Else
loginType = "Remote Desktop"
End If
Exit For
Next
MessageBox.Show(loginType)
'*****************everythi
'create a new query to get the user information for the selected session
'ObjectQuery associatorQuery = new ObjectQuery(string.Concat(
Dim associatorQuery As New ObjectQuery(String.Concat(
'?????????????????????????
'ObjectQuery(associatorQue
'execute the query
Dim associatorObjectSearcher As ManagementObjectSearcher = New ManagementObjectSearcher(m
Dim associatorObjectCollection
associatorObjectCollection
Dim user As String = ""
Dim name As String = ""
Dim domain As String = ""
'iterate through all users (should only be one result per session)
For Each ManagementObject In associatorObjectCollection
'determine properties and output the result
user = associatorObjectItem("Name
name = associatorObjectItem("Full
domain = associatorObjectItem("Doma
'?????????????????still have errors for these 3 items.
Exit For
Next
ASKER
Works great, I will just try to do this in C#. Been looking for an excuse to learn it. Chad
Open in new window