Re: Windows 2003 and WMI question
From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 07/14/04
- Next message: Shadrach: "Delete unwanted subfolders"
- Previous message: Torgeir Bakken \(MVP\): "Re: collecting more than 24 hours in seconds and converting it to hh:mm:ss"
- In reply to: Peter Nguyen: "Windows 2003 and WMI question"
- Next in thread: Peter Nguyen: "Re: Windows 2003 and WMI question"
- Reply: Peter Nguyen: "Re: Windows 2003 and WMI question"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Shadrach: "Delete unwanted subfolders"
- Previous message: Torgeir Bakken \(MVP\): "Re: collecting more than 24 hours in seconds and converting it to hh:mm:ss"
- In reply to: Peter Nguyen: "Windows 2003 and WMI question"
- Next in thread: Peter Nguyen: "Re: Windows 2003 and WMI question"
- Reply: Peter Nguyen: "Re: Windows 2003 and WMI question"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|