Home All Groups Group Topic Archive Search About


Author
10 Apr 2007 6:36 PM
Sriman
Hi,

  Due to unavailbility of .net framework in our production servers(no
permission to install the .net framework). i am planning to convert my .net
code to vbscript.
   Any one can give the equilent vbscript of the following .net code.

DirectoryEntry groupEntry = new DirectoryEntry("LDAP://" + strDomainName);
                        System.DirectoryServices.DirectorySearcher tsds =
new System.DirectoryServices.DirectorySearcher(groupEntry);
                        tsds.Filter =
"(&(|(objectClass=user)(objectclass=group))(samAccountName=" +
strGroupName))";
                        tsds.SearchScope = SearchScope.Subtree;
                        SearchResult src1;
                        src1 = tsds.FindOne();

Regards,
Sri

Author
11 Apr 2007 1:18 AM
Richard Mueller [MVP]
Sri wrote:

Show quote
>  Due to unavailbility of .net framework in our production servers(no
> permission to install the .net framework). i am planning to convert my
> .net
> code to vbscript.
>   Any one can give the equilent vbscript of the following .net code.
>
> DirectoryEntry groupEntry = new DirectoryEntry("LDAP://" + strDomainName);
>                        System.DirectoryServices.DirectorySearcher tsds =
> new System.DirectoryServices.DirectorySearcher(groupEntry);
>                        tsds.Filter =
> "(&(|(objectClass=user)(objectclass=group))(samAccountName=" +
> strGroupName))";
>                        tsds.SearchScope = SearchScope.Subtree;
>                        SearchResult src1;
>                        src1 = tsds.FindOne();
>

ADO can be used to search AD in VBScript. See this link:

http://www.rlmueller.net/ADOSearchTips.htm

Note that sAMAccountName must be unique in the domain. If a value is used by
a user, it cannot be used by a group. You can use the filter:

"(sAMAccountName=" & strGroupName &")"

For example:
================
Option Explicit

Dim adoCommand, adoConnection, strBase, strFilter, strAttributes

Dim strQuery, adoRecordset, strDN, strGroupName



' Setup ADO objects.

Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection



' Search entire Active Directory domain.
strBase = "<LDAP://dc=MyDomain,dc=com>"



' Specify sAMAccountName.

strGroupName = "TestGroup"


' Filter on objects with given name.
strFilter = "(sAMAccountName=" & strGroupName & ")"



' Comma delimited list of attribute values to retrieve.
strAttributes = "distinguishedName"



' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False



' Run the query.
Set adoRecordset = adoCommand.Execute


' Enumerate the resulting recordset.
Do Until adoRecordset.EOF

    ' Retrieve values and display.
    strDN = adoRecordset.Fields("distinguishdName").Value

    Wscript.Echo strDN

    ' Move to the next record in the recordset.
    adoRecordset.MoveNext
Loop



' Clean up.

adoRecordset.Close

adoConnection.Close


--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
Author
11 Apr 2007 1:34 PM
Sriman
Hi Mueller,

   Thanks for your reply.
I have question. Is there any method which will print the out put(other than
into file) other than Wscript.Echo ..like write, print etc., My requirement
is to display the status of the group and down to the user details to the
admin and write those details to file. using filesystem we can write into
file.But how to display the details?

Regards,
Sri

Show quote
"Richard Mueller [MVP]" wrote:

> Sri wrote:
>
> >  Due to unavailbility of .net framework in our production servers(no
> > permission to install the .net framework). i am planning to convert my
> > .net
> > code to vbscript.
> >   Any one can give the equilent vbscript of the following .net code.
> >
> > DirectoryEntry groupEntry = new DirectoryEntry("LDAP://" + strDomainName);
> >                        System.DirectoryServices.DirectorySearcher tsds =
> > new System.DirectoryServices.DirectorySearcher(groupEntry);
> >                        tsds.Filter =
> > "(&(|(objectClass=user)(objectclass=group))(samAccountName=" +
> > strGroupName))";
> >                        tsds.SearchScope = SearchScope.Subtree;
> >                        SearchResult src1;
> >                        src1 = tsds.FindOne();
> >
>
> ADO can be used to search AD in VBScript. See this link:
>
> http://www.rlmueller.net/ADOSearchTips.htm
>
> Note that sAMAccountName must be unique in the domain. If a value is used by
> a user, it cannot be used by a group. You can use the filter:
>
> "(sAMAccountName=" & strGroupName &")"
>
> For example:
> ================
> Option Explicit
>
> Dim adoCommand, adoConnection, strBase, strFilter, strAttributes
>
> Dim strQuery, adoRecordset, strDN, strGroupName
>
>
>
> ' Setup ADO objects.
>
> Set adoCommand = CreateObject("ADODB.Command")
> Set adoConnection = CreateObject("ADODB.Connection")
> adoConnection.Provider = "ADsDSOObject"
> adoConnection.Open "Active Directory Provider"
> adoCommand.ActiveConnection = adoConnection
>
>
>
> ' Search entire Active Directory domain.
> strBase = "<LDAP://dc=MyDomain,dc=com>"
>
>
>
> ' Specify sAMAccountName.
>
> strGroupName = "TestGroup"
>
>
> ' Filter on objects with given name.
> strFilter = "(sAMAccountName=" & strGroupName & ")"
>
>
>
> ' Comma delimited list of attribute values to retrieve.
> strAttributes = "distinguishedName"
>
>
>
> ' Construct the LDAP syntax query.
> strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
> adoCommand.CommandText = strQuery
> adoCommand.Properties("Page Size") = 100
> adoCommand.Properties("Timeout") = 30
> adoCommand.Properties("Cache Results") = False
>
>
>
> ' Run the query.
> Set adoRecordset = adoCommand.Execute
>
>
> ' Enumerate the resulting recordset.
> Do Until adoRecordset.EOF
>
>     ' Retrieve values and display.
>     strDN = adoRecordset.Fields("distinguishdName").Value
>
>     Wscript.Echo strDN
>
>     ' Move to the next record in the recordset.
>     adoRecordset.MoveNext
> Loop
>
>
>
> ' Clean up.
>
> adoRecordset.Close
>
> adoConnection.Close
>
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>
Author
11 Apr 2007 3:51 PM
Richard Mueller [MVP]
Show quote
"Sriman" <Sri***@discussions.microsoft.com> wrote in message
news:8B3A9920-4D17-41FE-8069-8F3224F6F169@microsoft.com...
> Hi Mueller,
>
>   Thanks for your reply.
> I have question. Is there any method which will print the out put(other
> than
> into file) other than Wscript.Echo ..like write, print etc., My
> requirement
> is to display the status of the group and down to the user details to the
> admin and write those details to file. using filesystem we can write into
> file.But how to display the details?
>
> Regards,
> Sri

I don't know of any way to print from a VBScript program. I generally use
Wscript.Echo commands to echo information to the console. I can redirect the
output to a text file, using the ">" redirection character. You can also use
the FileSystemObject to write information to a text file.

You can also use the MsgBox function to display information to users.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
Author
11 Apr 2007 4:16 PM
Sriman
Yes, If i use the Wscript.Echo its giving alert with ok button. I am looking
for the code which will displays the output to the console.

Show quote
"Richard Mueller [MVP]" wrote:

>
> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
> news:8B3A9920-4D17-41FE-8069-8F3224F6F169@microsoft.com...
> > Hi Mueller,
> >
> >   Thanks for your reply.
> > I have question. Is there any method which will print the out put(other
> > than
> > into file) other than Wscript.Echo ..like write, print etc., My
> > requirement
> > is to display the status of the group and down to the user details to the
> > admin and write those details to file. using filesystem we can write into
> > file.But how to display the details?
> >
> > Regards,
> > Sri
>
> I don't know of any way to print from a VBScript program. I generally use
> Wscript.Echo commands to echo information to the console. I can redirect the
> output to a text file, using the ">" redirection character. You can also use
> the FileSystemObject to write information to a text file.
>
> You can also use the MsgBox function to display information to users.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>
Author
12 Apr 2007 12:34 AM
Richard Mueller [MVP]
If you run the script with the wscript host, Wscript.Echo commands result in
a message box with an OK button. However, if you use the cscript host,
Wscript.Echo echos to the console. If the VBScript program is called
Example.vbs, you can use a command similar to below at a command prompt:

cscript Example.vbs

I often use the //nologo optional parameter to suppress the WSH logo
information, especially if I want to redirect the output to a text file. For
example:

cscript //nologo Example.vbs > output.txt

The above assumes you are in the directory where the file Example.vbs is
saved. Otherwise, you have to specify the full path and file name in the
command.

I see that on most systems the default host is wscript, so if you just run
the vbs file, wscript.exe is used and the Wscript.Echo statements result in
message boxes. This may be what you experience. For example, that most
likely happens if you enter:

example.vbs
or
example

The default host can be changed to cscript. My reference gives the following
command to set the default to cscript:

cscript //H:cscript //S

The //S option saves this setting for the user. The command:

cscript //I //nologo //H:cscript //S

saves 3 options for the particular user (on this computer), the //I option
specifies interactive mode (which I think is the default anywayt), //nologo
suppresses the WSH logo information, //H:cscript assigns cscript.exe as the
default host, and //S saves the settings for the user.

I don't alter the settings, since I've gotten into the habit of always using
cscript. When I tried a VBScript program just now with no host specified, I
saw how annoying the default wscript.exe can be.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

Show quote
"Sriman" <Sri***@discussions.microsoft.com> wrote in message
news:379C3080-99DB-43AC-B8F7-955A878BE47C@microsoft.com...
> Yes, If i use the Wscript.Echo its giving alert with ok button. I am
> looking
> for the code which will displays the output to the console.
>
> "Richard Mueller [MVP]" wrote:
>
>>
>> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
>> news:8B3A9920-4D17-41FE-8069-8F3224F6F169@microsoft.com...
>> > Hi Mueller,
>> >
>> >   Thanks for your reply.
>> > I have question. Is there any method which will print the out put(other
>> > than
>> > into file) other than Wscript.Echo ..like write, print etc., My
>> > requirement
>> > is to display the status of the group and down to the user details to
>> > the
>> > admin and write those details to file. using filesystem we can write
>> > into
>> > file.But how to display the details?
>> >
>> > Regards,
>> > Sri
>>
>> I don't know of any way to print from a VBScript program. I generally use
>> Wscript.Echo commands to echo information to the console. I can redirect
>> the
>> output to a text file, using the ">" redirection character. You can also
>> use
>> the FileSystemObject to write information to a text file.
>>
>> You can also use the MsgBox function to display information to users.
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>>
>>
Author
12 Apr 2007 1:56 PM
Sriman
Thank you mueller. cscript worked fine to me.
Below is my code. my requirement is to display the members in the group
down to the user. input(domain\grpname) comes from the xml file. In .net i am
able to retrieve the user list down to the user. but here in vbscript i am
able to list down the users of few groups in my domain. it will not allow me
to access the other domain users. I don't know the reason. no error is
coming. Please check my code and  suggest me the best way.

