Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Hta file to search the computer and user in the specific seat

Hi,

I always update the Ads Computers location and Users Office box with the location.
So when it comes to finding who is seated there it becomes difficult.Any way i have a Hta file that has a box where in i can type the Seat (Location) data and it gets both the user and the computer in the specific seat.
When seat no enered i need to get the users and computers all possible details on the screen

If they are not found then i can assume they are free seats and allot to some one.

In the last a 2 boxes  one for computer and other for User which can fetch all the users and computer seat no's with all possible details to a excel..
If required i can even check them on th excel...
Regards
Sharath
Avatar of RobSampson
RobSampson
Flag of Australia image

Sharath, for this one, I'm thinking we could just modify the one we used here:
https://www.experts-exchange.com/questions/22800311/Need-a-Hta-file-to-query-with-Description-of-all-ADS-users.html

Is that the same information you would want to display, given a seat number?

Regards,

Rob.
Avatar of bsharath

ASKER

Yes Rob exactly corect...
Rob these are some Questions that have not been commented till end...Can you please have a look and see if you can help on this... Sorry to trouble you so much... I am not able to help reducing asking questions as there is so much requirment for such solutions as man power here is so limited and so much jobs to do.And easy ways to do a job as you provide is so useful to us that we are able to manage with such less man power with working time also reduced.

https://www.experts-exchange.com/questions/22898775/Login-script-to-get-all-possible-details-from-the-machine.html
https://www.experts-exchange.com/questions/22893275/Add-Administrator-to-the-defalt-shares-in-the-remote-machine.html
https://www.experts-exchange.com/questions/22911941/Create-Users-and-Contact-with-1-script.html
https://www.experts-exchange.com/questions/22908282/Login-script-that-can-update-the-today's-installed-softwares-to-a-csv-file-with-the-sheetname-to-todays-date.html
https://www.experts-exchange.com/questions/22912145/Ads-to-update-just-what-is-mentioned-in-the-excel.html
Hope you will undersatnd...:-)
OK Sharath, I'll have a look when I get a chance....perhaps tomorrow....

Is the Seat Number is the Location field of a Computer Object, or the Office location of a User object, and is there any more data in that same field, or is it just a number?

Regards,

Rob.
For the Computers its the Location tab
For the Users its the office tab
So when the location entered in the HTa it has to query the above two fields and get all the rest data
Sharath, this should work for Users details, but I need to think about how to combine users details and computer details......would you happy for me to use a radio button, and you select whether your search is on a computer, or on a user?  While still complicated, that would be the easiest......


<head>
<title>User and Computer Information</title>
<HTA:APPLICATION
     APPLICATIONNAME="User and Computer Information"
     BORDER="thin"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
>
</head>

<script language="VBScript">

' Global variables
Dim arrRows

Sub Window_OnLoad
      intWidth = 800
      intHeight = 600
      Me.ResizeTo intWidth, intHeight
      Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
      btnFirstEvent.Disabled = True
      btnPreviousEvent.Disabled = True
      btnNextEvent.Disabled = True
      btnLastEvent.Disabled = True
      btnFirstEvent.Style.Visibility = "Hidden"
      btnPreviousEvent.Style.Visibility = "Hidden"
      btnNextEvent.Style.Visibility = "Hidden"
      btnLastEvent.Style.Visibility = "Hidden"
End Sub

Sub Default_Buttons
      If Window.Event.KeyCode = 13 Then
            btn_submit.Click
      End If
End Sub

