Re: Windows 2003 and WMI question

Tech-Archive recommends: Fix windows errors by optimizing your registry

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


Date: Wed, 14 Jul 2004 21:50:08 +0200

Peter Nguyen wrote:

> Hello All,
>
> I have a script that utilize wmi to get the local Administrators group name
> in different OS languages (Administrators group names differently in
> different language).
> The script works fine with Windows 2000/XP. However, the WMI call failed
> without a trace when running on Windows 2003 box (english, german, sweden,
> neitherland so far...).
>
> Does Windows 2003 make WMI calls different than 2K/XP? Any help would be
> greatly appreciated.
Hi

You script works fine on my Windows 2003 Server (not joined to
a domain).

Note that on domain computers your current script will enumerate all
domain group accounts as well as the local groups, and this will make
the script slow if there is many groups in the domain. Below is a
script that access only the local groups (and it might work better
on your Win2k3 Servers as well :-)

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

WScript.Echo GetAdministratorsGroupName

Function GetAdministratorsGroupName

   Dim oWshNetwork, oGroupAccounts, oGroupAccount, sComputer, sGroupSID

   Set oWshNetwork = CreateObject("WScript.Network")
   sComputer = oWshNetwork.ComputerName

   ' Well Known SID of the local Administrators group
   sGroupSID = "S-1-5-32-544"

   Set oGroupAccounts = GetObject( _
        "winmgmts://" & sComputer & "/root/cimv2") _
        .ExecQuery("Select Name from Win32_Group" _
      & " WHERE Domain = '" & sComputer & "' AND SID = '" & sGroupSID & "'")

   If oGroupAccounts.Count = 0 Then
     ' need to use Domain = 'BUILTIN' at least for Win2k SP2
     Set oGroupAccounts = GetObject( _
          "winmgmts://" & sComputer & "/root/cimv2") _
          .ExecQuery("Select Name from Win32_Group" _
        & " WHERE Domain = 'BUILTIN' AND SID = '" & sGroupSID & "'")
   End If

   For Each oGroupAccount In oGroupAccounts
     GetAdministratorsGroupName = oGroupAccount.Name
   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/community/scriptcenter/default.mspx


Relevant Pages

  • Re: Use the "Managed By" field in AD to set as local Admin
    ... I think the way must be in the logon script. ... Administrators group, you can run it repeatedly until there is no message ... "Domain Admins" should be a member of the local Administrators group on ... Dim strComputerDN, strComputer, strManagerDN ...
    (microsoft.public.windows.server.active_directory)
  • Re: Use the "Managed By" field in AD to set as local Admin
    ... I think the way must be in the logon script. ... Administrators group, you can run it repeatedly until there is no message ... "Domain Admins" should be a member of the local Administrators group on ... Dim strComputerDN, strComputer, strManagerDN ...
    (microsoft.public.windows.server.active_directory)
  • Re: Finding users in local admin groups
    ... > Here is a vbscript that you can run against a remote computer that moves ... > *local* users except 'Administrator) from the Administrators group to the ... You should also add to the script logging to a file of the ... > you moved on what computers. ...
    (microsoft.public.win2000.security)
  • Re: how to schedule a job or run a script with elevated privleges?
    ... schedule a job or run a script ... the local Administrators group when the computer is joined to the domain). ... You could create a script to run remotely on all computers in an OU (or in a ... group or all computers in the domain) in bulk using WMI. ...
    (microsoft.public.scripting.vbscript)
  • Wired error of get-credential for non-privilege user
    ... If login as a member of Administrators group, ... Second time you run script: ...
    (microsoft.public.windows.server.scripting)