WMI returns empty value

P

Piotr M.

Hi,

I'm looking for advice.

I wrote a simple script, which returns a user name who is log on, it's
working when on remote computer, user with adiministrator privileges is log
on.
But if simple user is log on, result of this script is empty.

I checked user permission in WMI Control Console, user has full access.

How to resolve this problem?

Piotr M.

' Check to see if the computer name or IP address is entered on the command
line
if WScript.Arguments.count < 1 then
' Computer name not enter by command line - get the name or IP
strComputer = InputBox("Enter the computer's name or IP address to check W
h o I s A t")
Call showuser(strcomputer)
Else
For Each strcomputer in wscript.arguments
Call showuser(strcomputer)
Next
end if

Function showuser(strComputer)
' Open a ref to WMI
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputer
' Check to see anybody if logged on
if isnull(objcomputer.username) then
Wscript.Echo "No user is logged onto " & objComputer.name
else
Wscript.Echo "User " & objComputer.UserName & " Is logged onto " &
objComputer.name
End if
Next
End Function
 
T

Torgeir Bakken \(MVP\)

Piotr said:
I'm looking for advice.

I wrote a simple script, which returns a user name who is log on, it's
working when on remote computer, user with adiministrator privileges is log
on.
But if simple user is log on, result of this script is empty.

I checked user permission in WMI Control Console, user has full access.

How to resolve this problem?
Hi

See if obtaining the owner of the explorer.exe process work better:

'--------------------8<----------------------

sUser = ConsoleUser(".") ' use "." for local computer

MsgBox "Console user: " & sUser, _
vbInformation + vbSystemModal, "Get user name"


Function ConsoleUser(sHost)
' Returns name of user logged on to console
' If no users are logged on, returns ""
Dim oWMI, colProc, oProcess, sUser, sDomain
Set oWmi = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(debug)}!\\" _
& sHost & "\root\cimv2")

Set colProc = oWmi.ExecQuery("Select Name from Win32_Process" _
& " Where Name='explorer.exe' and SessionID=0")

ConsoleUser = ""
For Each oProcess In colProc
lRet = oProcess.GetOwner(sUser, sDomain)
If lRet = 0 Then
ConsoleUser = sUser
End If
Next
End Function
'--------------------8<----------------------
 
P

Piotr M.

Torgeir Bakken (MVP) said:
Hi

See if obtaining the owner of the explorer.exe process work better:

'--------------------8<----------------------

sUser = ConsoleUser(".") ' use "." for local computer

MsgBox "Console user: " & sUser, _
vbInformation + vbSystemModal, "Get user name"


Function ConsoleUser(sHost)
' Returns name of user logged on to console
' If no users are logged on, returns ""
Dim oWMI, colProc, oProcess, sUser, sDomain
Set oWmi = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(debug)}!\\" _
& sHost & "\root\cimv2")

Set colProc = oWmi.ExecQuery("Select Name from Win32_Process" _
& " Where Name='explorer.exe' and SessionID=0")

ConsoleUser = ""
For Each oProcess In colProc
lRet = oProcess.GetOwner(sUser, sDomain)
If lRet = 0 Then
ConsoleUser = sUser
End If
Next
End Function
'--------------------8<----------------------



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx

Hi,
Your script working when I check 'launch32.exe' process, not
'explorer.exe'
But I wondering, why my script working only when administrator is logged on
remote computer.
I should change a security permision (for user or system account) somewhere
but ...where?

Piotr M.
 
T

Torgeir Bakken \(MVP\)

Piotr said:
Hi,
Your script working when I check 'launch32.exe' process, not
'explorer.exe'
But I wondering, why my script working only when administrator is logged on
remote computer.
I should change a security permision (for user or system account) somewhere
but ...where?
Hi

Many others have posted about this problem with the UserName property,
but as far as I know, nobody have come up with a solution.
 
Joined
Mar 22, 2007
Messages
1
Reaction score
0
Terminal Service

I ran into the same problem. I also noted that I was unable to list the owner of any processes. On the affected machine, the User Name column under Task Manager Processes was empty. Enabling and starting Terminal Services fixed the problem for me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top