We help IT Professionals succeed at work.
Get Started

Rename computer HTA Script HELP!!!

597 Views
Last Modified: 2014-05-14
I am trying to create a HTA script for renaming computers with multiple drop-down menus. First menu will ask for the campus name, one of 11 buildings. Upon selection of campus the second drop-down will populate with room numbers, which the numbering scheme is different for each campus. I.E. campus one has letters in their room number, the second campus is rooms 1-25, third campus is 100-150, and another campus does not have room "numbers" but the rooms are names. When the room number is selected, the third drop-down box will simply ask if the computer is a desktop or laptop. Next drop-down will ask if the computer is for a student or teacher. Finally, the last drop-down will ask for the computer number, which if it is a teacher computer, there will be no more than 6 computers in a room and if a student computer no more than 45 computers. After all drop-down menus have been selected then a text-box will show the crafted naming scheme which will allow the computer name to be changed for any special computers. So if I am in building 1 in room 3 with the fourth student desktop it will construct B1RM003DS04, rename computer with constructed name and reboot. Most of the computers will be on the domain already, but if not ask to join the domain as well. Also, it would be nice if it could check to see if the computer name generated is already taken before submitting the computer rename.
With what I have so far, when I run Generate Name (which I would like to make it automatically update every time a make a change to the drop down) instead of getting ALRMC01DT01 I get 1RM20111. I just don't know how to translate that. Once that is done, I would like to add a text box that automatically gets and displays current computer name for the rename process but allows you to type in another computer name for remote rename.
I have spent two frustrating days on this and as I just dabble in VBScript and HTA I am just at a loss.
 
I am wanting this because I am tired of our technicians renaming computers that do not fit our naming scheme.

<select id=sel_campus>
</select>
<select id=sel_room>
</select>
<select id=sel_computer>
</select>
<select id=sel_level>
</select>
<select id=sel_number>
</select>

<script language=vbscript>

option explicit

sub add_option (select_id, value, text)
dim opt : set opt = document.createelement("option")
opt.value = value
opt.text = text
select_id.add opt
set opt = nothing
end sub

sub load_combo (select_id, option_array)
dim i: for i = 0 to ubound(option_array)
add_option select_id, i, option_array(i)
next
end sub

sub clear_combo (select_id)
select_id.options.length = 0
end sub

dim campus : campus = array ("Campus", "Alamo", "Apache", "Intermediate", "Middle School", "High School", "Butz", "Food Services", "Central Office", "Maintenance / Bus Barn", "Special Services", "Technology")
load_combo sel_campus, Campus

dim alamo_rooms : alamo_rooms = split ("Room,A01,A02,A03,A04,A05,A06,A07,A08,A09,A10," _
& "B01,B02,B03,B04,B05,B06,B07,B08,B09," _
& "C01,C02,C03,C04,C05,C06,C07,C08,C09,C10,C11," _
& "D01,D02,D03,D04,D05,D06,D07,D08,D09,D10,D11", ",")
dim apache_rooms : apache_rooms = split ("Room,001,002,003,004,005,006,007,008,009,010," _
& "011,012,013,014,015,016,017,018,019,020," _
& "021,022,023,024,025,326,327,328,329,330," _
& "331,332,333,334,335",",")
dim intermediate_rooms : intermediate_rooms = split ("Room,001,002,003,004,005,006,007,008,009,010," _
& "010,012,013,014,015,016,017,018,019,020," _
& "021,022,023,024,025,026,027,028",",")
dim ms_rooms : ms_rooms = split ("Room,101,102,103,104,105,106,107,108,109,110," _
& "111,112,113,114,115,116,117,118,119,120," _
& "121,122,123,124,125,126,127,128,129,130," _
& "131,132,133,134,135,136,137,138,139,140," _
& "141,142,143,144,145,146,147,148,149,150,151",",")
dim hs_rooms : hs_rooms = split ("Room,001,002,003,004,005,006,007,008,009,010," _
& "010,012,013,014,015,016,017,018,019,020," _
& "021,022,023,024,025,026,027,028,029,030," _
& "031,31A,032,033,034,035,036,037,038,039,040," _
& "041,042,043,044,045,046,047,048,049,050,051,052",",")


dim com_num : com_num = split ("Computer Number,01,02,03,04,05,06,07,08,09,10," _
& "10,12,13,14,15,16,17,18,19,20," _
& "21,22,23,24,25,26,27,28,29,30," _
& "31,32,33,34,35,36,37,38,39,40," _
& "41,42,43,44,45,46,47,48,49,50,51,52",",")
Dim com_level : com_level = Split ("User Type,Teacher,Student",",")
Dim com_type : com_type = Split ("Computer Type,Desktop,Laptop",",")

