How can I set the option to allow Active Directory dialing from LDAP using VBScript?

Active Directory has a tab called Dial-In, and under that tab is a radio button with three settings:

Allow Access
Deny Access
Control access through remote access policy

      

I would like to write VBScript to take a username and return the settings for that user. (I am actually modifying existing VBScript, so I am forced to use this tool).

What's the best way to do this?

+1


a source to share


1 answer


Here is the best solution I could think of. It is easy to change it to bring the setting to all users.



Main

Function Main
  'Usage: cscript /nologo lookup.vbs mydomain username
  Wscript.Echo CanDialIn(Wscript.Arguments(0), Wscript.Arguments(1))
  Main = 0
End Function

Function CanDialIn(domainname, username)
  'Take a user name and query whether they have permission to Dial in or not
  'http://www.microsoft.com/technet/scriptcenter/resources/qanda/aug05/hey0825.mspx
  Const ADS_SCOPE_SUBTREE = 2
  Dim objConnection
  Dim objCommand
  Dim objRecordSet

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

  objCommand.Properties("Page Size") = 1000
  objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

  'Three possible values for msNPAllowDialin:
  'TRUE = "Allow Access"
  'FALSE = "Deny Access"
  'EMPTY = "Control access through remote access policy"
  objCommand.CommandText = _
    "SELECT msNPAllowDialin FROM 'LDAP://dc=" & domainname & ",dc=com' WHERE objectCategory='user' AND sAMAccountName = '" & username & "'"
  On Error Resume Next
  Set objRecordSet = objCommand.Execute
  if objRecordSet.EOF then
    CanDialIn = "Could not find user " & username
  else
    if objRecordSet.Fields("msNPAllowDialin").Value = True then
      CanDialIn = "Allow"
    else
      if objRecordSet.Fields("msNPAllowDialin").Value = False then
        CanDialIn = "Deny"
      else
        CanDialIn = "Control"
      end if
    end if  
  end if
End Function

      

+2


a source







All Articles