Option Explicit

Dim adoCommand, adoConnection, strBase, strFilter, strAttributes, xmlDoc, x,
WshNetwork, strComputer
Dim strDomainName, strNodeText, strXmlBuilder
Dim fso, res

Dim strQuery, adoRecordset, strDN, strGroupName

' Setup ADO objects.

Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

Set WshNetwork = WScript.CreateObject("WScript.Network")
strComputer = UCase(WshNetwork.ComputerName)

'Set fso = CreateObject("Scripting.FileSystemObject")
'Set res = fso.CreateTextFile(strComputer & ".xml", True)
'strXmlBuilder = strXmlBuilder & "<?xml version=\"1.0\" standalone=\"yes\"?>"
'strXmlBuilder =    strXmlBuilder & "\n"  + "<WINNTGrps>"

'res.WriteLine "setmachine= & SerialNumber
'res.Close


set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("groupstoberesolved.xml")

for each x in xmlDoc.documentElement.childNodes

  strNodeText = replace(x.text,"\","/")

  if x.nodename <> "#comment" then
  Wscript.Echo "Node Name:" & x.nodename & vbcrlf & "Node Text:" &
strNodeText & vbcrlf & "Domain Name:" & _
   mid(x.text,1, InStr(strNodeText,"/")-1)  _
            & vbcrlf & "GroupName:" & mid(x.text,InStr(strNodeText,"/") + 1,
len(strNodeText))

strDomainName = mid(x.text,1, InStr(strNodeText,"/")-1)           
strGroupName = mid(x.text,InStr(strNodeText,"/") + 1, len(strNodeText))

strBase = "<LDAP://" & strDomainName & ">"

strFilter = "(&(|(objectClass=user)(objectclass=group))" &
"(sAMAccountName=" & strGroupName & "))"
strAttributes = "distinguishedName"

' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
'Wscript.Echo strQuery
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False

' Run the query.
Set adoRecordset = adoCommand.Execute


' Enumerate the resulting recordset.
Do Until adoRecordset.EOF

    ' Retrieve values and display.
    strDN = adoRecordset.Fields("distinguishedName").Value

    enumMembers getGroup(strDN,strGroupName),  ""
    adoRecordset.MoveNext
Loop
end if
next

' Clean up.

adoRecordset.Close
adoConnection.Close


Function getGroup(strQueryFrom,strGroupName)
  Dim objConn, objRecSet, strQueryString
  Const adsOpenStatic = 3

   Set objConn = wscript.CreateObject("ADODB.Connection")
   objConn.Provider = "ADsDSOObject"
   objConn.Open
wscript.echo strQueryFrom
   strQueryString = "SELECT * FROM 'LDAP://" & strQueryFrom & "' "  & "
WHERE samAccountName =  '" & strGroupName & "'"

   Set objRecSet = wscript.CreateObject("ADODB.Recordset")

   objRecSet.Open strQueryString, objConn, adsOpenStatic

    If objRecSet.recordCount = 1 Then
    dim objFlds
      for each objFlds In objRecSet.Fields
        ' wscript.echo objFlds.Name
      next
      Set getGroup = GetObject(objRecSet("AdsPath"))

    Else
      wscript.echo "Record Cnt: " & objRecSet.recordCount & vbcrlf & "Query:
" & strQueryString ' ucase(strGroupName) & " was not found in the domain. ("
& objRootDSE.get("defaultNamingContext") & ")"
      wscript.quit
    End If
End Function


Sub enumMembers(byRef objGroup, strInheritedFrom)
Dim objMember

   For Each objMember In objGroup.Members
     If lcase(objMember.class) = "group" Then
     enumMembers objMember, objMember.samAccountName
   Else
     If objMember.displayname <> "" Then
       If strInheritedFrom = "" Then
         wscript.echo objMember.displayname
       Else
         wscript.echo objMember.displayname & " (From NESTED GROUP:  " &
strInheritedFrom & ")"
      End If
    Else
       If strInheritedFrom = "" Then
        wscript.echo objMember.samAccountName
     Else
       wscript.echo objMember.samAccountName & " (From NESTED GROUP:  " &
strInheritedFrom & ")"
     End If
   End If
End If

Next
End Sub

Show quote
"Richard Mueller [MVP]" wrote:

> If you run the script with the wscript host, Wscript.Echo commands result in
> a message box with an OK button. However, if you use the cscript host,
> Wscript.Echo echos to the console. If the VBScript program is called
> Example.vbs, you can use a command similar to below at a command prompt:
>
> cscript Example.vbs
>
> I often use the //nologo optional parameter to suppress the WSH logo
> information, especially if I want to redirect the output to a text file. For
> example:
>
> cscript //nologo Example.vbs > output.txt
>
> The above assumes you are in the directory where the file Example.vbs is
> saved. Otherwise, you have to specify the full path and file name in the
> command.
>
> I see that on most systems the default host is wscript, so if you just run
> the vbs file, wscript.exe is used and the Wscript.Echo statements result in
> message boxes. This may be what you experience. For example, that most
> likely happens if you enter:
>
> example.vbs
> or
> example
>
> The default host can be changed to cscript. My reference gives the following
> command to set the default to cscript:
>
> cscript //H:cscript //S
>
> The //S option saves this setting for the user. The command:
>
> cscript //I //nologo //H:cscript //S
>
> saves 3 options for the particular user (on this computer), the //I option
> specifies interactive mode (which I think is the default anywayt), //nologo
> suppresses the WSH logo information, //H:cscript assigns cscript.exe as the
> default host, and //S saves the settings for the user.
>
> I don't alter the settings, since I've gotten into the habit of always using
> cscript. When I tried a VBScript program just now with no host specified, I
> saw how annoying the default wscript.exe can be.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
> news:379C3080-99DB-43AC-B8F7-955A878BE47C@microsoft.com...
> > Yes, If i use the Wscript.Echo its giving alert with ok button. I am
> > looking
> > for the code which will displays the output to the console.
> >
> > "Richard Mueller [MVP]" wrote:
> >
> >>
> >> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
> >> news:8B3A9920-4D17-41FE-8069-8F3224F6F169@microsoft.com...
> >> > Hi Mueller,
> >> >
> >> >   Thanks for your reply.
> >> > I have question. Is there any method which will print the out put(other
> >> > than
> >> > into file) other than Wscript.Echo ..like write, print etc., My
> >> > requirement
> >> > is to display the status of the group and down to the user details to
> >> > the
> >> > admin and write those details to file. using filesystem we can write
> >> > into
> >> > file.But how to display the details?
> >> >
> >> > Regards,
> >> > Sri
> >>
> >> I don't know of any way to print from a VBScript program. I generally use
> >> Wscript.Echo commands to echo information to the console. I can redirect
> >> the
> >> output to a text file, using the ">" redirection character. You can also
> >> use
> >> the FileSystemObject to write information to a text file.
> >>
> >> You can also use the MsgBox function to display information to users.
> >>
> >> --
> >> Richard Mueller
> >> Microsoft MVP Scripting and ADSI
> >> Hilltop Lab - http://www.rlmueller.net
> >> --
> >>
> >>
> >>
>
>
>
Author
12 Apr 2007 8:46 PM
Sriman
Hi Mueller,

  How to handle the errors in vbscript. right now i have written "on error
resume next". but i want to store the groupnames which has descripancy, like
i don't have right to execute the few domains , at that time application
throwing errors. i  was handled the error in .net perfectly and able to
separate the not worked groups.

is there any way to handle the errors like in .net?

Regards,
Sri

Show quote
"Sriman" wrote:

> Thank you mueller. cscript worked fine to me.
>  Below is my code. my requirement is to display the members in the group
> down to the user. input(domain\grpname) comes from the xml file. In .net i am
> able to retrieve the user list down to the user. but here in vbscript i am
> able to list down the users of few groups in my domain. it will not allow me
> to access the other domain users. I don't know the reason. no error is
> coming. Please check my code and  suggest me the best way.
>
> Option Explicit
>
> Dim adoCommand, adoConnection, strBase, strFilter, strAttributes, xmlDoc, x,
> WshNetwork, strComputer
> Dim strDomainName, strNodeText, strXmlBuilder
> Dim fso, res
>
> Dim strQuery, adoRecordset, strDN, strGroupName
>
> ' Setup ADO objects.
>
> Set adoCommand = CreateObject("ADODB.Command")
> Set adoConnection = CreateObject("ADODB.Connection")
> adoConnection.Provider = "ADsDSOObject"
> adoConnection.Open "Active Directory Provider"
> adoCommand.ActiveConnection = adoConnection
>
> Set WshNetwork = WScript.CreateObject("WScript.Network")
> strComputer = UCase(WshNetwork.ComputerName)
>
> 'Set fso = CreateObject("Scripting.FileSystemObject")
> 'Set res = fso.CreateTextFile(strComputer & ".xml", True)
> 'strXmlBuilder = strXmlBuilder & "<?xml version=\"1.0\" standalone=\"yes\"?>"
> 'strXmlBuilder =    strXmlBuilder & "\n"  + "<WINNTGrps>"
>            
> 'res.WriteLine "setmachine= & SerialNumber
> 'res.Close
>
>
> set xmlDoc=CreateObject("Microsoft.XMLDOM")
> xmlDoc.async="false"
> xmlDoc.load("groupstoberesolved.xml")
>
> for each x in xmlDoc.documentElement.childNodes
>  
>   strNodeText = replace(x.text,"\","/")
>
>   if x.nodename <> "#comment" then
>   Wscript.Echo "Node Name:" & x.nodename & vbcrlf & "Node Text:" &
> strNodeText & vbcrlf & "Domain Name:" & _
>    mid(x.text,1, InStr(strNodeText,"/")-1)  _
>             & vbcrlf & "GroupName:" & mid(x.text,InStr(strNodeText,"/") + 1,
> len(strNodeText))
>
> strDomainName = mid(x.text,1, InStr(strNodeText,"/")-1)           
> strGroupName = mid(x.text,InStr(strNodeText,"/") + 1, len(strNodeText))
>
> strBase = "<LDAP://" & strDomainName & ">"
>
> strFilter = "(&(|(objectClass=user)(objectclass=group))" &
> "(sAMAccountName=" & strGroupName & "))"
> strAttributes = "distinguishedName"
>
> ' Construct the LDAP syntax query.
> strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
>  'Wscript.Echo strQuery
> adoCommand.CommandText = strQuery
> adoCommand.Properties("Page Size") = 100
> adoCommand.Properties("Timeout") = 30
> adoCommand.Properties("Cache Results") = False
>
> ' Run the query.
> Set adoRecordset = adoCommand.Execute
>
>
> ' Enumerate the resulting recordset.
> Do Until adoRecordset.EOF
>
>     ' Retrieve values and display.
>     strDN = adoRecordset.Fields("distinguishedName").Value
>    
>     enumMembers getGroup(strDN,strGroupName),  ""
>     adoRecordset.MoveNext
> Loop
> end if
> next
>
> ' Clean up.
>
> adoRecordset.Close
> adoConnection.Close
>
>
> Function getGroup(strQueryFrom,strGroupName)
>   Dim objConn, objRecSet, strQueryString
>   Const adsOpenStatic = 3
>
>    Set objConn = wscript.CreateObject("ADODB.Connection")
>    objConn.Provider = "ADsDSOObject"
>    objConn.Open
>  wscript.echo strQueryFrom
>    strQueryString = "SELECT * FROM 'LDAP://" & strQueryFrom & "' "  & "
> WHERE samAccountName =  '" & strGroupName & "'"
>
>    Set objRecSet = wscript.CreateObject("ADODB.Recordset")
>
>    objRecSet.Open strQueryString, objConn, adsOpenStatic
>
>     If objRecSet.recordCount = 1 Then
>     dim objFlds
>       for each objFlds In objRecSet.Fields
>         ' wscript.echo objFlds.Name
>       next
>       Set getGroup = GetObject(objRecSet("AdsPath"))
>      
>     Else
>       wscript.echo "Record Cnt: " & objRecSet.recordCount & vbcrlf & "Query:
> " & strQueryString ' ucase(strGroupName) & " was not found in the domain. ("
> & objRootDSE.get("defaultNamingContext") & ")"
>       wscript.quit
>     End If
> End Function
>
>
> Sub enumMembers(byRef objGroup, strInheritedFrom)
>  Dim objMember
>
>    For Each objMember In objGroup.Members
>      If lcase(objMember.class) = "group" Then
>      enumMembers objMember, objMember.samAccountName
>    Else
>      If objMember.displayname <> "" Then
>        If strInheritedFrom = "" Then
>          wscript.echo objMember.displayname
>        Else
>          wscript.echo objMember.displayname & " (From NESTED GROUP:  " &
> strInheritedFrom & ")"
>       End If
>     Else
>        If strInheritedFrom = "" Then
>         wscript.echo objMember.samAccountName
>      Else
>        wscript.echo objMember.samAccountName & " (From NESTED GROUP:  " &
> strInheritedFrom & ")"
>      End If
>    End If
>  End If
>
>  Next
> End Sub
>
> "Richard Mueller [MVP]" wrote:
>
> > If you run the script with the wscript host, Wscript.Echo commands result in
> > a message box with an OK button. However, if you use the cscript host,
> > Wscript.Echo echos to the console. If the VBScript program is called
> > Example.vbs, you can use a command similar to below at a command prompt:
> >
> > cscript Example.vbs
> >
> > I often use the //nologo optional parameter to suppress the WSH logo
> > information, especially if I want to redirect the output to a text file. For
> > example:
> >
> > cscript //nologo Example.vbs > output.txt
> >
> > The above assumes you are in the directory where the file Example.vbs is
> > saved. Otherwise, you have to specify the full path and file name in the
> > command.
> >
> > I see that on most systems the default host is wscript, so if you just run
> > the vbs file, wscript.exe is used and the Wscript.Echo statements result in
> > message boxes. This may be what you experience. For example, that most
> > likely happens if you enter:
> >
> > example.vbs
> > or
> > example
> >
> > The default host can be changed to cscript. My reference gives the following
> > command to set the default to cscript:
> >
> > cscript //H:cscript //S
> >
> > The //S option saves this setting for the user. The command:
> >
> > cscript //I //nologo //H:cscript //S
> >
> > saves 3 options for the particular user (on this computer), the //I option
> > specifies interactive mode (which I think is the default anywayt), //nologo
> > suppresses the WSH logo information, //H:cscript assigns cscript.exe as the
> > default host, and //S saves the settings for the user.
> >
> > I don't alter the settings, since I've gotten into the habit of always using
> > cscript. When I tried a VBScript program just now with no host specified, I
> > saw how annoying the default wscript.exe can be.
> >
> > --
> > Richard Mueller
> > Microsoft MVP Scripting and ADSI
> > Hilltop Lab - http://www.rlmueller.net
> > --
> >
> > "Sriman" <Sri***@discussions.microsoft.com> wrote in message
> > news:379C3080-99DB-43AC-B8F7-955A878BE47C@microsoft.com...
> > > Yes, If i use the Wscript.Echo its giving alert with ok button. I am
> > > looking
> > > for the code which will displays the output to the console.
> > >
> > > "Richard Mueller [MVP]" wrote:
> > >
> > >>
> > >> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
> > >> news:8B3A9920-4D17-41FE-8069-8F3224F6F169@microsoft.com...
> > >> > Hi Mueller,
> > >> >
> > >> >   Thanks for your reply.
> > >> > I have question. Is there any method which will print the out put(other
> > >> > than
> > >> > into file) other than Wscript.Echo ..like write, print etc., My
> > >> > requirement
> > >> > is to display the status of the group and down to the user details to
> > >> > the
> > >> > admin and write those details to file. using filesystem we can write
> > >> > into
> > >> > file.But how to display the details?
> > >> >
> > >> > Regards,
> > >> > Sri
> > >>
> > >> I don't know of any way to print from a VBScript program. I generally use
> > >> Wscript.Echo commands to echo information to the console. I can redirect
> > >> the
> > >> output to a text file, using the ">" redirection character. You can also
> > >> use
> > >> the FileSystemObject to write information to a text file.
> > >>
> > >> You can also use the MsgBox function to display information to users.
> > >>
> > >> --
> > >> Richard Mueller
> > >> Microsoft MVP Scripting and ADSI
> > >> Hilltop Lab - http://www.rlmueller.net
> > >> --
> > >>
> > >>
> > >>
> >
> >
> >
Author
13 Apr 2007 3:11 AM
Richard Mueller [MVP]
Error handling in VBScript is obviously not as good as in .NET. However, you
can suspend normal error handling with "On Error Resume Next", then restore
normal error handling with "On Error GoTo 0". You can use the builtin Err
object to check for errors.

I suspend normal error handling for the statements I expect might raise an
error, handle the error if it is raised, then restore normal error handling.
This way, if something unexpected happens, the problem is not ignored and I
get an error message (and line number) to help troubleshoot.

If you lack rights in the other domain, for example, an error might be
raised when you attempt to bind to a group. You could trap this error with
code similar to:
===========
On Error Resume Next
Set objGroup = GetObject("LDAP://" & strDN)
If (Err.Number <> 0) Then
    ' Error raised.
    Wscript.Echo "Error attempting to bind to group " & strDN
    Wscript.Echo "Error Number: " & Err.Number
    Wscript.Echo "Description: " & Err.Description
    On Error GoTo 0
Else
    On Error GoTo 0
    enumMembers objGroup, ""
End If
===========

If you are having trouble with groups in other domains, I wonder if using
the Global Catalog will help. Assuming the domains have trusts, the GC
should have partial information on all objects in the forest. This may make
the NameTranslate object a good choice in your case, for converting NT names
in the form MyDomain\TestGroup into Distinguished Names. In any case, if
NameTranslate cannot find the object, an error is raised by the Set method.
For example, the code I posted earlier can be modified to trap this possible
error as follows:
=============
' Constants for the NameTranslate object.

Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

' Specify values, or parse from XML file.
strDomainName = "MyDomain"
strGroupName = "TestGroup"

' Use the NameTranslate object to convert the NT name to the
' Distinguished Name required for the LDAP provider.
Set objTrans = CreateObject("NameTranslate")

' Initialize NameTranslate by locating the Global Catalog.
objTrans.Init ADS_NAME_INITTYPE_GC, ""

' Use the Set method to specify the NT format of the object name.
' Trap possible error.
On Error Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strDomainName & "\" & strGroupName
If (Err.Number = 0) Then
    ' No Error.
    On Error GoTo 0
    ' Use the Get method to retrieve the RPC 1779 Distinguished Name.
    strGroup = objTrans.Get(ADS_NAME_TYPE_1779)

    ' Bind to the group object.
    Set objGroup = GetObject("LDAP://" & strGroupDN)

    enumMembers objGroup, ""
Else
    Wscript.Echo "Cannot find group " & strDomainName & "\" & strGroupName
    Wscript.Echo "Error Number: " & Err.Number
    Wscript.Echo "Description: " & Err.Description
    On Error GoTo 0
End If

I hope this helps.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

Show quote
"Sriman" <Sri***@discussions.microsoft.com> wrote in message
news:2A7AD010-F5E2-4493-96A6-FE49686C895D@microsoft.com...
> Hi Mueller,
>
>  How to handle the errors in vbscript. right now i have written "on error
> resume next". but i want to store the groupnames which has descripancy,
> like
> i don't have right to execute the few domains , at that time application
> throwing errors. i  was handled the error in .net perfectly and able to
> separate the not worked groups.
>
> is there any way to handle the errors like in .net?
>
> Regards,
> Sri
>
> "Sriman" wrote:
>
>> Thank you mueller. cscript worked fine to me.
>>  Below is my code. my requirement is to display the members in the group
>> down to the user. input(domain\grpname) comes from the xml file. In .net
>> i am
>> able to retrieve the user list down to the user. but here in vbscript i
>> am
>> able to list down the users of few groups in my domain. it will not allow
>> me
>> to access the other domain users. I don't know the reason. no error is
>> coming. Please check my code and  suggest me the best way.
>>
>> Option Explicit
>>
>> Dim adoCommand, adoConnection, strBase, strFilter, strAttributes, xmlDoc,
>> x,
>> WshNetwork, strComputer
>> Dim strDomainName, strNodeText, strXmlBuilder
>> Dim fso, res
>>
>> Dim strQuery, adoRecordset, strDN, strGroupName
>>
>> ' Setup ADO objects.
>>
>> Set adoCommand = CreateObject("ADODB.Command")
>> Set adoConnection = CreateObject("ADODB.Connection")
>> adoConnection.Provider = "ADsDSOObject"
>> adoConnection.Open "Active Directory Provider"
>> adoCommand.ActiveConnection = adoConnection
>>
>> Set WshNetwork = WScript.CreateObject("WScript.Network")
>> strComputer = UCase(WshNetwork.ComputerName)
>>
>> 'Set fso = CreateObject("Scripting.FileSystemObject")
>> 'Set res = fso.CreateTextFile(strComputer & ".xml", True)
>> 'strXmlBuilder = strXmlBuilder & "<?xml version=\"1.0\"
>> standalone=\"yes\"?>"
>> 'strXmlBuilder =    strXmlBuilder & "\n"  + "<WINNTGrps>"
>>
>> 'res.WriteLine "setmachine= & SerialNumber
>> 'res.Close
>>
>>
>> set xmlDoc=CreateObject("Microsoft.XMLDOM")
>> xmlDoc.async="false"
>> xmlDoc.load("groupstoberesolved.xml")
>>
>> for each x in xmlDoc.documentElement.childNodes
>>
>>   strNodeText = replace(x.text,"\","/")
>>
>>   if x.nodename <> "#comment" then
>>   Wscript.Echo "Node Name:" & x.nodename & vbcrlf & "Node Text:" &
>> strNodeText & vbcrlf & "Domain Name:" & _
>>    mid(x.text,1, InStr(strNodeText,"/")-1)  _
>>             & vbcrlf & "GroupName:" & mid(x.text,InStr(strNodeText,"/") +
>> 1,
>> len(strNodeText))
>>
>> strDomainName = mid(x.text,1, InStr(strNodeText,"/")-1)
>> strGroupName = mid(x.text,InStr(strNodeText,"/") + 1, len(strNodeText))
>>
>> strBase = "<LDAP://" & strDomainName & ">"
>>
>> strFilter = "(&(|(objectClass=user)(objectclass=group))" &
>> "(sAMAccountName=" & strGroupName & "))"
>> strAttributes = "distinguishedName"
>>
>> ' Construct the LDAP syntax query.
>> strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
>>  'Wscript.Echo strQuery
>> adoCommand.CommandText = strQuery
>> adoCommand.Properties("Page Size") = 100
>> adoCommand.Properties("Timeout") = 30
>> adoCommand.Properties("Cache Results") = False
>>
>> ' Run the query.
>> Set adoRecordset = adoCommand.Execute
>>
>>
>> ' Enumerate the resulting recordset.
>> Do Until adoRecordset.EOF
>>
>>     ' Retrieve values and display.
>>     strDN = adoRecordset.Fields("distinguishedName").Value
>>
>>     enumMembers getGroup(strDN,strGroupName),  ""
>>     adoRecordset.MoveNext
>> Loop
>> end if
>> next
>>
>> ' Clean up.
>>
>> adoRecordset.Close
>> adoConnection.Close
>>
>>
>> Function getGroup(strQueryFrom,strGroupName)
>>   Dim objConn, objRecSet, strQueryString
>>   Const adsOpenStatic = 3
>>
>>    Set objConn = wscript.CreateObject("ADODB.Connection")
>>    objConn.Provider = "ADsDSOObject"
>>    objConn.Open
>>  wscript.echo strQueryFrom
>>    strQueryString = "SELECT * FROM 'LDAP://" & strQueryFrom & "' "  & "
>> WHERE samAccountName =  '" & strGroupName & "'"
>>
>>    Set objRecSet = wscript.CreateObject("ADODB.Recordset")
>>
>>    objRecSet.Open strQueryString, objConn, adsOpenStatic
>>
>>     If objRecSet.recordCount = 1 Then
>>     dim objFlds
>>       for each objFlds In objRecSet.Fields
>>         ' wscript.echo objFlds.Name
>>       next
>>       Set getGroup = GetObject(objRecSet("AdsPath"))
>>
>>     Else
>>       wscript.echo "Record Cnt: " & objRecSet.recordCount & vbcrlf &
>> "Query:
>> " & strQueryString ' ucase(strGroupName) & " was not found in the domain.
>> ("
>> & objRootDSE.get("defaultNamingContext") & ")"
>>       wscript.quit
>>     End If
>> End Function
>>
>>
>> Sub enumMembers(byRef objGroup, strInheritedFrom)
>>  Dim objMember
>>
>>    For Each objMember In objGroup.Members
>>      If lcase(objMember.class) = "group" Then
>>      enumMembers objMember, objMember.samAccountName
>>    Else
>>      If objMember.displayname <> "" Then
>>        If strInheritedFrom = "" Then
>>          wscript.echo objMember.displayname
>>        Else
>>          wscript.echo objMember.displayname & " (From NESTED GROUP:  " &
>> strInheritedFrom & ")"
>>       End If
>>     Else
>>        If strInheritedFrom = "" Then
>>         wscript.echo objMember.samAccountName
>>      Else
>>        wscript.echo objMember.samAccountName & " (From NESTED GROUP:  " &
>> strInheritedFrom & ")"
>>      End If
>>    End If
>>  End If
>>
>>  Next
>> End Sub
>>
>> "Richard Mueller [MVP]" wrote:
>>
>> > If you run the script with the wscript host, Wscript.Echo commands
>> > result in
>> > a message box with an OK button. However, if you use the cscript host,
>> > Wscript.Echo echos to the console. If the VBScript program is called
>> > Example.vbs, you can use a command similar to below at a command
>> > prompt:
>> >
>> > cscript Example.vbs
>> >
>> > I often use the //nologo optional parameter to suppress the WSH logo
>> > information, especially if I want to redirect the output to a text
>> > file. For
>> > example:
>> >
>> > cscript //nologo Example.vbs > output.txt
>> >
>> > The above assumes you are in the directory where the file Example.vbs
>> > is
>> > saved. Otherwise, you have to specify the full path and file name in
>> > the
>> > command.
>> >
>> > I see that on most systems the default host is wscript, so if you just
>> > run
>> > the vbs file, wscript.exe is used and the Wscript.Echo statements
>> > result in
>> > message boxes. This may be what you experience. For example, that most
>> > likely happens if you enter:
>> >
>> > example.vbs
>> > or
>> > example
>> >
>> > The default host can be changed to cscript. My reference gives the
>> > following
>> > command to set the default to cscript:
>> >
>> > cscript //H:cscript //S
>> >
>> > The //S option saves this setting for the user. The command:
>> >
>> > cscript //I //nologo //H:cscript //S
>> >
>> > saves 3 options for the particular user (on this computer), the //I
>> > option
>> > specifies interactive mode (which I think is the default anywayt),
>> > //nologo
>> > suppresses the WSH logo information, //H:cscript assigns cscript.exe as
>> > the
>> > default host, and //S saves the settings for the user.
>> >
>> > I don't alter the settings, since I've gotten into the habit of always
>> > using
>> > cscript. When I tried a VBScript program just now with no host
>> > specified, I
>> > saw how annoying the default wscript.exe can be.
>> >
>> > --
>> > Richard Mueller
>> > Microsoft MVP Scripting and ADSI
>> > Hilltop Lab - http://www.rlmueller.net
>> > --
>> >
>> > "Sriman" <Sri***@discussions.microsoft.com> wrote in message
>> > news:379C3080-99DB-43AC-B8F7-955A878BE47C@microsoft.com...
>> > > Yes, If i use the Wscript.Echo its giving alert with ok button. I am
>> > > looking
>> > > for the code which will displays the output to the console.
>> > >
>> > > "Richard Mueller [MVP]" wrote:
>> > >
>> > >>
>> > >> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
>> > >> news:8B3A9920-4D17-41FE-8069-8F3224F6F169@microsoft.com...
>> > >> > Hi Mueller,
>> > >> >
>> > >> >   Thanks for your reply.
>> > >> > I have question. Is there any method which will print the out
>> > >> > put(other
>> > >> > than
>> > >> > into file) other than Wscript.Echo ..like write, print etc., My
>> > >> > requirement
>> > >> > is to display the status of the group and down to the user details
>> > >> > to
>> > >> > the
>> > >> > admin and write those details to file. using filesystem we can
>> > >> > write
>> > >> > into
>> > >> > file.But how to display the details?
>> > >> >
>> > >> > Regards,
>> > >> > Sri
>> > >>
>> > >> I don't know of any way to print from a VBScript program. I
>> > >> generally use
>> > >> Wscript.Echo commands to echo information to the console. I can
>> > >> redirect
>> > >> the
>> > >> output to a text file, using the ">" redirection character. You can
>> > >> also
>> > >> use
>> > >> the FileSystemObject to write information to a text file.
>> > >>
>> > >> You can also use the MsgBox function to display information to
>> > >> users.
>> > >>
>> > >> --
>> > >> Richard Mueller
>> > >> Microsoft MVP Scripting and ADSI
>> > >> Hilltop Lab - http://www.rlmueller.net
>> > >> --
>> > >>
>> > >>
>> > >>
>> >
>> >
>> >
Author
13 Apr 2007 2:53 AM
Richard Mueller [MVP]
I have a hard time following your script. I assume that strDomainName is the
DNS name of a domain, similar to "dc=MyDomain,dc=com". I say this because
you use this as the base of an ADO query. I also assume that strGroupName is
the NetBIOS name of a group, similar to "TestGroup". You then search for the
object that has sAMAccountName equal to the value of strGroupName and
retrieve the Distinguished Name of the group, strDN.

However, you then pass strDN and strGroupName to function GetGroup, where I
get lost. I think you should replace the statement:

enumMembers getGroup(strDN, strGroupName), ""

With the following:

Set objGroup = GetObject("LDAP://" & strDN)
enumMembers objGroup, ""

If instead strDomainName is the NetBIOS name of a domain, and strGroupName
is the NetBIOS name of a group, it would make more sense to use the
NameTranslate object to convert these to the Distinguished Name of the
group. For one domain and one group, the code would be similar to:
=================
' Constants for the NameTranslate object.

Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1


' Specify values, or parse from XML file.
strDomainName = "MyDomain"
strGroupName = "TestGroup"

' Use the NameTranslate object to convert the NT name to the
' Distinguished Name required for the LDAP provider.
Set objTrans = CreateObject("NameTranslate")


' Initialize NameTranslate by locating the Global Catalog.
objTrans.Init ADS_NAME_INITTYPE_GC, ""


' Use the Set method to specify the NT format of the object name.
objTrans.Set ADS_NAME_TYPE_NT4, strDomainName & "\" & strGroupName



' Use the Get method to retrieve the RPC 1779 Distinguished Name.
strGroup = objTrans.Get(ADS_NAME_TYPE_1779)

' Bind to the group object.
Set objGroup = GetObject("LDAP://" & strGroupDN)



enumMembers objGroup, ""
===============
You could repeat this for each domain\group combination. I think you sub
enumMembers should work.

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

Show quote
"Sriman" <Sri***@discussions.microsoft.com> wrote in message
news:B8C8A71A-67BE-4E53-AA97-6AEF1E63861D@microsoft.com...
> Thank you mueller. cscript worked fine to me.
> Below is my code. my requirement is to display the members in the group
> down to the user. input(domain\grpname) comes from the xml file. In .net i
> am
> able to retrieve the user list down to the user. but here in vbscript i am
> able to list down the users of few groups in my domain. it will not allow
> me
> to access the other domain users. I don't know the reason. no error is
> coming. Please check my code and  suggest me the best way.
>
> Option Explicit
>
> Dim adoCommand, adoConnection, strBase, strFilter, strAttributes, xmlDoc,
> x,
> WshNetwork, strComputer
> Dim strDomainName, strNodeText, strXmlBuilder
> Dim fso, res
>
> Dim strQuery, adoRecordset, strDN, strGroupName
>
> ' Setup ADO objects.
>
> Set adoCommand = CreateObject("ADODB.Command")
> Set adoConnection = CreateObject("ADODB.Connection")
> adoConnection.Provider = "ADsDSOObject"
> adoConnection.Open "Active Directory Provider"
> adoCommand.ActiveConnection = adoConnection
>
> Set WshNetwork = WScript.CreateObject("WScript.Network")
> strComputer = UCase(WshNetwork.ComputerName)
>
> 'Set fso = CreateObject("Scripting.FileSystemObject")
> 'Set res = fso.CreateTextFile(strComputer & ".xml", True)
> 'strXmlBuilder = strXmlBuilder & "<?xml version=\"1.0\"
> standalone=\"yes\"?>"
> 'strXmlBuilder =    strXmlBuilder & "\n"  + "<WINNTGrps>"
>
> 'res.WriteLine "setmachine= & SerialNumber
> 'res.Close
>
>
> set xmlDoc=CreateObject("Microsoft.XMLDOM")
> xmlDoc.async="false"
> xmlDoc.load("groupstoberesolved.xml")
>
> for each x in xmlDoc.documentElement.childNodes
>
>  strNodeText = replace(x.text,"\","/")
>
>  if x.nodename <> "#comment" then
>  Wscript.Echo "Node Name:" & x.nodename & vbcrlf & "Node Text:" &
> strNodeText & vbcrlf & "Domain Name:" & _
>   mid(x.text,1, InStr(strNodeText,"/")-1)  _
>            & vbcrlf & "GroupName:" & mid(x.text,InStr(strNodeText,"/") +
> 1,
> len(strNodeText))
>
> strDomainName = mid(x.text,1, InStr(strNodeText,"/")-1)
> strGroupName = mid(x.text,InStr(strNodeText,"/") + 1, len(strNodeText))
>
> strBase = "<LDAP://" & strDomainName & ">"
>
> strFilter = "(&(|(objectClass=user)(objectclass=group))" &
> "(sAMAccountName=" & strGroupName & "))"
> strAttributes = "distinguishedName"
>
> ' Construct the LDAP syntax query.
> strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
> 'Wscript.Echo strQuery
> adoCommand.CommandText = strQuery
> adoCommand.Properties("Page Size") = 100
> adoCommand.Properties("Timeout") = 30
> adoCommand.Properties("Cache Results") = False
>
> ' Run the query.
> Set adoRecordset = adoCommand.Execute
>
>
> ' Enumerate the resulting recordset.
> Do Until adoRecordset.EOF
>
>    ' Retrieve values and display.
>    strDN = adoRecordset.Fields("distinguishedName").Value
>
>    enumMembers getGroup(strDN,strGroupName),  ""
>    adoRecordset.MoveNext
> Loop
> end if
> next
>
> ' Clean up.
>
> adoRecordset.Close
> adoConnection.Close
>
>
> Function getGroup(strQueryFrom,strGroupName)
>  Dim objConn, objRecSet, strQueryString
>  Const adsOpenStatic = 3
>
>   Set objConn = wscript.CreateObject("ADODB.Connection")
>   objConn.Provider = "ADsDSOObject"
>   objConn.Open
> wscript.echo strQueryFrom
>   strQueryString = "SELECT * FROM 'LDAP://" & strQueryFrom & "' "  & "
> WHERE samAccountName =  '" & strGroupName & "'"
>
>   Set objRecSet = wscript.CreateObject("ADODB.Recordset")
>
>   objRecSet.Open strQueryString, objConn, adsOpenStatic
>
>    If objRecSet.recordCount = 1 Then
>    dim objFlds
>      for each objFlds In objRecSet.Fields
>        ' wscript.echo objFlds.Name
>      next
>      Set getGroup = GetObject(objRecSet("AdsPath"))
>
>    Else
>      wscript.echo "Record Cnt: " & objRecSet.recordCount & vbcrlf &
> "Query:
> " & strQueryString ' ucase(strGroupName) & " was not found in the domain.
> ("
> & objRootDSE.get("defaultNamingContext") & ")"
>      wscript.quit
>    End If
> End Function
>
>
> Sub enumMembers(byRef objGroup, strInheritedFrom)
> Dim objMember
>
>   For Each objMember In objGroup.Members
>     If lcase(objMember.class) = "group" Then
>     enumMembers objMember, objMember.samAccountName
>   Else
>     If objMember.displayname <> "" Then
>       If strInheritedFrom = "" Then
>         wscript.echo objMember.displayname
>       Else
>         wscript.echo objMember.displayname & " (From NESTED GROUP:  " &
> strInheritedFrom & ")"
>      End If
>    Else
>       If strInheritedFrom = "" Then
>        wscript.echo objMember.samAccountName
>     Else
>       wscript.echo objMember.samAccountName & " (From NESTED GROUP:  " &
> strInheritedFrom & ")"
>     End If
>   End If
> End If
>
> Next
> End Sub
>
> "Richard Mueller [MVP]" wrote:
>
>> If you run the script with the wscript host, Wscript.Echo commands result
>> in
>> a message box with an OK button. However, if you use the cscript host,
>> Wscript.Echo echos to the console. If the VBScript program is called
>> Example.vbs, you can use a command similar to below at a command prompt:
>>
>> cscript Example.vbs
>>
>> I often use the //nologo optional parameter to suppress the WSH logo
>> information, especially if I want to redirect the output to a text file.
>> For
>> example:
>>
>> cscript //nologo Example.vbs > output.txt
>>
>> The above assumes you are in the directory where the file Example.vbs is
>> saved. Otherwise, you have to specify the full path and file name in the
>> command.
>>
>> I see that on most systems the default host is wscript, so if you just
>> run
>> the vbs file, wscript.exe is used and the Wscript.Echo statements result
>> in
>> message boxes. This may be what you experience. For example, that most
>> likely happens if you enter:
>>
>> example.vbs
>> or
>> example
>>
>> The default host can be changed to cscript. My reference gives the
>> following
>> command to set the default to cscript:
>>
>> cscript //H:cscript //S
>>
>> The //S option saves this setting for the user. The command:
>>
>> cscript //I //nologo //H:cscript //S
>>
>> saves 3 options for the particular user (on this computer), the //I
>> option
>> specifies interactive mode (which I think is the default anywayt),
>> //nologo
>> suppresses the WSH logo information, //H:cscript assigns cscript.exe as
>> the
>> default host, and //S saves the settings for the user.
>>
>> I don't alter the settings, since I've gotten into the habit of always
>> using
>> cscript. When I tried a VBScript program just now with no host specified,
>> I
>> saw how annoying the default wscript.exe can be.
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
>> news:379C3080-99DB-43AC-B8F7-955A878BE47C@microsoft.com...
>> > Yes, If i use the Wscript.Echo its giving alert with ok button. I am
>> > looking
>> > for the code which will displays the output to the console.
>> >
>> > "Richard Mueller [MVP]" wrote:
>> >
>> >>
>> >> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
>> >> news:8B3A9920-4D17-41FE-8069-8F3224F6F169@microsoft.com...
>> >> > Hi Mueller,
>> >> >
>> >> >   Thanks for your reply.
>> >> > I have question. Is there any method which will print the out
>> >> > put(other
>> >> > than
>> >> > into file) other than Wscript.Echo ..like write, print etc., My
>> >> > requirement
>> >> > is to display the status of the group and down to the user details
>> >> > to
>> >> > the
>> >> > admin and write those details to file. using filesystem we can write
>> >> > into
>> >> > file.But how to display the details?
>> >> >
>> >> > Regards,
>> >> > Sri
>> >>
>> >> I don't know of any way to print from a VBScript program. I generally
>> >> use
>> >> Wscript.Echo commands to echo information to the console. I can
>> >> redirect
>> >> the
>> >> output to a text file, using the ">" redirection character. You can
>> >> also
>> >> use
>> >> the FileSystemObject to write information to a text file.
>> >>
>> >> You can also use the MsgBox function to display information to users.
>> >>
>> >> --
>> >> Richard Mueller
>> >> Microsoft MVP Scripting and ADSI
>> >> Hilltop Lab - http://www.rlmueller.net
>> >> --
>> >>
>> >>
>> >>
>>
>>
>>
Author
13 Apr 2007 8:28 PM
Sriman
great help. now script working perfect. small question
will it handles the NTDomains also?

Show quote
"Richard Mueller [MVP]" wrote:

> I have a hard time following your script. I assume that strDomainName is the
> DNS name of a domain, similar to "dc=MyDomain,dc=com". I say this because
> you use this as the base of an ADO query. I also assume that strGroupName is
> the NetBIOS name of a group, similar to "TestGroup". You then search for the
> object that has sAMAccountName equal to the value of strGroupName and
> retrieve the Distinguished Name of the group, strDN.
>
> However, you then pass strDN and strGroupName to function GetGroup, where I
> get lost. I think you should replace the statement:
>
> enumMembers getGroup(strDN, strGroupName), ""
>
> With the following:
>
> Set objGroup = GetObject("LDAP://" & strDN)
> enumMembers objGroup, ""
>
> If instead strDomainName is the NetBIOS name of a domain, and strGroupName
> is the NetBIOS name of a group, it would make more sense to use the
> NameTranslate object to convert these to the Distinguished Name of the
> group. For one domain and one group, the code would be similar to:
> =================
> ' Constants for the NameTranslate object.
>
> Const ADS_NAME_INITTYPE_GC = 3
> Const ADS_NAME_TYPE_NT4 = 3
> Const ADS_NAME_TYPE_1779 = 1
>
>
> ' Specify values, or parse from XML file.
> strDomainName = "MyDomain"
> strGroupName = "TestGroup"
>
> ' Use the NameTranslate object to convert the NT name to the
> ' Distinguished Name required for the LDAP provider.
> Set objTrans = CreateObject("NameTranslate")
>
>
> ' Initialize NameTranslate by locating the Global Catalog.
> objTrans.Init ADS_NAME_INITTYPE_GC, ""
>
>
> ' Use the Set method to specify the NT format of the object name.
> objTrans.Set ADS_NAME_TYPE_NT4, strDomainName & "\" & strGroupName
>
>
>
> ' Use the Get method to retrieve the RPC 1779 Distinguished Name.
> strGroup = objTrans.Get(ADS_NAME_TYPE_1779)
>
> ' Bind to the group object.
> Set objGroup = GetObject("LDAP://" & strGroupDN)
>
>
>
> enumMembers objGroup, ""
> ===============
> You could repeat this for each domain\group combination. I think you sub
> enumMembers should work.
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
> news:B8C8A71A-67BE-4E53-AA97-6AEF1E63861D@microsoft.com...
> > Thank you mueller. cscript worked fine to me.
> > Below is my code. my requirement is to display the members in the group
> > down to the user. input(domain\grpname) comes from the xml file. In .net i
> > am
> > able to retrieve the user list down to the user. but here in vbscript i am
> > able to list down the users of few groups in my domain. it will not allow
> > me
> > to access the other domain users. I don't know the reason. no error is
> > coming. Please check my code and  suggest me the best way.
> >
> > Option Explicit
> >
> > Dim adoCommand, adoConnection, strBase, strFilter, strAttributes, xmlDoc,
> > x,
> > WshNetwork, strComputer
> > Dim strDomainName, strNodeText, strXmlBuilder
> > Dim fso, res
> >
> > Dim strQuery, adoRecordset, strDN, strGroupName
> >
> > ' Setup ADO objects.
> >
> > Set adoCommand = CreateObject("ADODB.Command")
> > Set adoConnection = CreateObject("ADODB.Connection")
> > adoConnection.Provider = "ADsDSOObject"
> > adoConnection.Open "Active Directory Provider"
> > adoCommand.ActiveConnection = adoConnection
> >
> > Set WshNetwork = WScript.CreateObject("WScript.Network")
> > strComputer = UCase(WshNetwork.ComputerName)
> >
> > 'Set fso = CreateObject("Scripting.FileSystemObject")
> > 'Set res = fso.CreateTextFile(strComputer & ".xml", True)
> > 'strXmlBuilder = strXmlBuilder & "<?xml version=\"1.0\"
> > standalone=\"yes\"?>"
> > 'strXmlBuilder =    strXmlBuilder & "\n"  + "<WINNTGrps>"
> >
> > 'res.WriteLine "setmachine= & SerialNumber
> > 'res.Close
> >
> >
> > set xmlDoc=CreateObject("Microsoft.XMLDOM")
> > xmlDoc.async="false"
> > xmlDoc.load("groupstoberesolved.xml")
> >
> > for each x in xmlDoc.documentElement.childNodes
> >
> >  strNodeText = replace(x.text,"\","/")
> >
> >  if x.nodename <> "#comment" then
> >  Wscript.Echo "Node Name:" & x.nodename & vbcrlf & "Node Text:" &
> > strNodeText & vbcrlf & "Domain Name:" & _
> >   mid(x.text,1, InStr(strNodeText,"/")-1)  _
> >            & vbcrlf & "GroupName:" & mid(x.text,InStr(strNodeText,"/") +
> > 1,
> > len(strNodeText))
> >
> > strDomainName = mid(x.text,1, InStr(strNodeText,"/")-1)
> > strGroupName = mid(x.text,InStr(strNodeText,"/") + 1, len(strNodeText))
> >
> > strBase = "<LDAP://" & strDomainName & ">"
> >
> > strFilter = "(&(|(objectClass=user)(objectclass=group))" &
> > "(sAMAccountName=" & strGroupName & "))"
> > strAttributes = "distinguishedName"
> >
> > ' Construct the LDAP syntax query.
> > strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
> > 'Wscript.Echo strQuery
> > adoCommand.CommandText = strQuery
> > adoCommand.Properties("Page Size") = 100
> > adoCommand.Properties("Timeout") = 30
> > adoCommand.Properties("Cache Results") = False
> >
> > ' Run the query.
> > Set adoRecordset = adoCommand.Execute
> >
> >
> > ' Enumerate the resulting recordset.
> > Do Until adoRecordset.EOF
> >
> >    ' Retrieve values and display.
> >    strDN = adoRecordset.Fields("distinguishedName").Value
> >
> >    enumMembers getGroup(strDN,strGroupName),  ""
> >    adoRecordset.MoveNext
> > Loop
> > end if
> > next
> >
> > ' Clean up.
> >
> > adoRecordset.Close
> > adoConnection.Close
> >
> >
> > Function getGroup(strQueryFrom,strGroupName)
> >  Dim objConn, objRecSet, strQueryString
> >  Const adsOpenStatic = 3
> >
> >   Set objConn = wscript.CreateObject("ADODB.Connection")
> >   objConn.Provider = "ADsDSOObject"
> >   objConn.Open
> > wscript.echo strQueryFrom
> >   strQueryString = "SELECT * FROM 'LDAP://" & strQueryFrom & "' "  & "
> > WHERE samAccountName =  '" & strGroupName & "'"
> >
> >   Set objRecSet = wscript.CreateObject("ADODB.Recordset")
> >
> >   objRecSet.Open strQueryString, objConn, adsOpenStatic
> >
> >    If objRecSet.recordCount = 1 Then
> >    dim objFlds
> >      for each objFlds In objRecSet.Fields
> >        ' wscript.echo objFlds.Name
> >      next
> >      Set getGroup = GetObject(objRecSet("AdsPath"))
> >
> >    Else
> >      wscript.echo "Record Cnt: " & objRecSet.recordCount & vbcrlf &
> > "Query:
> > " & strQueryString ' ucase(strGroupName) & " was not found in the domain.
> > ("
> > & objRootDSE.get("defaultNamingContext") & ")"
> >      wscript.quit
> >    End If
> > End Function
> >
> >
> > Sub enumMembers(byRef objGroup, strInheritedFrom)
> > Dim objMember
> >
> >   For Each objMember In objGroup.Members
> >     If lcase(objMember.class) = "group" Then
> >     enumMembers objMember, objMember.samAccountName
> >   Else
> >     If objMember.displayname <> "" Then
> >       If strInheritedFrom = "" Then
> >         wscript.echo objMember.displayname
> >       Else
> >         wscript.echo objMember.displayname & " (From NESTED GROUP:  " &
> > strInheritedFrom & ")"
> >      End If
> >    Else
> >       If strInheritedFrom = "" Then
> >        wscript.echo objMember.samAccountName
> >     Else
> >       wscript.echo objMember.samAccountName & " (From NESTED GROUP:  " &
> > strInheritedFrom & ")"
> >     End If
> >   End If
> > End If
> >
> > Next
> > End Sub
> >
> > "Richard Mueller [MVP]" wrote:
> >
> >> If you run the script with the wscript host, Wscript.Echo commands result
> >> in
> >> a message box with an OK button. However, if you use the cscript host,
> >> Wscript.Echo echos to the console. If the VBScript program is called
> >> Example.vbs, you can use a command similar to below at a command prompt:
> >>
> >> cscript Example.vbs
> >>
> >> I often use the //nologo optional parameter to suppress the WSH logo
> >> information, especially if I want to redirect the output to a text file.
> >> For
> >> example:
> >>
> >> cscript //nologo Example.vbs > output.txt
> >>
> >> The above assumes you are in the directory where the file Example.vbs is
> >> saved. Otherwise, you have to specify the full path and file name in the
> >> command.
> >>
> >> I see that on most systems the default host is wscript, so if you just
> >> run
> >> the vbs file, wscript.exe is used and the Wscript.Echo statements result
> >> in
> >> message boxes. This may be what you experience. For example, that most
> >> likely happens if you enter:
> >>
> >> example.vbs
> >> or
> >> example
> >>
> >> The default host can be changed to cscript. My reference gives the
> >> following
> >> command to set the default to cscript:
> >>
> >> cscript //H:cscript //S
> >>
> >> The //S option saves this setting for the user. The command:
> >>
> >> cscript //I //nologo //H:cscript //S
> >>
> >> saves 3 options for the particular user (on this computer), the //I
> >> option
> >> specifies interactive mode (which I think is the default anywayt),
> >> //nologo
> >> suppresses the WSH logo information, //H:cscript assigns cscript.exe as
> >> the
> >> default host, and //S saves the settings for the user.
> >>
> >> I don't alter the settings, since I've gotten into the habit of always
> >> using
> >> cscript. When I tried a VBScript program just now with no host specified,
> >> I
> >> saw how annoying the default wscript.exe can be.
> >>
> >> --
> >> Richard Mueller
> >> Microsoft MVP Scripting and ADSI
> >> Hilltop Lab - http://www.rlmueller.net
> >> --
> >>
> >> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
> >> news:379C3080-99DB-43AC-B8F7-955A878BE47C@microsoft.com...
> >> > Yes, If i use the Wscript.Echo its giving alert with ok button. I am
> >> > looking
> >> > for the code which will displays the output to the console.
> >> >
> >> > "Richard Mueller [MVP]" wrote:
> >> >
> >> >>
> >> >> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
> >> >> news:8B3A9920-4D17-41FE-8069-8F3224F6F169@microsoft.com...
> >> >> > Hi Mueller,
> >> >> >
> >> >> >   Thanks for your reply.
Author
14 Apr 2007 12:59 AM
Richard Mueller [MVP]
The NT SAM account database is not LDAP compliant, so you must use the WinNT
provider. However, since NT does not support nested domain groups, and the
WinNT provider reveals the "primary" group, enumerating group membership is
much simpler. Just bind to the group with the WinNT provider and use the
Members method. All members are revealed. Also, NT only uses the NT names
(NetBIOS names) of objects, so there is no conversion to Distinguished Name.
In brief:

' Specify (or read) NetBIOS name of group and domain.
strGroup = "Sales"
strDomain = "MyDomain"

' Bind to group.
Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")

' Enumerate group members.
For Each objMember In objGroup.Members
    Wscript.Echo objMember.Name
Next

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--

Show quote
"Sriman" <Sri***@discussions.microsoft.com> wrote in message
news:B6294B09-155E-4E58-8ABD-5C563ADD33FD@microsoft.com...
> great help. now script working perfect. small question
> will it handles the NTDomains also?
>
> "Richard Mueller [MVP]" wrote:
>
>> I have a hard time following your script. I assume that strDomainName is
>> the
>> DNS name of a domain, similar to "dc=MyDomain,dc=com". I say this because
>> you use this as the base of an ADO query. I also assume that strGroupName
>> is
>> the NetBIOS name of a group, similar to "TestGroup". You then search for
>> the
>> object that has sAMAccountName equal to the value of strGroupName and
>> retrieve the Distinguished Name of the group, strDN.
>>
>> However, you then pass strDN and strGroupName to function GetGroup, where
>> I
>> get lost. I think you should replace the statement:
>>
>> enumMembers getGroup(strDN, strGroupName), ""
>>
>> With the following:
>>
>> Set objGroup = GetObject("LDAP://" & strDN)
>> enumMembers objGroup, ""
>>
>> If instead strDomainName is the NetBIOS name of a domain, and
>> strGroupName
>> is the NetBIOS name of a group, it would make more sense to use the
>> NameTranslate object to convert these to the Distinguished Name of the
>> group. For one domain and one group, the code would be similar to:
>> =================
>> ' Constants for the NameTranslate object.
>>
>> Const ADS_NAME_INITTYPE_GC = 3
>> Const ADS_NAME_TYPE_NT4 = 3
>> Const ADS_NAME_TYPE_1779 = 1
>>
>>
>> ' Specify values, or parse from XML file.
>> strDomainName = "MyDomain"
>> strGroupName = "TestGroup"
>>
>> ' Use the NameTranslate object to convert the NT name to the
>> ' Distinguished Name required for the LDAP provider.
>> Set objTrans = CreateObject("NameTranslate")
>>
>>
>> ' Initialize NameTranslate by locating the Global Catalog.
>> objTrans.Init ADS_NAME_INITTYPE_GC, ""
>>
>>
>> ' Use the Set method to specify the NT format of the object name.
>> objTrans.Set ADS_NAME_TYPE_NT4, strDomainName & "\" & strGroupName
>>
>>
>>
>> ' Use the Get method to retrieve the RPC 1779 Distinguished Name.
>> strGroup = objTrans.Get(ADS_NAME_TYPE_1779)
>>
>> ' Bind to the group object.
>> Set objGroup = GetObject("LDAP://" & strGroupDN)
>>
>>
>>
>> enumMembers objGroup, ""
>> ===============
>> You could repeat this for each domain\group combination. I think you sub
>> enumMembers should work.
>>
>> --
>> Richard Mueller
>> Microsoft MVP Scripting and ADSI
>> Hilltop Lab - http://www.rlmueller.net
>> --
>>
>> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
>> news:B8C8A71A-67BE-4E53-AA97-6AEF1E63861D@microsoft.com...
>> > Thank you mueller. cscript worked fine to me.
>> > Below is my code. my requirement is to display the members in the group
>> > down to the user. input(domain\grpname) comes from the xml file. In
>> > .net i
>> > am
>> > able to retrieve the user list down to the user. but here in vbscript i
>> > am
>> > able to list down the users of few groups in my domain. it will not
>> > allow
>> > me
>> > to access the other domain users. I don't know the reason. no error is
>> > coming. Please check my code and  suggest me the best way.
>> >
>> > Option Explicit
>> >
>> > Dim adoCommand, adoConnection, strBase, strFilter, strAttributes,
>> > xmlDoc,
>> > x,
>> > WshNetwork, strComputer
>> > Dim strDomainName, strNodeText, strXmlBuilder
>> > Dim fso, res
>> >
>> > Dim strQuery, adoRecordset, strDN, strGroupName
>> >
>> > ' Setup ADO objects.
>> >
>> > Set adoCommand = CreateObject("ADODB.Command")
>> > Set adoConnection = CreateObject("ADODB.Connection")
>> > adoConnection.Provider = "ADsDSOObject"
>> > adoConnection.Open "Active Directory Provider"
>> > adoCommand.ActiveConnection = adoConnection
>> >
>> > Set WshNetwork = WScript.CreateObject("WScript.Network")
>> > strComputer = UCase(WshNetwork.ComputerName)
>> >
>> > 'Set fso = CreateObject("Scripting.FileSystemObject")
>> > 'Set res = fso.CreateTextFile(strComputer & ".xml", True)
>> > 'strXmlBuilder = strXmlBuilder & "<?xml version=\"1.0\"
>> > standalone=\"yes\"?>"
>> > 'strXmlBuilder =    strXmlBuilder & "\n"  + "<WINNTGrps>"
>> >
>> > 'res.WriteLine "setmachine= & SerialNumber
>> > 'res.Close
>> >
>> >
>> > set xmlDoc=CreateObject("Microsoft.XMLDOM")
>> > xmlDoc.async="false"
>> > xmlDoc.load("groupstoberesolved.xml")
>> >
>> > for each x in xmlDoc.documentElement.childNodes
>> >
>> >  strNodeText = replace(x.text,"\","/")
>> >
>> >  if x.nodename <> "#comment" then
>> >  Wscript.Echo "Node Name:" & x.nodename & vbcrlf & "Node Text:" &
>> > strNodeText & vbcrlf & "Domain Name:" & _
>> >   mid(x.text,1, InStr(strNodeText,"/")-1)  _
>> >            & vbcrlf & "GroupName:" & mid(x.text,InStr(strNodeText,"/")
>> > +
>> > 1,
>> > len(strNodeText))
>> >
>> > strDomainName = mid(x.text,1, InStr(strNodeText,"/")-1)
>> > strGroupName = mid(x.text,InStr(strNodeText,"/") + 1, len(strNodeText))
>> >
>> > strBase = "<LDAP://" & strDomainName & ">"
>> >
>> > strFilter = "(&(|(objectClass=user)(objectclass=group))" &
>> > "(sAMAccountName=" & strGroupName & "))"
>> > strAttributes = "distinguishedName"
>> >
>> > ' Construct the LDAP syntax query.
>> > strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
>> > 'Wscript.Echo strQuery
>> > adoCommand.CommandText = strQuery
>> > adoCommand.Properties("Page Size") = 100
>> > adoCommand.Properties("Timeout") = 30
>> > adoCommand.Properties("Cache Results") = False
>> >
>> > ' Run the query.
>> > Set adoRecordset = adoCommand.Execute
>> >
>> >
>> > ' Enumerate the resulting recordset.
>> > Do Until adoRecordset.EOF
>> >
>> >    ' Retrieve values and display.
>> >    strDN = adoRecordset.Fields("distinguishedName").Value
>> >
>> >    enumMembers getGroup(strDN,strGroupName),  ""
>> >    adoRecordset.MoveNext
>> > Loop
>> > end if
>> > next
>> >
>> > ' Clean up.
>> >
>> > adoRecordset.Close
>> > adoConnection.Close
>> >
>> >
>> > Function getGroup(strQueryFrom,strGroupName)
>> >  Dim objConn, objRecSet, strQueryString
>> >  Const adsOpenStatic = 3
>> >
>> >   Set objConn = wscript.CreateObject("ADODB.Connection")
>> >   objConn.Provider = "ADsDSOObject"
>> >   objConn.Open
>> > wscript.echo strQueryFrom
>> >   strQueryString = "SELECT * FROM 'LDAP://" & strQueryFrom & "' "  & "
>> > WHERE samAccountName =  '" & strGroupName & "'"
>> >
>> >   Set objRecSet = wscript.CreateObject("ADODB.Recordset")
>> >
>> >   objRecSet.Open strQueryString, objConn, adsOpenStatic
>> >
>> >    If objRecSet.recordCount = 1 Then
>> >    dim objFlds
>> >      for each objFlds In objRecSet.Fields
>> >        ' wscript.echo objFlds.Name
>> >      next
>> >      Set getGroup = GetObject(objRecSet("AdsPath"))
>> >
>> >    Else
>> >      wscript.echo "Record Cnt: " & objRecSet.recordCount & vbcrlf &
>> > "Query:
>> > " & strQueryString ' ucase(strGroupName) & " was not found in the
>> > domain.
>> > ("
>> > & objRootDSE.get("defaultNamingContext") & ")"
>> >      wscript.quit
>> >    End If
>> > End Function
>> >
>> >
>> > Sub enumMembers(byRef objGroup, strInheritedFrom)
>> > Dim objMember
>> >
>> >   For Each objMember In objGroup.Members
>> >     If lcase(objMember.class) = "group" Then
>> >     enumMembers objMember, objMember.samAccountName
>> >   Else
>> >     If objMember.displayname <> "" Then
>> >       If strInheritedFrom = "" Then
>> >         wscript.echo objMember.displayname
>> >       Else
>> >         wscript.echo objMember.displayname & " (From NESTED GROUP:  " &
>> > strInheritedFrom & ")"
>> >      End If
>> >    Else
>> >       If strInheritedFrom = "" Then
>> >        wscript.echo objMember.samAccountName
>> >     Else
>> >       wscript.echo objMember.samAccountName & " (From NESTED GROUP:  "
>> > &
>> > strInheritedFrom & ")"
>> >     End If
>> >   End If
>> > End If
>> >
>> > Next
>> > End Sub
>> >
>> > "Richard Mueller [MVP]" wrote:
>> >
>> >> If you run the script with the wscript host, Wscript.Echo commands
>> >> result
>> >> in
>> >> a message box with an OK button. However, if you use the cscript host,
>> >> Wscript.Echo echos to the console. If the VBScript program is called
>> >> Example.vbs, you can use a command similar to below at a command
>> >> prompt:
>> >>
>> >> cscript Example.vbs
>> >>
>> >> I often use the //nologo optional parameter to suppress the WSH logo
>> >> information, especially if I want to redirect the output to a text
>> >> file.
>> >> For
>> >> example:
>> >>
>> >> cscript //nologo Example.vbs > output.txt
>> >>
>> >> The above assumes you are in the directory where the file Example.vbs
>> >> is
>> >> saved. Otherwise, you have to specify the full path and file name in
>> >> the
>> >> command.
>> >>
>> >> I see that on most systems the default host is wscript, so if you just
>> >> run
>> >> the vbs file, wscript.exe is used and the Wscript.Echo statements
>> >> result
>> >> in
>> >> message boxes. This may be what you experience. For example, that most
>> >> likely happens if you enter:
>> >>
>> >> example.vbs
>> >> or
>> >> example
>> >>
>> >> The default host can be changed to cscript. My reference gives the
>> >> following
>> >> command to set the default to cscript:
>> >>
>> >> cscript //H:cscript //S
>> >>
>> >> The //S option saves this setting for the user. The command:
>> >>
>> >> cscript //I //nologo //H:cscript //S
>> >>
>> >> saves 3 options for the particular user (on this computer), the //I
>> >> option
>> >> specifies interactive mode (which I think is the default anywayt),
>> >> //nologo
>> >> suppresses the WSH logo information, //H:cscript assigns cscript.exe
>> >> as
>> >> the
>> >> default host, and //S saves the settings for the user.
>> >>
>> >> I don't alter the settings, since I've gotten into the habit of always
>> >> using
>> >> cscript. When I tried a VBScript program just now with no host
>> >> specified,
>> >> I
>> >> saw how annoying the default wscript.exe can be.
>> >>
>> >> --
>> >> Richard Mueller
>> >> Microsoft MVP Scripting and ADSI
>> >> Hilltop Lab - http://www.rlmueller.net
>> >> --
>> >>
>> >> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
>> >> news:379C3080-99DB-43AC-B8F7-955A878BE47C@microsoft.com...
>> >> > Yes, If i use the Wscript.Echo its giving alert with ok button. I am
>> >> > looking
>> >> > for the code which will displays the output to the console.
>> >> >
>> >> > "Richard Mueller [MVP]" wrote:
>> >> >
>> >> >>
>> >> >> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
>> >> >> news:8B3A9920-4D17-41FE-8069-8F3224F6F169@microsoft.com...
>> >> >> > Hi Mueller,
>> >> >> >
>> >> >> >   Thanks for your reply.
Author
16 Apr 2007 6:12 PM
Sriman
Hi Mueller,

  How to find out whether the group belongs to NT or LDAP?
right now, i am executing the group with LDAP, if any error comes, executing
the same group with winnt provider. I am sure, what am doing is wrong.  neer
your suggestion.

Regards,
Sri.

Show quote
"Richard Mueller [MVP]" wrote:

> The NT SAM account database is not LDAP compliant, so you must use the WinNT
> provider. However, since NT does not support nested domain groups, and the
> WinNT provider reveals the "primary" group, enumerating group membership is
> much simpler. Just bind to the group with the WinNT provider and use the
> Members method. All members are revealed. Also, NT only uses the NT names
> (NetBIOS names) of objects, so there is no conversion to Distinguished Name.
> In brief:
>
> ' Specify (or read) NetBIOS name of group and domain.
> strGroup = "Sales"
> strDomain = "MyDomain"
>
> ' Bind to group.
> Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
>
> ' Enumerate group members.
> For Each objMember In objGroup.Members
>     Wscript.Echo objMember.Name
> Next
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
> news:B6294B09-155E-4E58-8ABD-5C563ADD33FD@microsoft.com...
> > great help. now script working perfect. small question
> > will it handles the NTDomains also?
> >
> > "Richard Mueller [MVP]" wrote:
> >
> >> I have a hard time following your script. I assume that strDomainName is
> >> the
> >> DNS name of a domain, similar to "dc=MyDomain,dc=com". I say this because
> >> you use this as the base of an ADO query. I also assume that strGroupName
> >> is
> >> the NetBIOS name of a group, similar to "TestGroup". You then search for
> >> the
> >> object that has sAMAccountName equal to the value of strGroupName and
> >> retrieve the Distinguished Name of the group, strDN.
> >>
> >> However, you then pass strDN and strGroupName to function GetGroup, where
> >> I
> >> get lost. I think you should replace the statement:
> >>
> >> enumMembers getGroup(strDN, strGroupName), ""
> >>
> >> With the following:
> >>
> >> Set objGroup = GetObject("LDAP://" & strDN)
> >> enumMembers objGroup, ""
> >>
> >> If instead strDomainName is the NetBIOS name of a domain, and
> >> strGroupName
> >> is the NetBIOS name of a group, it would make more sense to use the
> >> NameTranslate object to convert these to the Distinguished Name of the
> >> group. For one domain and one group, the code would be similar to:
> >> =================
> >> ' Constants for the NameTranslate object.
> >>
> >> Const ADS_NAME_INITTYPE_GC = 3
> >> Const ADS_NAME_TYPE_NT4 = 3
> >> Const ADS_NAME_TYPE_1779 = 1
> >>
> >>
> >> ' Specify values, or parse from XML file.
> >> strDomainName = "MyDomain"
> >> strGroupName = "TestGroup"
> >>
> >> ' Use the NameTranslate object to convert the NT name to the
> >> ' Distinguished Name required for the LDAP provider.
> >> Set objTrans = CreateObject("NameTranslate")
> >>
> >>
> >> ' Initialize NameTranslate by locating the Global Catalog.
> >> objTrans.Init ADS_NAME_INITTYPE_GC, ""
> >>
> >>
> >> ' Use the Set method to specify the NT format of the object name.
> >> objTrans.Set ADS_NAME_TYPE_NT4, strDomainName & "\" & strGroupName
> >>
> >>
> >>
> >> ' Use the Get method to retrieve the RPC 1779 Distinguished Name.
> >> strGroup = objTrans.Get(ADS_NAME_TYPE_1779)
> >>
> >> ' Bind to the group object.
> >> Set objGroup = GetObject("LDAP://" & strGroupDN)
> >>
> >>
> >>
> >> enumMembers objGroup, ""
> >> ===============
> >> You could repeat this for each domain\group combination. I think you sub
> >> enumMembers should work.
> >>
> >> --
> >> Richard Mueller
> >> Microsoft MVP Scripting and ADSI
> >> Hilltop Lab - http://www.rlmueller.net
> >> --
> >>
> >> "Sriman" <Sri***@discussions.microsoft.com> wrote in message
> >> news:B8C8A71A-67BE-4E53-AA97-6AEF1E63861D@microsoft.com...
> >> > Thank you mueller. cscript worked fine to me.
> >> > Below is my code. my requirement is to display the members in the group
> >> > down to the user. input(domain\grpname) comes from the xml file. In
> >> > .net i
> >> > am
> >> > able to retrieve the user list down to the user. but here in vbscript i
> >> > am
> >> > able to list down the users of few groups in my domain. it will not
> >> > allow
> >> > me
> >> > to access the other domain users. I don't know the reason. no error is
> >> > coming. Please check my code and  suggest me the best way.
> >> >
> >> > Option Explicit
> >> >
> >> > Dim adoCommand, adoConnection, strBase, strFilter, strAttributes,
> >> > xmlDoc,
> >> > x,
> >> > WshNetwork, strComputer
> >> > Dim strDomainName, strNodeText, strXmlBuilder
> >> > Dim fso, res
> >> >
> >> > Dim strQuery, adoRecordset, strDN, strGroupName
> >> >
> >> > ' Setup ADO objects.
> >> >
> >> > Set adoCommand = CreateObject("ADODB.Command")
> >> > Set adoConnection = CreateObject("ADODB.Connection")
> >> > adoConnection.Provider = "ADsDSOObject"
> >> > adoConnection.Open "Active Directory Provider"
> >> > adoCommand.ActiveConnection = adoConnection
> >> >
> >> > Set WshNetwork = WScript.CreateObject("WScript.Network")
> >> > strComputer = UCase(WshNetwork.ComputerName)
> >> >
> >> > 'Set fso = CreateObject("Scripting.FileSystemObject")
> >> > 'Set res = fso.CreateTextFile(strComputer & ".xml", True)
> >> > 'strXmlBuilder = strXmlBuilder & "<?xml version=\"1.0\"
> >> > standalone=\"yes\"?>"
> >> > 'strXmlBuilder =    strXmlBuilder & "\n"  + "<WINNTGrps>"
> >> >
> >> > 'res.WriteLine "setmachine= & SerialNumber
> >> > 'res.Close
> >> >
> >> >
> >> > set xmlDoc=CreateObject("Microsoft.XMLDOM")
> >> > xmlDoc.async="false"
> >> > xmlDoc.load("groupstoberesolved.xml")
> >> >
> >> > for each x in xmlDoc.documentElement.childNodes
> >> >
> >> >  strNodeText = replace(x.text,"\","/")
> >> >
> >> >  if x.nodename <> "#comment" then
> >> >  Wscript.Echo "Node Name:" & x.nodename & vbcrlf & "Node Text:" &
> >> > strNodeText & vbcrlf & "Domain Name:" & _
> >> >   mid(x.text,1, InStr(strNodeText,"/")-1)  _
> >> >            & vbcrlf & "GroupName:" & mid(x.text,InStr(strNodeText,"/")
> >> > +
> >> > 1,
> >> > len(strNodeText))
> >> >
> >> > strDomainName = mid(x.text,1, InStr(strNodeText,"/")-1)
> >> > strGroupName = mid(x.text,InStr(strNodeText,"/") + 1, len(strNodeText))
> >> >
> >> > strBase = "<LDAP://" & strDomainName & ">"
> >> >
> >> > strFilter = "(&(|(objectClass=user)(objectclass=group))" &
> >> > "(sAMAccountName=" & strGroupName & "))"
> >> > strAttributes = "distinguishedName"
> >> >
> >> > ' Construct the LDAP syntax query.
> >> > strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
> >> > 'Wscript.Echo strQuery
> >> > adoCommand.CommandText = strQuery
> >> > adoCommand.Properties("Page Size") = 100
> >> > adoCommand.Properties("Timeout") = 30
> >> > adoCommand.Properties("Cache Results") = False
> >> >
> >> > ' Run the query.
> >> > Set adoRecordset = adoCommand.Execute
> >> >
> >> >
> >> > ' Enumerate the resulting recordset.
> >> > Do Until adoRecordset.EOF
> >> >
> >> >    ' Retrieve values and display.
> >> >    strDN = adoRecordset.Fields("distinguishedName").Value
> >> >
> >> >    enumMembers getGroup(strDN,strGroupName),  ""
> >> >    adoRecordset.MoveNext
> >> > Loop
> >> > end if
> >> > next
> >> >
> >> > ' Clean up.
> >> >
> >> > adoRecordset.Close
> >> > adoConnection.Close
> >> >
> >> >
> >> > Function getGroup(strQueryFrom,strGroupName)
> >> >  Dim objConn, objRecSet, strQueryString
> >> >  Const adsOpenStatic = 3
> >> >
> >> >   Set objConn = wscript.CreateObject("ADODB.Connection")
> >> >   objConn.Provider = "ADsDSOObject"
> >> >   objConn.Open
> >> > wscript.echo strQueryFrom
> >> >   strQueryString = "SELECT * FROM 'LDAP://" & strQueryFrom & "' "  & "
> >> > WHERE samAccountName =  '" & strGroupName & "'"
> >> >
> >> >   Set objRecSet = wscript.CreateObject("ADODB.Recordset")
> >> >
> >> >   objRecSet.Open strQueryString, objConn, adsOpenStatic
> >> >
> >> >    If objRecSet.recordCount = 1 Then
> >> >    dim objFlds
> >> >      for each objFlds In objRecSet.Fields
> >> >        ' wscript.echo objFlds.Name
> >> >      next
> >> >      Set getGroup = GetObject(objRecSet("AdsPath"))
> >> >
> >> >    Else
> >> >      wscript.echo "Record Cnt: " & objRecSet.recordCount & vbcrlf &
> >> > "Query:
> >> > " & strQueryString ' ucase(strGroupName) & " was not found in the
> >> > domain.
> >> > ("
> >> > & objRootDSE.get("defaultNamingContext") & ")"
> >> >      wscript.quit
> >> >    End If
> >> > End Function
> >> >
> >> >
> >> > Sub enumMembers(byRef objGroup, strInheritedFrom)
> >> > Dim objMember
> >> >
> >> >   For Each objMember In objGroup.Members
> >> >     If lcase(objMember.class) = "group" Then
> >> >     enumMembers objMember, objMember.samAccountName
> >> >   Else
> >> >     If objMember.displayname <> "" Then
> >> >       If strInheritedFrom = "" Then
> >> >         wscript.echo objMember.displayname
> >> >       Else
> >> >         wscript.echo objMember.displayname & " (From NESTED GROUP:  " &
> >> > strInheritedFrom & ")"
> >> >      End If
> >> >    Else
> >> >       If strInheritedFrom = "" Then
> >> >        wscript.echo objMember.samAccountName
> >> >     Else
> >> >       wscript.echo objMember.samAccountName & " (From NESTED GROUP:  "
> >> > &
> >> > strInheritedFrom & ")"
> >> >     End If
> >> >   End If
> >> > End If
> >> >
> >> > Next
> >> > End Sub
> >> >
> >> > "Richard Mueller [MVP]" wrote:
> >> >
> >> >> If you run the script with the wscript host, Wscript.Echo commands
> >> >> result
> >> >> in
> >> >> a message box with an OK button. However, if you use the cscript host,
> >> >> Wscript.Echo echos to the console. If the VBScript program is called
> >> >> Example.vbs, you can use a command similar to below at a command
> >> >> prompt:
> >> >>
> >> >> cscript Example.vbs
> >> >>
> >> >> I often use the //nologo optional parameter to suppress the WSH logo
> >> >> information, especially if I want to redirect the output to a text
> >> >> file.
> >> >> For
> >> >> example:
> >> >>
> >> >> cscript //nologo Example.vbs > output.txt
> >> >>
> >> >> The above assumes you are in the directory where the file Example.vbs
> >> >> is
> >> >> saved. Otherwise, you have to specify the full path and file name in
> >> >> the
> >> >> command.
> >> >>
> >> >> I see that on most systems the default host is wscript, so if you just
> >> >> run
> >> >> the vbs file, wscript.exe is used and the Wscript.Echo statements
> >> >> result
> >> >> in

AddThis Social Bookmark Button