Nathan McKaskle
Nathan McKaskle

Reputation: 3083

WMI Query Error for Win32_LogonSession (Windows 2003)

I'm trying to write a vbscript that takes the currently logged in users on a terminal server and does something else with that information. I whittled it down to the most basic script based on the line on which I was getting the error.

'On Error Resume Next

dim colSessions, objWMI, objitem

Set oWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colSessions = objWMI.ExecQuery("Select * from Win32_LogonSession")

For Each objitem In colSessions
    WScript.Echo objitem.LogonId
Next

I am getting the following error on line 6 (where the query is for Win32_LogonSession):

VBScript runtime error: Object required: ' '

Why am I getting this error? What am I doing wrong? I can't find anyone else reporting this problem (why am I always the first to find and report them?).

Upvotes: 1

Views: 851

Answers (1)

Luke
Luke

Reputation: 11431

Check the variable names. oWMI (on the GetObject line) should be objWMI.

Upvotes: 1

Related Questions