Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


[solved but extented]about user logged out with "switch user"

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,48958
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> [solved but extented]about user logged out with "switch user"
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 [solved but extented]about user logged out with "s... - 7/2/2007 2:50:13 AM   
  whatwhatkit

 

Posts: 8
Score: 0
Joined: 7/2/2007
Status: offline
How to show all logged on user in XP including the the users that have use the "switch user" ?

Please help me,Thanks a lot!


I am from Hong Kong and I love this forum very much.This is my first post and I hope I can get a good answer. ^^

I have find some code,the codes can show that I am logging in,but they still cannot show other users that use "switch user"

i.e.
".UserName" method does not show the user that use "switch user"









e.g.1

Option Explicit
Dim objWMIService, objComputer, colComputer, strComputer

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")

For Each objComputer in colComputer
Wscript.Echo objComputer.UserName & " is logged on"
Next

' End of Sample Script. Who is logged on?















e.g.2


Dim objNet
On Error Resume Next

'In case we fail to create object then display our custom error

Set objNet = CreateObject("WScript.NetWork")
If  Err.Number <> 0 Then                'If error occured then display notice
MsgBox "Don't be Shy." & vbCRLF &_
         "Do not press ""No"" If your browser warns you."
Document.Location = "UserInfo.html"     
                                  'Place the Name of the document.
                                'It will display again
End if

Dim strInfo
strInfo = "User Name is     " & objNet.UserName & vbCRLF & _
    "Computer Name is " & objNet.ComputerName & vbCRLF & _
    "Domain Name is   " & objNet.UserDomain
MsgBox strInfo

Set objNet = Nothing                    'Destroy the Object to free the Memory





< Message edited by whatwhatkit -- 7/2/2007 6:17:02 PM >
 
 
Post #: 1
 
 RE: about user logged out with "switch user" - 7/2/2007 2:53:40 AM   
  ebgreen


Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
Well, I do not have a solution for your problem but I can tell you why you have the problem. When you use "Switch User" the current user is not logged out so you would never see them as a logged out user.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to whatwhatkit)
 
 
Post #: 2
 
 RE: about user logged out with "switch user" - 7/2/2007 6:02:57 AM   
  whatwhatkit

 

Posts: 8
Score: 0
Joined: 7/2/2007
Status: offline
quote:

ORIGINAL: ebgreen

Well, I do not have a solution for your problem but I can tell you why you have the problem. When you use "Switch User" the current user is not logged out so you would never see them as a logged out user.


Yes,they are not logged out.

I want to show them all,but i don't know the way.

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: about user logged out with "switch user" - 7/2/2007 7:01:49 AM   
  ebgreen


Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
I don't have a way to test it right now but I would look at the running processes. I suspect that you will see some from the switched users.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to whatwhatkit)
 
 
Post #: 4
 
 RE: about user logged out with "switch user" - 7/2/2007 11:35:18 AM   
  dm_4ever


Posts: 2663
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
ebgreen is correct....look at the explorer.exe process and get the owner for each.

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: about user logged out with "switch user" - 7/2/2007 5:16:08 PM   
  whatwhatkit

 

Posts: 8
Score: 0
Joined: 7/2/2007
Status: offline
quote:

ORIGINAL: dm_4ever

ebgreen is correct....look at the explorer.exe process and get the owner for each.


Oh,I think getting the owner of explorer.exe can achieve my objective.
Thank a lot.

I will try to work it out,but I am new to vbs.

(in reply to dm_4ever)
 
 
Post #: 6
 
 RE: about user logged out with "switch user" - 7/2/2007 6:10:07 PM   
  whatwhatkit

 

Posts: 8
Score: 0
Joined: 7/2/2007
Status: offline
As I have said,I am new to VBS.
I search from google and finally get something close to the answer.
However,it return the process owner of ALL process!
I made some changes and everything works fine,I have made the code returning only the owner of "explore.exe" and thus the user that are switched in the msgbox


solution 1: return the process owner of ALL process in the msgbox (from: http://www.microsoft.com/technet/scriptcenter/guide/sas_prc_fywf.mspx?mfr=true )
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("SELECT * FROM Win32_Process")
For Each objProcess in colProcessList
colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain)
Wscript.Echo "Process " & objProcess.Name & " is owned by " _
& strUserDomain & "\" & strNameOfUser & "."
Next





solution 2: return only the owner of "explore.exe" and thus the user that are switched in the msgbox( modified from solution 1 by try and error^^)

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery _
("SELECT * FROM Win32_Process")
For Each objProcess in colProcessList
colProperties = objProcess.GetOwner(strNameOfUser,strUserDomain)
if objProcess.Name = "explorer.exe" Then
Wscript.Echo "Process " & objProcess.Name & " is owned by " _
& strUserDomain & "\" & strNameOfUser & "."
end If
Next







Up to here, the problem can be considered to be solved.
But, for my understanding, would someone explan the code to me?
I know nearly nothing about the code, and my solution 2 seems doing a lot of unnessary thing. ^^
Thank you!


p.s.

Set colProcessList = objWMIService.ExecQuery _
 
("SELECT * FROM Win32_Process")

It seems that * is too much, I tried  the code below and errors.

Set colProcessList = objWMIService.ExecQuery _
 
("SELECT "explore.exe" FROM Win32_Process"





< Message edited by whatwhatkit -- 7/2/2007 6:17:33 PM >

(in reply to whatwhatkit)
 
 
Post #: 7
 
 RE: about user logged out with "switch user" - 7/3/2007 1:18:36 AM   
  dm_4ever


Posts: 2663
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Try this...


      

< Message edited by dm_4ever -- 7/3/2007 1:19:43 AM >


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to whatwhatkit)
 
 
Post #: 8
 
 RE: about user logged out with "switch user" - 7/3/2007 2:55:56 AM   
  whatwhatkit

 

Posts: 8
Score: 0
Joined: 7/2/2007
Status: offline
quote:

ORIGINAL: dm_4ever

Try this...


      


it work well! thank you.
Why I must use For loop to loop though every thing?

(in reply to dm_4ever)
 
 
Post #: 9
 
 RE: about user logged out with "switch user" - 7/3/2007 3:14:22 AM   
  ebgreen


Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
How else would you loop through everything?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to whatwhatkit)
 
 
Post #: 10
 
 RE: about user logged out with "switch user" - 7/3/2007 3:37:22 AM   
  whatwhatkit

 

Posts: 8
Score: 0
Joined: 7/2/2007
Status: offline
quote:

ORIGINAL: ebgreen

How else would you loop through everything?


Or.....I would like to ask

Why I need to use a For Loop in here?

(in reply to ebgreen)
 
 
Post #: 11
 
 RE: about user logged out with "switch user" - 7/3/2007 3:45:36 AM   
  ebgreen


Posts: 5035
Score: 31
Joined: 7/12/2005
Status: online
What you get back from the query is a collection of items. The only way to do something with all of the items is to loop through doing it with each item in turn.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to whatwhatkit)
 
 
Post #: 12
 
 RE: about user logged out with "switch user" - 7/3/2007 4:04:27 AM   
  whatwhatkit

 

Posts: 8
Score: 0
Joined: 7/2/2007
Status: offline
Thank You,
I understand now!

(in reply to ebgreen)
 
 
Post #: 13
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> [solved but extented]about user logged out with "switch user" Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts