From: Bart Perrier on
I am using the Win32_ComputerSystem Class to retrieve the currently logged
in user of a workstation. I have other tools that retrieve this information
but am migrating to an HTA for common network tasks; this being one of them.

My issue is that many workstations are returning "No User Logged In". So far
the only machines I have seen this on are 2000 Professional and I am certain
that a user is logged in. The WMI version is 1085.0005 but I have other 2000
Server machines with 1085.0005 that I am successful in retrieving the logged
in user.

Should I be using a different class to get more reliability?

Thanks.
Bart Perrier

' create WMIService connection to strComputer
Set objWMIService = GetObject("winmgmts:" & _
"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
If ErrorConnecting(strComputer) = False Then
Set colLoggedInUser = objWMIService.ExecQuery _
("SELECT * FROM Win32_ComputerSystem ")
For Each objLoggedInUser In colLoggedInUser
strHTML = strHTML & objLoggedInUser.username & "<br>"
If IsNull(objLoggedInUser.username) Then
strHTML = "No User Logged In"
End If
Next
DataArea1.InnerHTML = strHTML
End If


From: Ato Bisda on
Hello,

Try a "multi-pronged" approach.

If Win32_ComputerSystem comes up empty, you can try either of the following
alternative methods:

(1) From a Wscript.Shell, do an "NBTSTAT -a computerName" and trap stdout.
The logged-in username (if any) should show up as an "<03>" record.

(2) Look up the last logged-in user entry in the remote computer's registry.
You can use either REGOBJ.DLL or the WMI registry provider to remotely
read the value "DefaultUserName" in the following key:

HKEY_LOCAL_MACHINE\SOFTWARE\MiĆ½crosoft\Windows NT\CurrentVersion\Winlogon


HTH,
Ato



- Hide quoted text -
- Show quoted text -


"Bart Perrier" <bart_perrier(a)hotmail.com> wrote in message
news:%23quoDYCfFHA.576(a)TK2MSFTNGP15.phx.gbl...
> I am using the Win32_ComputerSystem Class to retrieve the currently logged
> in user of a workstation. I have other tools that retrieve this information
> but am migrating to an HTA for common network tasks; this being one of them.
>
> My issue is that many workstations are returning "No User Logged In". So far
> the only machines I have seen this on are 2000 Professional and I am certain
> that a user is logged in. The WMI version is 1085.0005 but I have other 2000
> Server machines with 1085.0005 that I am successful in retrieving the logged
> in user.
>
> Should I be using a different class to get more reliability?
>
> Thanks.
> Bart Perrier
>
> ' create WMIService connection to strComputer
> Set objWMIService = GetObject("winmgmts:" & _
> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> If ErrorConnecting(strComputer) = False Then
> Set colLoggedInUser = objWMIService.ExecQuery _
> ("SELECT * FROM Win32_ComputerSystem ")
> For Each objLoggedInUser In colLoggedInUser
> strHTML = strHTML & objLoggedInUser.username & "<br>"
> If IsNull(objLoggedInUser.username) Then
> strHTML = "No User Logged In"
> End If
> Next
> DataArea1.InnerHTML = strHTML
> End If
>
>


From: Mike Long on
An alternate method I use is environment strings.

Set WshShell = WScript.CreateObject("Wscript.Shell")
Username = WshShell.ExpandEnvironmentStrings("%USERNAME%")


Mike
-Knowing it doesn't really answer the question, but trying to help
anyway

From: Bart Perrier on
I appreciate both replies. I am considering the last logged in user as
mentioned by Ato as a "best guess" if my Win32_ComputerSystem query is NULL.
The more I think about it, the better it sounds...given the other result
failed.

I'm searching for another Class but haven't seen one for logged in user.

Thanks for both ideas.

Bart


"Mike Long" <mlong35(a)gmail.com> wrote in message
news:1120078092.298399.260530(a)g14g2000cwa.googlegroups.com...
> An alternate method I use is environment strings.
>
> Set WshShell = WScript.CreateObject("Wscript.Shell")
> Username = WshShell.ExpandEnvironmentStrings("%USERNAME%")
>
>
> Mike
> -Knowing it doesn't really answer the question, but trying to help
> anyway
>


From: Scott McNairy (MVP) on
That property uses the GetUserName api documented here
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getusername.asp)
as you can see it has a couple of considerations that make it not so
reliable in the way you are seeing in determining who is currently logged
into the system. I think that the below script may give you better results
as others have had success with it.

set svc = getObject("winmgmts:root\cimv2")
set objEnum = svc.execQuery("select __relpath from win32_process where
caption = 'explorer.exe'")
for each obj in objEnum
set outParams = obj.ExecMethod_("GetOwner")
wscript.echo outParams.Domain & "\" & outParams.User
next

--
Scott McNairy
Microsoft MVP - Windows Server Management Infrastructure


"Bart Perrier" <bart_perrier(a)hotmail.com> wrote in message
news:%232iCraPfFHA.1248(a)TK2MSFTNGP12.phx.gbl...
>I appreciate both replies. I am considering the last logged in user as
> mentioned by Ato as a "best guess" if my Win32_ComputerSystem query is
> NULL.
> The more I think about it, the better it sounds...given the other result
> failed.
>
> I'm searching for another Class but haven't seen one for logged in user.
>
> Thanks for both ideas.
>
> Bart
>
>
> "Mike Long" <mlong35(a)gmail.com> wrote in message
> news:1120078092.298399.260530(a)g14g2000cwa.googlegroups.com...
>> An alternate method I use is environment strings.
>>
>> Set WshShell = WScript.CreateObject("Wscript.Shell")
>> Username = WshShell.ExpandEnvironmentStrings("%USERNAME%")
>>
>>
>> Mike
>> -Knowing it doesn't really answer the question, but trying to help
>> anyway
>>
>
>