Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WinNT error message

297 views
Skip to first unread message

kane9522

unread,
Sep 16, 2009, 12:41:01 AM9/16/09
to
Hi All, I am having some trouble with a script I am trying to write, I am
getting this error message:

Error: The Group name could not be found
Code: 800708AC
Source: (null)

what I am trying to do is determine whether a computer account in AD is part
of global group, I have code to do the same thing with user accounts, and the
user accounts code is working...the code for checking the computer is just a
copy of the user checking code...I have tested the user code and know that it
works, so one would assume that the computer checking code would also
work...any help would be appreciated...

Dim WshShell, WshEnv, objFSO, WshNetwork, objGroupListUser,
objGroupListComputer, objUserMemberOf, objGroupUser, objComputerMemberOf,
objGroupComputer
Dim objSysInfoUser, objSysInfoComputer, objDomain, objCurrentUser, UserObj,
objCurrentComputer, ComputerObj, objUser, objComputer
Dim DomainString, UserString, ComputerString, strUser, strComputer

Const OverwriteExisting = True

'On Error Resume Next

'Configures Variables
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = WScript.CreateObject("WScript.Shell")
Set WshEnv = WshShell.Environment("Process")
Set WshNetwork = CreateObject("WScript.Network")

Set objSysInfoUser = CreateObject("ADSystemInfo")
Set objSysInfoComputer = CreateObject("ADSystemInfo")
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")

'Get user name
UserString = WshNetwork.UserName
Set objCurrentUser = GetObject("LDAP://" & objSysInfoUser.UserName)
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
strUser = objSysInfoUser.UserName
Set objUser = GetObject("LDAP://" & strUser)

'Get Computer name
ComputerString = WshNetwork.ComputerName
Set objCurrentComputer = GetObject("LDAP://" &
objSysInfoComputer.ComputerName)

'This is the line that causes the error
Set ComputerObj = GetObject("WinNT://" & DomainString & "/" & ComputerString)

'Set ComputerObj = GetObject("WinNT://" & ComputerString)
strComputer = objSysInfoComputer.ComputerName
Set objComputer = GetObject("LDAP://" & strComputer)

objUserMemberOf = objUser.GetEx("memberOf")
For Each objGroupUser in objUserMemberOf
strListUser = strListUser & objGroupUser & vbcr
Next

'errors if computer has no groups...
'objComputerMemberOf = objComputer.GetEx("memberOf")
'For Each objGroupComputer in objComputerMemberOf
' strListComputer = strListComputer & objGroupComputer & vbcr
'Next

strFullName = objUser.FullName
strFirstName = objUser.FirstName

wscript.echo "Domain: " & DomainString
wscript.echo "Computer Network: " & ComputerString
wscript.echo "Computer ADInfo: " & strComputer
'wscript.echo "Full Name " & strFullName
'wscript.echo "First Name " & strFirstName
'wscript.echo "strUser " & strUser
'wscript.echo "Username " & UserString
WScript.Echo "Groups for " & strUser & vbCr & strListUser
wscript.echo "Groups for " & strComputer & vbCr & strListComputer


strGroupUser = "2003GG_NoPrintersConfig"
If (IsMemberUser(strGroupUser) = True) Then
Wscript.Echo "User " & objUser.name & " is a member of group " &
strGroupUser
ElseIf (IsMemberUser(strGroupUser) = False) Then
Wscript.Echo "User " & objUser.name & " is NOT a member of group " &
strGroupUser
End If

strGroupComputer = "2003GG_NoPrintersConfig"
If (IsMemberComputer(strGroupComputer) = True) Then
wscript.echo "Computer " & objComputer.name & " is a member of group " &
strGroupComputer
ElseIf (IsMemberComputer(strGroupComputer) = False) Then
wscript.echo "Computer " & objComputer.name & " is not a member of group "
& strGroupComputer
End If

Function IsMemberUser(ByVal strGroupUser)

' Function to test for group membership.
' strGroup is the NT name (sAMAccountName) of the group to test.
' objGroupList is a dictionary object, with global scope.
' Returns True if the user or computer is a member of the group.

If (IsEmpty(objGroupListUser) = True) Then
Set objGroupListUser = CreateObject("Scripting.Dictionary")
Call LoadGroupsUser(objUser)
End If

IsMemberUser = objGroupListUser.Exists(strGroupUser)

End Function

Function IsMemberComputer(ByVal strGroupComputer)

' Function to test for group membership.
' strGroup is the NT name (sAMAccountName) of the group to test.
' objGroupList is a dictionary object, with global scope.
' Returns True if the user or computer is a member of the group.

If (IsEmpty(objGroupListComputer) = True) Then
Set objGroupListComputer = CreateObject("Scripting.Dictionary")
Call LoadGroupsComputer(objComputer)
End If

IsMemberComptuer = objGroupListComputer.Exists(strGroupComputer)

End Function

Sub LoadGroupsUser(ByVal objUser)

' Recursive subroutine to populate dictionary object with group
' memberships. When this subroutine is first called by Function
' IsMember, objADObject is the user or computer object. On recursive calls
' objADObject will be a group object. For each group in the MemberOf
' collection, first check to see if the group is already in the
' dictionary object. If it is not, add the group to the dictionary
' object and recursively call this subroutine again to enumerate any
' groups the group might be a member of (nested groups). It is necessary
' to first check if the group is already in the dictionary object to
' prevent an infinite loop if the group nesting is "circular".

