Re: Using WMI to correctly identify the current user on a remote syste

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 10/07/04


Date: Thu, 07 Oct 2004 12:34:38 +0200

DCC wrote:

> I'm working on a status script for deployment in our W2kSP4 and WXPSP1
> environment. The script runs on an app server and does the following:
>
> - query active directory for all machines in a particular OU
> - iterate through the collection and obtain the required information
> - write the information to a SQL database
>
> I'm using WMI to retreive the OS, RAM, uptime and last reboot for each
> system without any trouble. However, when I try to determine if a user is
> logged into the remote system I receive faulty data (but no errors). Here's
> a stand-alone vbs code sample (from MS) that exibits the strange behavior:
>
> -------------------------------------------------------
> strComputer = "RemoteComputer"
> Set objWMIService = GetObject("winmmgts:" _
> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
> Set colComputer = objWMIService.ExecQuery _
> ("Select * from Win32_ComputerSystem")
>
> For Each objComputer in colComputer
> Wscript.Echo objComputer.UserName
> Next
> ------------------------------------------------------
>
> The code is being executed on a system that is part of the domain and in the
> context of a user who has local admin rights on all the target systems.
>
> This code returns the proper domain and user information *only* if the user
> logged into the remote system is an administrator. If the user is not an
> administrator, the code returns "null" (as if no user were logged in).
Hi

This has been up in the newsgroups many times, it looks like this
is a (undocumented) limitation (or maybe bug) in WMI.

One think I just though of, take the debug privilege and see it
that helps, like this:

Set objWMIService = GetObject("winmgmts:" _
     & "{impersonationLevel=impersonate,(debug)}!\\" _
     & strComputer & "\root\cimv2")

-- 
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


Relevant Pages

  • Re: WMI Reference
    ... You will be writing a complex custom application / script for that. ... A good way to get used to what Wmi is and the way it works is to use ... be detected by Sms, etc. ... Scriptomatic tool from the scripting tech center. ...
    (microsoft.public.sms.admin)
  • Re: 2 questions: uptime and last logged on users
    ... > For your computer uptime question: ... > ' Converts WMI Date and Time Format to standard date/time ... > torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.win32.programmer.wmi)
  • Re: security center
    ... but you can query the PC's via WMI (Windows Management Instrumentation) scripting. ... The below script is for the local computer, and would need to be modified to determine all PC's on your network/domain and then query each computer individually and report when there is a problem. ...
    (microsoft.public.windowsxp.security_admin)
  • Re: Copying and running processes on remote machines
    ... WMI Scripting Primer: Part 1 ... Managing Windows Registry with Scripting ...
    (microsoft.public.win32.programmer.wmi)
  • Re: Online Test
    ... Using ping seem to be a rather crude way. ... > Almost any method for communicating with a remote computer is going to have ... > WMI script to determine that a system is not there. ... torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway ...
    (microsoft.public.scripting.vbscript)