Sub Submit_Form

      txt_name.Value = ""
      txt_loginname.Value = ""
      txt_email.Value = ""
      txt_empid.Value = ""
      txt_designation.Value = ""
      txt_extensionno.Value = ""
      txt_mobileno.Value = ""
      txt_manager.Value = ""
      txt_department.Value = ""
      span_currentrecord.InnerHTML = "0"
      span_totalrecords.InnerHTML = "0"

      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.
      Set objRootDSE = GetObject("LDAP://RootDSE")
      
      strDNSDomain = objRootDSE.Get("defaultNamingContext")
      strBase = "<LDAP://" & strDNSDomain & ">"

      strFilter = "(&(objectCategory=person)(objectClass=user)(physicalDeliveryOfficeName=" & txt_seatnumsearch.Value & "))"
      'strFilter = "(&(objectClass=computer)(cn=" & strComputer & "))"
      
      ' Comma delimited list of attribute values to retrieve.
      strAttributes = "cn,samAccountName,mail,description,Title,TelephoneNumber,Mobile,Manager,Department"
      
      ' 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.
      strDetails = ""
      If Not adoRecordset.EOF Then
            Do Until adoRecordset.EOF
                  If strDetails = "" Then
                        strDetails = Replace(adoRecordset.Fields("cn").Value, "CN=", "") &_
                                          "|TD|" & adoRecordset.Fields("samAccountName").Value &_
                                          "|TD|" & adoRecordset.Fields("mail").Value &_
                                          "|TD|" & Join(adoRecordset.Fields("description").Value) &_
                                          "|TD|" & adoRecordset.Fields("Title").Value &_
                                          "|TD|" & adoRecordset.Fields("TelephoneNumber").Value &_
                                          "|TD|" & adoRecordset.Fields("Mobile").Value
                                          If IsNull(adoRecordset.Fields("Manager").Value) = False Then
                                                strDetails = strDetails & "|TD|" & Replace(Split(adoRecordset.Fields("Manager").Value, ",")(0), "CN=", "")
                                          Else
                                                strDetails = strDetails & "|TD|"
                                          End If
                                          strDetails = strDetails & "|TD|" & adoRecordset.Fields("Department").Value
                  Else
                        strDetails = strDetails & "|TR|" & Replace(adoRecordset.Fields("cn").Value, "CN=", "") &_
                                          "|TD|" & adoRecordset.Fields("samAccountName").Value &_
                                          "|TD|" & adoRecordset.Fields("mail").Value &_
                                          "|TD|" & Join(adoRecordset.Fields("description").Value) &_
                                          "|TD|" & adoRecordset.Fields("Title").Value &_
                                          "|TD|" & adoRecordset.Fields("TelephoneNumber").Value &_
                                          "|TD|" & adoRecordset.Fields("Mobile").Value
                                          If IsNull(adoRecordset.Fields("Manager").Value) = False Then
                                                strDetails = strDetails & "|TD|" & Replace(Split(adoRecordset.Fields("Manager").Value, ",")(0), "CN=", "")
                                          Else
                                                strDetails = strDetails & "|TD|"
                                          End If
                                          strDetails = strDetails & "|TD|" & adoRecordset.Fields("Department").Value
                  End If
                adoRecordset.MoveNext
            Loop
      Else
            MsgBox "No records were found"
      End If
      
      ' Clean up.
      adoRecordset.Close
      Set adoRecordset = Nothing
      
      adoConnection.Close

      If strDetails <> "" Then
            arrRows = ""
            arrRows = Split(strDetails, "|TR|")
            If UBound(arrRows) < 0 Then
                  span_currentrecord.InnerHTML = "0"
                  span_totalrecords.InnerHTML = "0"
            Else
                  arrData = Split(arrRows(0), "|TD|")
                  txt_name.Value = arrData(0)
                  txt_loginname.Value = arrData(1)
                  txt_email.Value = arrData(2)
                  txt_empid.Value = arrData(3)
                  txt_designation.Value = arrData(4)
                  txt_extensionno.Value = arrData(5)
                  txt_mobileno.Value = arrData(6)
                  txt_manager.Value = arrData(7)
                  txt_department.Value = arrData(8)
                  span_currentrecord.InnerHTML = "1"
                  span_totalrecords.InnerHTML = UBound(arrRows) + 1
            End If
      Else
            span_currentrecord.InnerHTML = "0"
            span_totalrecords.InnerHTML = "0"
      End If
      If strDetails = "" Then
            btnFirstEvent.Disabled = True
            btnPreviousEvent.Disabled = True
            btnNextEvent.Disabled = True
            btnLastEvent.Disabled = True      
            btnFirstEvent.Style.Visibility = "Hidden"
            btnPreviousEvent.Style.Visibility = "Hidden"
            btnNextEvent.Style.Visibility = "Hidden"
            btnLastEvent.Style.Visibility = "Hidden"
      ElseIf UBound(arrRows) = 0 Then
            btnFirstEvent.Disabled = True
            btnPreviousEvent.Disabled = True
            btnNextEvent.Disabled = True
            btnLastEvent.Disabled = True
            btnFirstEvent.Style.Visibility = "Hidden"
            btnPreviousEvent.Style.Visibility = "Hidden"
            btnNextEvent.Style.Visibility = "Hidden"
            btnLastEvent.Style.Visibility = "Hidden"
      Else
            btnFirstEvent.Disabled = False
            btnPreviousEvent.Disabled = False
            btnNextEvent.Disabled = False
            btnLastEvent.Disabled = False
            btnFirstEvent.Style.Visibility = "Visible"
            btnPreviousEvent.Style.Visibility = "Visible"
            btnNextEvent.Style.Visibility = "Visible"
            btnLastEvent.Style.Visibility = "Visible"
      End If
