We help IT Professionals succeed at work.

I need to test this code on Windows server 2000 or 2003?!

Abdu_Allah asked
Medium Priority
Last Modified: 2013-12-23
Hi, While Windows server 2000 or 2003 is not available for me so I need to test this ASP code on it, this code is just authenticate users against Active Directory and if there an error it writes on the screen otherwise it will write login success:

Just create new asp file and name it as "testad.asp" and put the following code in it.


     On Error Resume next
     Dim ErrorMessege

    function IsAdmin(Domain, Username)
          'Set grp = GetObject("WinNT://" & Domain & "/" & "Domain Administrators" & ",group")
          'If (grp.IsMember("WinNT://" & Domain & "/" & Username)) Then
          '                    IsAdmin = true
          '                    Set grp = nothing
          '                    exit function
          '          Set grp = nothing
          '          IsAdmin = false
          'End If

          Set grp = Getobject("WinNT://" & Domain & "/" & "Domain Administrators" & ",group")
          For Each member In grp.Members
             if lcase(member.Name) = lcase(Username) then
                   IsAdmin = true
                    Set grp = nothing
                    exit function
              end if
               If (member.Class = "Group") Then
                         For Each obj In member.Members
                              if lcase(obj.Name) = lcase(Username) then
                                   IsAdmin = true
                                   Set grp = nothing
                                   exit function
                              end if
                End If          
          Set grp = nothing
         IsAdmin = false
     end function

    function ValidateLoginAgainstActiveDirectory(Domain, Username, Password, byref txtErr)

               Dim SCRIPT_NAME
               if Domain = "" then
                    txtErr = "Domain name cannot be empty"
                    ValidateLoginAgainstActiveDirectory = false
                    exit function
               elseif Username = "" then
                    txtErr = "User name cannot be empty"
                    ValidateLoginAgainstActiveDirectory = false
                    exit function
               elseif Password = "" then
                    txtErr = "Password cannot be empty"
                    ValidateLoginAgainstActiveDirectory = false
                    exit function
               end if
               Const ADS_SECURE_AUTHENTICATION = 1
             On Error Resume Next
             Dim authNamespace, authObject
             Set authNamespace = GetObject("WinNT:")
               Set authObject = authNamespace.OpenDSObject("WinNT://" & Domain, Username, Password, ADS_SECURE_AUTHENTICATION)
             If Err.Number <> 0 Then
                       ' Authentication process failed
                    txtErr = "Error Number 3: Wrong User ID or Password"
                    ValidateLoginAgainstActiveDirectory = False
                    exit function

                    ' Authentication process succeseded
                    Set authNamespace = Getobject("WinNT://" & Domain & "/" & Username & ",user")
                    If Err.Number <> 0 Then
                              response.write "<font color=""red"">Error Number 4: " & Err.Description & "</font><br>"
                    end if
                    'response.write authNamespace.Homedirectory
                    'If Err.Number <> 0 Then
                       ' Authentication process failed
                    'response.write "error"
                    'ValidateLoginAgainstActiveDirectory = False
                    'end if
                    'Check if user's homedirectory is not empty
                    response.write authNamespace.Homedirectory & "<br>"
                    if IsAdmin(Domain,Username) then
                       response.write "The user is admin"
                    end if
                    ValidateLoginAgainstActiveDirectory = True
             End If
             Set authNamespace = Nothing
             Set authObject = Nothing


    End function

    'Get System configuration

    function TrueFalse(cond)
          if cond = true then
               TrueFalse = "Y"
               TrueFalse = "N"
          end if
    end function

    Dim sText
     IsPostBack = Request.Form("dologin")

     if usr_name = "" then
          usr_name = Request.Form("id")
          pass = Request.Form("pwd")
          domain = Request.Form("Domain")
     end if
   if  usr_name <> "" Then
                        ValidUser = ValidateLoginAgainstActiveDirectory(domain, usr_name, pass,ErrorMessege)
                    if ValidUser = True  Then
                        'It is OK!!!
                        Response.write "Login success"

                              sText = ErrorMessege
                              if sText  <> "" then
                                        sText = "<font color=""red"">" & ErrorMessege & "</font>"
                                        sText = "<font color=""red"">Wrong User ID or Password</font>"
                                   end if
                              Response.Write sText
                     End if
    End if%>

               <link href="filemanager.css" rel="stylesheet" type="text/css">
                  <META http-equiv="Content-Language" content="en">
              <META http-equiv="Content-Type" content="text/html; charset=windows-1252">
              <TITLE>You need To login</TITLE>
         <BODY TOPMARGIN="40" >
         Dim sURL
         sURL = Request.ServerVariables("SCRIPT_NAME")
         if Request.ServerVariables("QUERY_STRING") <> "" Then
              sURL = sURL & "?" & Request.ServerVariables("QUERY_STRING")
         End if

    <table cellpadding="0" cellspacing="0" align="center" width="231" >

       <tbody><tr width="100%">
        <td width="231"  >&nbsp;</td>
     <table border="1" bordercolorlight="#c0c0c0" width="231" cellpadding="0" cellspacing="0"  align="center">
     <tr><td id="loginForm" width="100%">
          <form name="form2" action="testad.asp" method="post">          
          <p>       &nbsp; Enter login name and password.</p>
          <input name="login_name" type="hidden" >
               <table  cellspacing="0" >
                              <td class="name" width="30%"><label for="login_name"><INPUT type="hidden" name="dologin" value="yes">
                    &nbsp;<B> Login</B></label></td>
                    <td width="70%"><INPUT name="id" id="login_name" maxlength="501" tabindex="1"

                    <td class="name" width="30%"><label for="passwd">&nbsp;<B> Password</B></label></td>
                    <td width="70%"><INPUT name="pwd" id="passwd" maxlength="14" tabindex="2" type="password"></td>
                    <td class="name" width="30%"><label for="Domain">&nbsp;<B> Domain</B></label></td>
                    <td width="70%">  <select name="Domain" id="Domain"  tabindex="3" onChange="MM_jumpMenu('parent',this,1)">
                                              'fill domain names in drop down list
                                               Set objIADsContainer = GetObject("WinNT:")
                                               If Err.Number <> 0 Then
                                                       response.write "<font color=""red"">Error Number 1: " & Err.Description & "</font><br>"
                                               end if
                                               objIADsContainer.Filter = Array("domain")
                                               For Each objIADsDomain In objIADsContainer
                                                  'response.write "<option >" & objIADsDomain.name & "</option>"
                                                  response.write "<option >" & objIADsDomain.name & "</option>"
                                               If Err.Number <> 0 Then
                                                       response.write "<font color=""red"">Error Number 2: " & Err.Description & "</font><br>"
                                               end if
                                                  'response.write "<option >" & "USER-89DC93EC9A"& "</option>"
                                               Set objIADsDomain = Nothing
                                               Set objIADsContainer = Nothing%>
               <tr align="middle">
                              <td class="name"></td>
                             <TD align="middle"><P><INPUT class="button" type="submit" value="Login" name="B1" style="WIDTH: 102px; HEIGHT: 23px" size="50"></P></TD>
               </tr>     </table>          
