G
Guest
I have the following problem:
User A is logged in to a windows 2000 terminal. He runs an application which
runs under the credentials of a different user. If I try to see the current
user throught the application I can only see the user that started the
thread. How can I see the user that is logged in??
I tried the following code:
Private Function GetUser() As String
Dim strCurrentUser As String = ""
Dim moReturn As Management.ManagementObjectCollection
Dim moSearch As Management.ManagementObjectSearcher
Dim mo As Management.ManagementObject
'This scrolls through all the running processes on the PC to
determine who is running the "explorer.exe" process. It then returns the
username ready for comparison.
moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_Process")
moReturn = moSearch.Get
For Each mo In moReturn
Dim arOwner(2) As String
mo.InvokeMethod("GetOwner", arOwner)
Dim strOut As String
strOut = String.Format("{0} Owner {1} Domain {2}", mo("Name"),
arOwner(0), arOwner(1))
MessageBox.Show(strOut)
If (mo("Name") = "explorer.exe") Then
strCurrentUser = String.Format("{0}", arOwner(0))
MessageBox.Show(strCurrentUser)
End If
Next
Return strCurrentUser
End Function
which works on my windows XP machine but when I try it on my windows 2000
terminal server (In workgroup mode) the owner of the explorer.exe proccess is
empty.
Any help.. PLEAAASSEEE....
Thanks in advance
Lucas
User A is logged in to a windows 2000 terminal. He runs an application which
runs under the credentials of a different user. If I try to see the current
user throught the application I can only see the user that started the
thread. How can I see the user that is logged in??
I tried the following code:
Private Function GetUser() As String
Dim strCurrentUser As String = ""
Dim moReturn As Management.ManagementObjectCollection
Dim moSearch As Management.ManagementObjectSearcher
Dim mo As Management.ManagementObject
'This scrolls through all the running processes on the PC to
determine who is running the "explorer.exe" process. It then returns the
username ready for comparison.
moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_Process")
moReturn = moSearch.Get
For Each mo In moReturn
Dim arOwner(2) As String
mo.InvokeMethod("GetOwner", arOwner)
Dim strOut As String
strOut = String.Format("{0} Owner {1} Domain {2}", mo("Name"),
arOwner(0), arOwner(1))
MessageBox.Show(strOut)
If (mo("Name") = "explorer.exe") Then
strCurrentUser = String.Format("{0}", arOwner(0))
MessageBox.Show(strCurrentUser)
End If
Next
Return strCurrentUser
End Function
which works on my windows XP machine but when I try it on my windows 2000
terminal server (In workgroup mode) the owner of the explorer.exe proccess is
empty.
Any help.. PLEAAASSEEE....
Thanks in advance
Lucas