Login | |
|
 |
RE: Help figuring out Whats wrong with Script - 3/27/2008 5:49:11 AM
|
|
 |
|
| |
ebgreen
Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
|
You need to verify that you have the Win32_LogonSession class on the machine that you are running the script against (can't think of any way that you would not have it but just make sure). Next you need to make sure that at the time that you run the script there are some instances of that class where the LogonType is 2 or the LogonType is 10. Basically your query is return ing now instances. You just need to figure out why.
_____________________________
"... 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
|
|
| |
|
|
|
 |
RE: Help figuring out Whats wrong with Script - 3/27/2008 6:26:21 AM
|
|
 |
|
| |
ebgreen
Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
|
Your query only returns a collection if their are sessions I believe. This means that if their aren't any sessions no collection is ever created. Try using IsObject instead of .Count.
_____________________________
"... 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
|
|
| |
|
|
|
 |
RE: Help figuring out Whats wrong with Script - 3/31/2008 12:46:58 AM
|
|
 |
|
| |
ebgreen
Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
|
So without actually figuring out the root issue since I don't have time to right now, wrap the count test in an On Error Resume Next block: On Error Resume Next bDoThings = False if colSessions.Count > 0 Then bDoThings =True On Error Goto 0 If bDoThings Then 'Process the recordset here End If
_____________________________
"... 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
|
|
| |
|
|
|
 |
RE: Help figuring out Whats wrong with Script - 3/31/2008 3:16:31 AM
|
|
 |
|
| |
ebgreen
Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
|
That's really goofy. I must be missing something. What do you see with this change? bDoThings = False MsgBox colSessions.Count if colSessions.Count > 0 Then bDoThings =True Else MsgBox ("No Sessions Exist, either no users or Win32_LogonSession does not exist") End If On Error Goto 0
_____________________________
"... 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
|
|
| |
|
|
|
 |
RE: Help figuring out Whats wrong with Script - 3/31/2008 3:45:28 AM
|
|
 |
|
| |
ebgreen
Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
|
I think the issue is that there is no colSessions ever created if the class does not exist, so there is no .Count property of the non-existent collection.
_____________________________
"... 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
|
|
| |
|
|
|
 |
RE: Help figuring out Whats wrong with Script - 3/31/2008 5:06:06 AM
|
|
 |
|
| |
ebgreen
Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
|
Ok, so the ExecQuery returns a collection regardless. It's just that without a valid class the collection does not have all of it's properties populated. So it looks like there isn't a really good method for doing this. I suppose you could do something like this: Option Explicit Dim strComputer , bDoThings Dim objWMIService , colSessions , objSession , colList , objItem strComputer = InputBox("Please Enter Server To Check for Logged In Users") Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") On Error Resume Next Set colSessions = objWMIService.ExecQuery ("Select * from Win32_LogonSession Where LogonType = 2 OR LogonType = 10") nCount = colSessions.Count bDoThings = False if VarType(nCount) > 0 Then bDoThings =True Else MsgBox ("No Sessions Exist, either no users or Win32_LogonSession does not exist") End If On Error Goto 0 If bDoThings = True Then For Each objSession in colSessions Set colList = objWMIService.ExecQuery("Associators of "& "{Win32_LogonSession.LogonId=" & objSession.LogonId & "} " & "Where AssocClass=Win32_LoggedOnUser Role=Dependent" ) For Each objItem in colList WScript.Echo "Username: " & objItem.Name Next Next Wscript.Echo "Script is Complete" End If I think that would do what you want.
_____________________________
"... 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
|
|
| |
|
|
|
 |
RE: Help figuring out Whats wrong with Script - 3/31/2008 5:33:16 AM
|
|
 |
|
| |
ebgreen
Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
|
So even with the On Error Resume Next in there you still get an error? When I run that code looking for a completely non-existent class it runs without an error.
_____________________________
"... 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
|
|
| |
|
|
|
|
|