开发者

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 I开发者_开发技巧n 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?).


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