Re: Problem with WMI.
From: Roland Hall (nobody_at_nowhere)
Date: 06/04/04
- Next message: Dan: "RE: Is there anyone who can help me out"
- Previous message: Patrick Long: "Re: Reading and Writing binary data with a TextStream"
- In reply to: Gaurav: "Problem with WMI."
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Dan: "RE: Is there anyone who can help me out"
- Previous message: Patrick Long: "Re: Reading and Writing binary data with a TextStream"
- In reply to: Gaurav: "Problem with WMI."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|