Re: Problem with WMI.

From: Roland Hall (nobody_at_nowhere)
Date: 06/04/04


Date: Fri, 4 Jun 2004 05:22:02 -0500


"Gaurav" <gaurav081@yahoo.co.in> wrote in message
news:36c62b36.0406030605.915c0d3@posting.google.com...
: I am running a script to get the logged on user on a remote machine
: but its not working.
:
: I'm sitting on a Domain Controller logged on as administrator of the
: domain and running the script.The script runs fine when domain
: administrator is logged on to remote machine. But if a normal user is
: logged on it gives nothin as output.
: Pls tell me what is the reason behind it and how to solve it.
: Thanks in advance
: Gaurav
:
: Here goes my script......
:
: Set objWMIService = GetObject("winmgmts:" _
: & "{impersonationLevel=impersonate}!\\" & strServer &
: "\root\cimv2")
: Set colComputer = objWMIService.ExecQuery _
: ("Select * from Win32_ComputerSystem")
:
: For Each objComputer in colComputer
: a = objComputer.UserName
: wscript.echo a
: Next

Perhaps this will work but I get a null return. I've seen umpteen posts
regarding this and this is what they say to do. Change sUser and sPass to
an administrative account on the remote computer. I'm passing the
computername as an argument. Just use computername, not \\computername.

Option Explicit
dim strComputer, oConn, colComputer, oComputer, oLocator, sUser, sPass
sUser = "domain\username"
sPass = "password"
dim oArgs
set oArgs = wscript.arguments
if oArgs.length > 0 then
  strComputer = oArgs(0)
  set oLocator = CreateObject("WbemScripting.SWbemLocator")
  set oConn = oLocator.ConnectServer(strComputer, "root\cimv2", sUser,
sPass)
  oConn.Security_.ImpersonationLevel = 3

  set colComputer = oConn.ExecQuery ("Select * from Win32_ComputerSystem")
  For Each oComputer in colComputer
    Wscript.Echo oComputer.UserName
  Next
else
  wscript.echo "Error" & vbCrLf & _
  "Syntax: getuser computername"
end if
set oArgs = nothing
set oLocator = nothing
set oConn = nothing
set colComputer = nothing

HTH...

-- 
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp


Relevant Pages

  • Re: yet another question on file names with spaces?
    ... > I agree, the echo is redudant. ... > know what they are before the script runs - see below. ... > finding whether they are also on the remote machine. ... > images and pdfs which I only want to transfer once. ...
    (comp.unix.shell)
  • Re: match machine name to user name
    ... > dim strComputer, oConn, colComputer, oComputer, oLocator, sUser, sPass ... > set oArgs = wscript.arguments ... I will be running the script from my machine. ... so I guess I am used to reading 'bottom up'. ...
    (microsoft.public.scripting.vbscript)
  • Re: Remove programs with a script?
    ... While I execute this I get error: ... The script passed to CreateScript must be a WSH hosted script ... The remote machine needs to have WshRemote enabled: ... WshRemote instances do not run in the context of the visible, ...
    (microsoft.public.scripting.wsh)
  • Re: Remove programs with a script?
    ... While I execute this I get error: ... The script passed to CreateScript must be a WSH hosted script ... The remote machine needs to have WshRemote enabled: ... WshRemote instances should never attempt to produce any visible ...
    (microsoft.public.scripting.wsh)
  • Re: How to redirect output of shell command using WMI
    ... But this the script given will not work for me, ... I cannot use shares like "d$" for the remote machine. ... Also one more point I would mention here is that, when I run the command ... Note that this is how NTFS security works: ...
    (microsoft.public.windows.server.scripting)