How can i convert a asp VB script into a VB script.

Posted on 2008-10-17
Last Modified: 2011-09-20
What this script does is it shows the user account that is logged on and there phone number from active directory.

I have this code working in asp.
but i cannot get the code to work in

Can someone help me out.

<%Option Explicit%>



 ' Check to see if the session variable is already populated.

  If Session("LOGON_USER") = "" Then

    ' Check to see if the user has logged on at all.

    If Request.ServerVariables("LOGON_USER") = "" Then

      ' Force authentication if not.


      Response.Status = "401 Access Denied"



      ' Store the client's user name in a session variable.

      Session("LOGON_USER") = Request.ServerVariables("LOGON_USER")

      ' Strip out an NT domain from the user name.

      If InStr(Session("LOGON_USER"),"\") then

                    Session("LOGON_USER") = Mid(Session("LOGON_USER"), InStr(Session("LOGON_USER"), "\") + 1)


      End If

    End If

  End If

Function getADUserInfo(strUID)

        on error resume next

        strGeneralLookupError = false

    strBase = "<LDAP://DC=[domain], DC=[domain ext ie local or com]>"

        strFilter = "(sAMAccountName=" & strUID & ")" 

        strAttributes = "cn, mail, company, givenName, sn, ADsPath, name, sAMAccountName, telephoneNumber"

        'strAttributes = "cn, company, givenName, sn, ADsPath, name, sAMAccountName, telephoneNumber"

        strScope = "subtree"    

        strFullCommand = strBase & ";" & strFilter & ";" & strAttributes & ";" & strScope

        set rsADUserInfo = Server.CreateObject("ADODB.Recordset")

        set     rsADUserInfo = connAD.Execute(strFullCommand)

        if err.number <> 0 then

                strGeneralLookupError = true

        end if

        set getADUserInfo = rsADUserInfo

        set rsADUserInfo = Nothing

End Function


Sub getUserData(p_strUserID)

        on error resume next

        set rsUserData = Server.CreateObject("ADODB.Recordset")

        set rsUserData = getADUserInfo(p_strUserID)

        if not rsUserData.EOF then

                strUserGN = rsUserData("givenName")

                strUserSN = rsUserData("sn")

                strUserOU = rsUserData("company")

                strUserEmail = rsUserData("mail")

                strUserPhone = rsUserData("telephoneNumber")


                strADLookupSuccess = false

        end if


        set rsUserData = Nothing

End Sub


on error resume next


response.expires = 0


DIM connAD, rsUserData, rsADUserInfo

DIM strUserGN, strUserSN, strUserOU, strUserEmail, strUserPhone

DIM strBase, strFilter,strAttributes, strScope, strFullCommand

DIM strGeneralLookupError, strADLookupSuccess

DIM strUserID


strUserGN = "The user can not be found in the system."

strGeneralLookupError = false

strADLookupSuccess = true


set connAD = Server.CreateObject("ADODB.Connection")

connAD.Provider = "ADsDSOObject"

connAD.Properties("User ID") = "[domain]\[user account]" ' ### remember to make sure this user has rights to access AD

connAD.Properties("Password") = "[password]"

connAD.Properties("Encrypt Password") = true



strUserID = Session("LOGON_USER")

call getUserData(strUserID)



set connAD = Nothing





<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">

<title>ASP Code to access AD with LDAP Page</title>




<%=strUserSN%><br />

<%=strUserOU%><br />

<%=strUserEmail%><br />

<%=strUserPhone%><br />



Open in new window

Question by:phoenixfire425

Accepted Solution

maXXXeE earned 125 total points
ID: 22739954
For a start, uses VB.Net or C# and not VBScript.

ASP.Net is a very different thing compared to  ASP 3(or classic asp), u cant just copy the asp3 code and get it running.

u could check out this url

Author Comment

ID: 22950035
Thank you that was a little useful

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: and…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now