End Sub

Sub Get_Event

      arrData = Split(arrRows(span_currentrecord.InnerHTML - 1), "|TD|")
      txt_name.Value = arrData(0)
      txt_loginname.Value = arrData(1)
      txt_email.Value = arrData(2)
      txt_empid.Value = arrData(3)
      txt_designation.Value = arrData(4)
      txt_extensionno.Value = arrData(5)
      txt_mobileno.Value = arrData(6)
      txt_manager.Value = arrData(7)
      txt_department.Value = arrData(8)

End Sub

Sub First_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If txt_seatnumsearch.Value = "" Then
                  MsgBox "Please enter an employee id number to search for."
            ElseIf span_totalrecords.InnerHTML < 1 Then
                  MsgBox "There are no records to display"
            ElseIf span_currentrecord.InnerHTML = 1 Then
                  MsgBox "You are already viewing the first record."
            Else
                  span_currentrecord.InnerHTML = 1
                  Get_Event
            End If
      End If
      
End Sub

Sub Previous_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If span_currentrecord.InnerHTML > 1 Then
                  span_currentrecord.InnerHTML = span_currentrecord.InnerHTML - 1
                  Get_Event
            ElseIf span_currentrecord.InnerHTML = 1 Then
                        MsgBox "You are already viewing the first record."
            ElseIf txt_seatnumsearch.Value = "" Then
                  MsgBox "Please enter an employee id number to search for."
            Else
                  MsgBox "There are no records to display"
            End If
      End If

End Sub

Sub Next_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If txt_seatnumsearch.Value = "" Then
                  MsgBox "Please enter an employee id number to search for."
            ElseIf span_totalrecords.InnerHTML = 0 Then
                  MsgBox "There are no records for to display"
            ElseIf span_currentrecord.InnerHTML = span_totalrecords.InnerHTML Then
                  MsgBox "You are already viewing the last record."
            Else
                  span_currentrecord.InnerHTML = span_currentrecord.InnerHTML + 1
                  Get_Event
            End If
      End If
      
End Sub

Sub Last_Event
      
      If IsArray(arrRows) = False Then
            MsgBox "There are no records to display."
      Else
            If txt_seatnumsearch.Value = "" Then
                  MsgBox "Please enter an employee id number to search for."
            ElseIf span_totalrecords.InnerHTML = 0 Then
                  MsgBox "There are no records to display"
            ElseIf span_currentrecord.InnerHTML = span_totalrecords.InnerHTML Then
                        MsgBox "You are already viewing the last record."
            Else
                  span_currentrecord.InnerHTML = span_totalrecords.InnerHTML
                  Get_Event
            End If
      End If
      
End Sub

</script>