sub sel_campus_onchange
clear_combo sel_room
select case sel_campus.text
Case 0 'Campus
Case 1 'Alamo
load_combo sel_room, alamo_rooms
Case 2 'Apache
load_combo sel_room, apache_rooms
Case 3 'Intermediate
load_combo sel_room, intermediate_rooms
Case 4 'Middle School
load_combo sel_room, ms_rooms
Case 5 'High School
load_combo sel_room, hs_rooms
Case 6 'Butz
load_combo sel_room, alamo_rooms
Case 7 'Food Services
load_combo sel_room, alamo_rooms
Case 8 'Central Office
load_combo sel_room, alamo_rooms
Case 9 'Maintenance / Bus Barn
load_combo sel_room, alamo_rooms

End select
end Sub

sub sel_room_onchange
clear_combo sel_computer
select case sel_room.value
Case 0 'Room Numbers
case 1 'Room 1
load_combo sel_computer, com_type
Case 2 'Room 2
load_combo sel_computer, com_type
Case 3 'Room 3
load_combo sel_computer, com_type
Case 4 'Room 4
load_combo sel_computer, com_type
Case 5 'Room 5
load_combo sel_computer, com_type
Case 6 'Room 6
load_combo sel_computer, com_type
Case 7 'Room 7
load_combo sel_computer, com_type
Case 8 'Room 8
load_combo sel_computer, com_type
Case 9 'Room 9
load_combo sel_computer, com_type
Case 10 'Room 10
load_combo sel_computer, com_type
Case 11 'Room 11
load_combo sel_computer, com_type
Case 12 'Room 12
load_combo sel_computer, com_type
Case 13 'Room 13
load_combo sel_computer, com_type
Case 14 'Room 14
load_combo sel_computer, com_type
Case 15 'Room 15
load_combo sel_computer, com_type
Case 16 'Room 16
load_combo sel_computer, com_type
Case 17 'Room 17
load_combo sel_computer, com_type
Case 18 'Room 18
load_combo sel_computer, com_type
Case 19 'Room 19
load_combo sel_computer, com_type
Case 20 'Room 20
load_combo sel_computer, com_type
Case 21 'Room 21
load_combo sel_computer, com_type
Case 22 'Room 22
load_combo sel_computer, com_type
Case 23 'Room 23
load_combo sel_computer, com_type
Case 24 'Room 24
load_combo sel_computer, com_type
Case 25 'Room 25
load_combo sel_computer, com_type
Case 26 'Room 26
load_combo sel_computer, com_type
Case 27 'Room 27
load_combo sel_computer, com_type
Case 28 'Room 28
load_combo sel_computer, com_type
Case 29 'Room 29
load_combo sel_computer, com_type
Case 30 'Room 30
load_combo sel_computer, com_type
Case 31 'Room 31
load_combo sel_computer, com_type
Case 32 'Room 32
load_combo sel_computer, com_type
Case 33 'Room 33
load_combo sel_computer, com_type
Case 34 'Room 34
load_combo sel_computer, com_type
Case 35 'Room 35
load_combo sel_computer, com_type
Case 36 'Room 36
load_combo sel_computer, com_type
Case 37 'Room 37
load_combo sel_computer, com_type
Case 38 'Room 38
load_combo sel_computer, com_type
Case 39 'Room 39
load_combo sel_computer, com_type
Case 40 'Room 40
load_combo sel_computer, com_type
Case 41 'Room 41
load_combo sel_computer, com_type
Case 42 'Room 42
load_combo sel_computer, com_type
Case 43 'Room 43
load_combo sel_computer, com_type
Case 44 'Room 44
load_combo sel_computer, com_type
Case 45 'Room 45
load_combo sel_computer, com_type
Case 46 'Room 46
load_combo sel_computer, com_type
Case 47 'Room 47
load_combo sel_computer, com_type
Case 48 'Room 48
load_combo sel_computer, com_type
Case 49 'Room 49
load_combo sel_computer, com_type
Case 50 'Room 50
load_combo sel_computer, com_type
Case 51 'Room 51
load_combo sel_computer, com_type
Case 52 'Room 52
load_combo sel_computer, com_type
Case 53 'Room 53
load_combo sel_computer, com_type
Case 54 'Room 54
load_combo sel_computer, com_type
Case 55 'Room 55
load_combo sel_computer, com_type
end select
end Sub

sub sel_computer_onchange
clear_combo sel_level
select case sel_computer.value
Case 0 'Computer Type
case 01 'Desktop
load_combo sel_level, com_level
Case 02 'Laptop
load_combo sel_level, com_level
end select
end Sub

sub sel_level_onchange
clear_combo sel_number
select case sel_level.value
Case 0 'Computer Number
case 1 'Computer 1
load_combo sel_number, com_num
Case 2 'Computer 2
load_combo sel_number, com_num
end select
end Sub

Sub RunScript
  ComputerName.value = sel_campus.value & "RM" & sel_room.value & " " & sel_computer.value & " " & sel_level.value & " " & sel_number.value
End Sub


</script>

<body bgcolor="white">
<p>
    <button onclick="RunScript">Generate Name</button> <br>
<p>Computer Name<BR>
<input type=text id="ComputerName" name=ComputerName size=45></p>

    
    
</body>
</html>

Open in new window

Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2007
Commented:
This problem has been solved!
Unlock 10 Answers and 45 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE