Re: Really slow to get information from Win32_UserAccount
Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance
James Crosswell wrote:
Torgeir Bakken (MVP) wrote:
WMI:
This should get the fullname of current user (local as well as
domain user) pretty effective:
'--------------------8<----------------------
Set objWshNet = CreateObject("WScript.Network")
strComputer = objWshNet.ComputerName
strUserName = objWshNet.UserName
strUserDomain = objWshNet.UserDomain
strQuery = "Select FullName from Win32_UserAccount WHERE Domain = '" _
& strUserDomain & "' AND Name = '" & strUserName & "'"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer &
"\root\cimv2")
Set collUsers = objWMIService.ExecQuery(strQuery,, 48)
For Each objUser in collUsers
strFullName = objUser.FullName
Next
Wscript.Echo strFullName
'--------------------8<----------------------
Hm, currenlty I know the user's login name (e.g. 'MICROFORGE\James'), so
the query I was executing via WMI (which also takes for ever) is
something a long the lines of:
Select FullName FROM Win32_UserAccount
WHERE Caption = 'MICROFORGE\James'
Do you think the code you suggested above would be quicker (maybe the
WMI provider for the Win32_UserAccount class could avoid having to
contact a bunch of directory servers if there was a where clause on the
Domain)?
It might be quicker, but also because I added ",, 48" to the ExecQuery
statement, more about that here:
http://groups.google.co.uk/group/microsoft.public.windowsxp.wmi/msg/9ecfd36c3000002f?hl=en&
The only way to find out really, is to try my script and see what
response time you get.
ADSI/WinNT:
As long as all clients are Win2k or WinXP (I assume they are as you
are originally using WMI to obtain the fullname property), ADSI script
will also do the job (local as well as domain users):
'--------------------8<----------------------
Set objWshNet = CreateObject("WScript.Network")
strUserName = objWshNet.UserName
strUserDomain = objWshNet.UserDomain
Set objUser = GetObject("WinNT://" & strUserDomain _
& "/" & strUserName & ",user")
strFullName = objUser.FullName
Wscript.Echo strFullName
'--------------------8<----------------------
If you mean all the machines that would run the code then no, some of
them could be Windows NT 4.0 or Windows 9x.. but I haven't had any
problems with the FullName property on these machines...
On the other hand, the above script looks promising and as I understand
it, ADSI can be downloaded/installed on Windows NT 4.0 and Windows 9x.
Yes, that is correct, just as the WMI Core is available for NT4 and
Win9x as a separate download.
Just one question: will that "WinNT://DOMAIN/USER_NAME" format work if
the domain controller is a Windows 2003 Server that does NOT have pre
Windows 2000 Compatible access enabled? I'm looking for a fairly generic
solution that I could run in any network environment.
Yes, the "WinNT://DOMAIN/USER_NAME" format will work regardless
of how your domain controllers are configured...
--
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 Timeout on Remote Computer
... >> I am having problems with running WMI query against a few remote Windows ... the script will go on to the next computer? ... I read that the WMI timeout is set really high ... (microsoft.public.scripting.vbscript) - RE: MS03-039 Deploy Script
... Thanks to Diego for sharing the script with us. ... To run WMI-based scripts, we can install Windows ... Management Instrumentation (WMI) CORE 1.5 on these systems: ... |>>helps deploying the patch using WMI: ... (microsoft.public.security) - Re: What is the difference between WSH, VBScript and WMI (and ADSI) ?
... WMI networking methods are only supported on Windows NT-based platforms, ... Network-Related WMI Methods Fail on Windows 95, Windows 98, Windows Me ... Explorer 4.0 or later with WSH and ADSI installed. ... Windows Script Host supports scripts that are written in Visual Basic ... (microsoft.public.windowsxp.help_and_support) - Re: What is the difference between WSH, VBScript and WMI (and ADSI) ?
... WMI networking methods are only supported on Windows NT-based platforms, ... Network-Related WMI Methods Fail on Windows 95, Windows 98, Windows Me ... Explorer 4.0 or later with WSH and ADSI installed. ... Windows Script Host supports scripts that are written in Visual Basic ... (microsoft.public.windowsxp.general) - Re: What is the difference between WSH, VBScript and WMI (and ADSI) ?
... WMI networking methods are only supported on Windows NT-based platforms, ... Network-Related WMI Methods Fail on Windows 95, Windows 98, Windows Me ... Explorer 4.0 or later with WSH and ADSI installed. ... Windows Script Host supports scripts that are written in Visual Basic ... (microsoft.public.windowsxp.help_and_support) |
|