<body STYLE="font:14 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')" onkeypress='vbs:Default_Buttons'>
      <table width='90%' height = '100%' align='center' border='0'>
            <tr>
                  <td align='center' colspan="2">
                        <h3>User and Computer Information</h3><br>
                  </td>
            </tr
            <tr>
                  <td align="right">
                        Enter a Seat Number:
                  </td>
                  <td>
                        <input type="text" maxlength="6" size="10" id="txt_seatnumsearch" name="txt_seatnumsearch">
                        &nbsp&nbsp&nbsp&nbsp&nbsp<input type="button" value="Submit" name="btn_submit"  onClick="vbs:Submit_Form">
                  </td>
            </tr>
            <tr>
                  <td align='center' colspan="2">
                        <table>
                              <tr>
                                    <td>
                                          User Name:
                                    </td>
                                    <td>
                                          <input type="text" maxlength="30" size="40" id="txt_name" name="txt_name">
                                    </td>
                              </tr>
                              <tr>
                                    <td>
                                          Login Name:
                                    </td>
                                    <td>
                                          <input type="text" maxlength="30" size="40" id="txt_loginname" name="txt_loginname">
                                    </td>
                              </tr>
                              <tr>
                                    <td>
                                          Email Address:
                                    </td>
                                    <td>
                                          <input type="text" maxlength="50" size="70" id="txt_email" name="txt_email">
                                    </td>
                              </tr>
                              <tr>
                                    <td>
                                          Emp ID:
                                    </td>
                                    <td>
                                          <input type="text" maxlength="6" size="10" id="txt_empid" name="txt_empid">
                                    </td>
                              </tr>
                              <tr>
                                    <td>
                                          Designation:
                                    </td>
                                    <td>
                                          <input type="text" maxlength="50" size="70" id="txt_designation" name="txt_designation">
                                    </td>
                              </tr>
                              <tr>
                                    <td>
                                          Extension No:
                                    </td>
                                    <td>
                                          <input type="text" maxlength="4" size="10" id="txt_extensionno" name="txt_extensionno">
                                    </td>
                              </tr>
                              <tr>
                                    <td>
                                          Mobile Number:
                                    </td>
                                    <td>
                                          <input type="text" maxlength="14" size="20" id="txt_mobileno" name="txt_mobileno">
                                    </td>
                              </tr>
                              <tr>
                                    <td>
                                          Manager:
                                    </td>
                                    <td>
                                          <input type="text" maxlength="50" size="70" id="txt_manager" name="txt_manager">
                                    </td>
                              </tr>
                              <tr>
                                    <td>
                                          Department:
                                    </td>
                                    <td>
                                          <input type="text" maxlength="30" size="50" id="txt_department" name="txt_department">
                                    </td>
                              </tr>
                              <tr>
                                    <td colspan="2" align="center">
                                          <br>Showing record&nbsp
                                          <span id="span_currentrecord">
                                          0
                                          </span>
                                          &nbspof&nbsp
                                          <span id="span_totalrecords">
                                          0
                                          </span>
                                          <br>
                                          <input type='button' value='||< First' name='btnFirstEvent'  onClick='vbs:First_Event'>&nbsp&nbsp&nbsp&nbsp&nbsp
                                          <input type='button' value='<< Previous' name='btnPreviousEvent'  onClick='vbs:Previous_Event'>&nbsp&nbsp&nbsp&nbsp&nbsp
                                          <input type='button' value='Next >>' name='btnNextEvent'  onClick='vbs:Next_Event'>&nbsp&nbsp&nbsp&nbsp&nbsp
                                          <input type='button' value='Last >||' name='btnLastEvent'  onClick='vbs:Last_Event'>
                                    </td>
                              </tr>
                        </table>
                  </td>
            </tr>
      </table>
</body>
Rob but this HTA would be to search a detail.
Like when i give the seat as "HC-2F-001"

Then the user detail and the computer which is there has to be displayed only thn it would match.

If you feel it will take too much of time then i have no problem.
You can give me 2 boxes for the search.
Is it possible to give me check boxes as at the same time i can select box boxes so that the HTA can get both details on the same screen.
Rob th characters for seat has to be max 16 char.

I understand....the problem is that it's pretty two independant recordsets, and two completely different searches, for the user and computer information.  So, let's say you search for "user" details by a seat, then I add the Notes field to the list of info, so you can see the computer name.  Then, you'd have to manually click the Computer option to search by, enter the same seat number, and click Search, and then see if the computer that is displayed matches....

Would that be OK?  It will still take some time to build, but I can do it.

Regards,

Rob.
Ok Rob that's fine...Even this way i can get what i need...Thanks...
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Rob GM,

For the user i get all the details quering the seat no.
But for computer when i put the same seat no it says no records.
I made sure that a machine has the same location set to the seat no.But shows no records...
Is the seat number in the location field?  And does that field in the AD have only the data you search for?

I have made it search for
*<seatnum>

meaning anything can be written before the text to search for, but not after....

Regards,

Rob.
Yes Rob in the Computers properties > Location tab i have the seat no's like this.

FC-7F-001

So when i give this as the search criteria selecting the computer "FC-7F-001" I get nothing.
But there is data in the location tab
That's strange.  When I click the Computer radio button to search by, and in my AD I have
FC-7F-001
as the Location, then in the "Enter a seat number" box in the HTA, I put
FC-7F-001
and click Submit, I get my computer name show up......

Seems weird, I can't re-create your problem.....

Rob.
Sorry for the trouble Rob..

I tried so many times and it did not show the machine name.And now when i tried i shows exactly.

Thanks a lot Rob...

Hmmmm....maybe it had to replicate, if you just made the change recently?

Anyway, glad it works for you.

Rob.
Rob in this Q...
https://www.experts-exchange.com/questions/22898775/Login-script-to-get-all-possible-details-from-the-machine.html
Just a little Tweeking required.It works fine for 1 computer but not for all...Any help...