Dim colstrGroups, objGroup, j

objGroupListUser.CompareMode = vbTextCompare

colstrGroups = objUser.memberOf

If (IsEmpty(colstrGroups) = True) Then
Exit Sub
End If

If (TypeName(colstrGroups) = "String") Then

' Escape any forward slash characters, "/", with the backslash
' escape character. All other characters that should be escaped are.

colstrGroups = Replace(colstrGroups, "/", "\/")

Set objGroup = GetObject("LDAP://" & colstrGroups)

If (objGroupListUser.Exists(objGroup.sAMAccountName) = False) Then
objGroupListUser.Add objGroup.sAMAccountName, True
Call LoadGroupsUser(objGroup)
End If

Set objGroup = Nothing

Exit Sub

End If

For j = 0 To UBound(colstrGroups)

' Escape any forward slash characters, "/", with the backslash
' escape character. All other characters that should be escaped are.

colstrGroups(j) = Replace(colstrGroups(j), "/", "\/")

Set objGroup = GetObject("LDAP://" & colstrGroups(j))

If (objGroupListUser.Exists(objGroup.sAMAccountName) = False) Then
objGroupListUser.Add objGroup.sAMAccountName, True
Call LoadGroupsUser(objGroup)
End If

Next

Set objGroup = Nothing

End Sub

Sub LoadGroupsComputer(ByVal objComputer)

' Recursive subroutine to populate dictionary object with group
' memberships. When this subroutine is first called by Function
' IsMember, objADObject is the user or computer object. On recursive calls
' objADObject will be a group object. For each group in the MemberOf
' collection, first check to see if the group is already in the
' dictionary object. If it is not, add the group to the dictionary
' object and recursively call this subroutine again to enumerate any
' groups the group might be a member of (nested groups). It is necessary
' to first check if the group is already in the dictionary object to
' prevent an infinite loop if the group nesting is "circular".

Dim colstrGroups, objGroup, j

objGroupListComputer.CompareMode = vbTextCompare

colstrGroups = objComputer.memberOf

If (IsEmpty(colstrGroups) = True) Then
Exit Sub
End If

If (TypeName(colstrGroups) = "String") Then

' Escape any forward slash characters, "/", with the backslash
' escape character. All other characters that should be escaped are.

colstrGroups = Replace(colstrGroups, "/", "\/")

Set objGroup = GetObject("LDAP://" & colstrGroups)

If (objGroupListComputer.Exists(objGroup.sAMAccountName) = False) Then
objGroupListComputer.Add objGroup.sAMAccountName, True
Call LoadGroupsComputer(objGroup)
End If

Set objGroup = Nothing

Exit Sub

End If

For j = 0 To UBound(colstrGroups)

' Escape any forward slash characters, "/", with the backslash
' escape character. All other characters that should be escaped are.

colstrGroups(j) = Replace(colstrGroups(j), "/", "\/")

Set objGroup = GetObject("LDAP://" & colstrGroups(j))

If (objGroupListComputer.Exists(objGroup.sAMAccountName) = False) Then
objGroupListComputer.Add objGroup.sAMAccountName, True
Call LoadGroupsComputer(objGroup)
End If

Next

Set objGroup = Nothing

End Sub

Richard Mueller [MVP]

unread,
Sep 16, 2009, 10:51:38 AM9/16/09
to
First, there is probably no reason to use the WinNT provider. It is slower
and reveals fewer attributes. If you do use it, use wshNetwork.UserDomain to
retrieve the NetBIOS name of the domain. The value of RootDSE.dnsHostName
will be similar to:

MyComputer.MyDomain.com

where MyComputer is a Domain Controller.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"kane9522" <kane...@discussions.microsoft.com> wrote in message
news:45E24808-D861-44D9...@microsoft.com...

kane9522

unread,
Sep 16, 2009, 7:09:01 PM9/16/09
to
Hi Richard,
using that WshNetwork.UserDomain has fixed the error
message but is still not showing that the computer account is part of a
particular group...I can check AD and see that the computer account
definitely has the group I need to check it for, in this case
2003GG_NoPrintersConfig, the check works correctly for the user account...any
ideas??

Richard Mueller [MVP]

unread,
Sep 17, 2009, 12:38:02 PM9/17/09
to
The following should fix most problems:

1. Replace all instances of vbCr with vbCrLf. With vbCr only the last line
shows up, as each line overwrites the previous.
2. Replace objUser.FullName with objUser.displayName. FullName is not
exposed by the LDAP provider.
3. Replace objUser.FirstName with objUser.givenName. FirstName is not
exposed by the LDAP provider.
4. As noted before, replace


Set ComputerObj = GetObject("WinNT://" & DomainString & "/" &
ComputerString)

with
Set ComputerObj = GetObject("WinNT://" & WshNetwork.UserDomain & "/" &
ComputerString)
5. IsMemberComptuer is mis-spelled in IsMemberComputer.

I added the following lines at the start when I tested the script:

Option Explicit
Dim strListUser, strFullName, strFirstName, strListComputer
Dim strGoupUser, strGroupComputer

This caught the mis-spelling. The program ran to completion for me.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"kane9522" <kane...@discussions.microsoft.com> wrote in message

news:D3FE443A-BFD9-4F81...@microsoft.com...

0 new messages