Watch Question

As harmless as this probably is, I'm not a big fan of running scripts from unknown sources on a server of mine.  However, I did want to pass along some info that you may find useful.

You can download and install a 180 day trial version of Windows Server 2003 R2, Enterprise Edition from Microsoft.  All you need is a spare PC (or a spare hard drive to throw in an existing PC) to install this and test as much as you want.  Here's the link:


I actually downloaded this myself about two weeks ago to set up a server at home to play with MS Virtual Server 2005.  I just threw another hard drive in one of my PCs and installed it to that drive.

Just a thought.


Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


>or a spare hard drive to throw in an existing PC

Actually this is a good thought but can I install Windows Server 2003 on another hard disk while XP is installed on the first disk?! if so how can I do that?!
Yes, but I wouldn't have both drives "active" at the same time.  I do this on a PC I have at home right now.  I have two hard drives, but only one is plugged in with the power and IDE cables at a time.  So right now the drive with my Windows 2003 trial server is plugged in so I can experiment with Virtual Server 2005 R2.  When I need to boot XP back up, I shut down the PC, open the case, unplug the drive with 2003, and plug in the drive with XP.  

Speaking of virtual server...  if you wanted to have a PC with several operating systems running at the same time, you might want to consider Microsoft's Virtual PC 2004 or Virtual Server 2005.  Either that or VMWare's GSX product (which I believe is free now).  This way you could run multiple OS's on the same hardware AT THE SAME TIME.  Just make sure you have enough RAM. :)

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.