We help IT Professionals succeed at work.

Rename computer HTA Script HELP!!! The sequal

Gabriel Clifton
on
636 Views
Last Modified: 2016-11-23
I am continuing on a script sirbounty helped on https://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28428407.html which allows me to use combo drop down boxes to generate computer names. I am wonderfully happy with the script but my boss wants something added. The ability to limit computer numbers for each room and user type. As it is right now, we select campus, room number, computer type, user type, and computer number. If I want campus Alamo, room number A01, Desktop computer, Teacher, computer number 1 it will generate ALRMA01DT01, which the script then checks to see if the computer already exists in AD and if it does it will not allow them to rename the computer to that name. This is great and will help eliminate our techs from randomly renaming a computer that is not part of our naming scheme, but the part my boss is wanting to add will help eliminate one of the other parts they frequently do, if computer 01 is not available move to 02 or next available number when there should only be one computer for that user in that room. Which just tells us they pulled a computer out of a room and did not rename it, take it off the domain, or tell us and now AD is getting full of computer that just does not need to be there. So, this limiter will force the techs (we hope) to help keep our AD clean and naming scheme right. If the naming scheme is correct, I have a script that searches through AD for computers, reads the computer name and makes sure it is in the right OU to ensure the correct GPOs are applied. Also, we have setup our Dell Kace K1000 labels to mimic our AD structure so that if a particular OU or computer needs a specific software it is automatically installed.

Ok enough of that rant.

I want to add the ability to limit computer numbers based on any combination from this script. I really do not want a separate file to keep this portable and not need to worry about keeping up with both files and we may integrate this with our imaging server.

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="description" content="Created by Gabriel Clifton with assistance from sirbounty">
<meta name="description" content="Last Update: 05/09/2014">

<title>Computer Rename Application</title>
<style>
.divbody{
padding:0px 15px 0px 15px;
}

body
{
font-family: calibri, verdana, arial;
	color: 000000;
	background-color: #53769E;
	text-align: left;
}
.pretty-table
{
  padding: 0;
  margin: 0;
  border-collapse: collapse;
  border: 1px solid #333;
  font-size: 0.9em;
  color: #000;
  background: black;
}

.pretty-table caption
{
  caption-side: bottom;
  font-size: 0.9em;
  font-style: italic;
  text-align: right;
  padding: 0.5em 0;
}
.pretty-table td
{
  background-color:white;
  padding: 0.5em;
}
.pretty-table th, 
{
  padding: 0.5em;
  text-align: left;
  color: white;

}
.pretty-table th[scope=col]
{
  color: #000;
  background-color: #8fadcc;
  text-transform: uppercase;
  font-size: 0.9em;
  border-bottom: 2px solid #333;
  border-right: 2px solid #333;
}
.pretty-table th+th[scope=col]
{
  color: #fff;
  background-color: #7d98b3;
  border-right: 1px dotted #666;
}
.pretty-table th[scope=row]
{
  background-color: #b8cfe5;
  border-right: 2px solid #333;
}
.pretty-table tr.alt th, .pretty-table tr.alt td
{
  color: #2a4763;
}
.pretty-table tr:hover th[scope=row], .pretty-table tr:hover td
{
  background-color: #632a2a;
  color: #fff;
}
#status_bar {
  box-shadow:rgb(136, 136, 136) 0px 5px 5px;
  background-color:#F7F7F7;
  border:1px solid #A5A5A5;
  font-color: #A5A5A5;
  font-size: 70%;
  border-bottom:0px;
  bottom:0px;
  height:25px;
  margin:auto;
  padding:5px 5px 5px 5px;
  position:absolute;
  width:100%;
  z-index:500;
}

..tabs {
border-collapse: collapse;
color: black;
cursor: pointer;
cursor: hand;
font-family: arial;
font-size: 9pt;
font-weight: bold;
margin-top: 4px;
padding: 2px 4px 0px 4px;
position: relative;
text-align: center;
text-decoration: none;
z-index: 1;
}
..tabs0 {
background-color: LightGrey;
border: solid 1px black;
}
..tabs1 {
background-color: Gainsboro;
border-color: black;
border-style: solid solid hidden solid;
border-width: 1px; }
..nav {
border-collapse: collapse;
align: center;
padding: 0;
spacing: 0;
width: 100%; }

</style>
<HTA:APPLICATION
	ICON="\\Server\Share\panther.ICO"
	APPLICATIONNAME="ComputerRename"
	BORDER="dialog"
	SCROLL="no" 
	MAXIMIZEBUTTON="no"
	SINGLEINSTANCE="no"
	CONTEXTMENU="no"
	WINDOWSTATE="normal"/> 	

</head>
<table border="0" width="100%"  cellspacing="0" cellpadding="0">
    <tr>
        <td width="33%" valign="top"><img src="\\Server\Share\FtStocktonLogo_Large.png" alt="Panther" width="110" height="110"></td>
        <td width="34%" valign="top">
        <font size="8" color="white"><b><center>Fort Stockton<br>
            Independent School District</b></center></font>
        </td>
        <td width="33%" align="right" valign="top"><img src="\\Server\Share\FtStocktonLogo_Large.png" alt="Panther" width="110" height="110"></td>
  </tr>
  <tr>
  <td></td>
  <td></td>
  			<td style="text-align:right;font-size:0.9em;font-weight:bold;font-style:oblique;color:#888888;">
				Created by Gabriel Clifton
			</td>
</tr>
</table>

<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 Window_onLoad
	width = "1000"
	height = "550"
	' This moves the window to the middle of the screen
	Set objWMIService = GetObject("winmgmts:\\.\root\cimv2") 
	Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor WHERE DeviceID='DesktopMonitor1'") 
	For Each objItem in ColItems 
	intHorizontal = objItem.ScreenWidth 
	intVertical = objItem.ScreenHeight 
	Next 
	intLeft = (intHorizontal - width)/2 
	intTop = (intVertical - height)/2 
	window.resizeTo width,height 
	
 Dim objNetwork : Set objNetwork = CreateObject("wscript.network")
 oldComputerName.value = objNetwork.ComputerName
End Sub

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

'Campus Names
load_combo sel_campus, array ("CAMPUS","ALAMO","APACHE","INTERMEDIATE","MIDDLE SCHOOL","HIGH SCHOOL","BUTZ","FOOD SERVICES","CENTRAL OFFICE","BUS BARN","SPECIAL SERVICES","TECHNOLOGY","MAINTENANCE")

'Campus Room Numbers
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," _
& "COUNSELOR,FRONT DESK,NURSE,PRINCIPAL,SECRETARY,TIME CLOCK,MUSIC,LIBRARY,GYM,CAFETERIA,MOBILE LAB 1", ",")

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," _
& "COUNSELOR,FRONT DESK,NURSE,PRINCIPAL,SECRETARY,TIME CLOCK,MUSIC,LIBRARY,GYM,CAFETERIA,MOBILE LAB 1,MOBILE LAB 2",",")

dim intermediate_rooms : intermediate_rooms = split ("ROOM,DARE,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," _
& "COUNSELOR,FRONT DESK,NURSE,PRINCIPAL,SECRETARY,TIME CLOCK,MUSIC,LIBRARY,GYM,ISS,CAFETERIA,MOBILE LAB 1",",")

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," _
& "COUNSELOR,FRONT DESK,NURSE,PRINCIPAL,ASSISTANT PRINCIPAL,SECRETARY,TIME CLOCK,BAND,CHOIR,LIBRARY,BLUE GYM,WHITE GYM,ISS,MOBILE LAB 1,TRACK TIME,CAFETERIA",",")

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,032,033,034,035,036,037,038,039,040," _
& "041,042,WOOD SHOP,AGRICULTURE,045,046,047,048,049,050,ART,METAL SHOP," _
& "COUNSELOR,FRONT DESK,NURSE,PRINCIPAL,ASSISTANT PRINCIPAL,SECRETARY,ATTENDANCE,STUDENT SERVICES,PARENT LIAISON,TIME CLOCK," _
& "BAND,CHOIR,THEATER,AUDITORIUM,LIBRARY," _
& "ATHLETICS SECRETARY,FIELD HOUSE,FILM EDITING,HPE,SWIM COACH,ATHLETICS,BLUE GYM,WHITE GYM,HOME ECONOMICS,ISS,GCS,TRACK TIME," _
& "LAB V01,LAB V02,LAB V03,LAB V04,LAB V05,LAB V06,LAB V07,LAB V08," _
& "LIBRARY MOBILE LAB,CATE MOBILE LAB,ENGLISH / SS MOBILE LAB,MATH / SCIENCE MOBILE LAB,CAFETERIA,OFFICER",",")

Dim butz_rooms : butz_rooms = Split ("ROOM,BILINGUAL DIRECTOR,BILINGUAL SECRETARY,PRINCIPAL,TIME CLOCK," _
& "CURRICULUM,DAEP,DAYCARE DIRECTOR,TEACHSCAPE,DAYCARE TEACHER,DISTRICT PEIMS COORDINATOR,MIGRANT RECRUITER" _
& ",MIGRANT RECRUITER AIDE,NURSE DIRECTOR,CAFETERIA",",")

Dim fs_rooms : fs_rooms = split ("ROOM,ADMINISTRATION",",")

Dim co_rooms : co_rooms = Split ("ROOM,ACCOUNTS PAYABLE COORDINATOR,ASSISTANT SUPERINTENDENT," _
& "ASSISTANT SUPERINTENDENT SECRETARY,BUSINESS MANAGER,GUEST COMPUTER,PAYROLL COORDINATOR,SUPERINTENDENT,SUPERINTENDENT SECRETARY",",")

Dim bb_rooms : bb_rooms = Split ("ROOM,BUS BARN,AUTO TECH",",")

Dim ss_rooms : ss_rooms = Split ("ROOM,031,032,033,034,035,036,037,038",",")

Dim tech_rooms : tech_rooms = Split ("ROOM,NETWORK ADMINISTRATOR,RECEPTIONIST,SYSTEMS ADMINISTRATOR," _
& "TECH DIRECTOR,WEB MASTER,INVENTORY COMPUTER,TECH 1,TECH 2,TRAINING LAB EAST,TRAINING LAB WEST",",")

Dim mai_rooms : mai_rooms = Split ("ROOM,MAINTENANCE,ELECTRICAL MAINTENANCE,WAREHOUSE",",")

'User Type
Dim com_level : com_level = Split ("USER TYPE,TEACHER,STUDENT,NCOMPUTING 1",",")

'Computer Type
Dim com_type : com_type = Split ("COMPUTER TYPE,DESKTOP,LAPTOP,NCOMPUTING 2",",")

'Computer Numbers
dim com_num : com_num = split ("COMPUTER NUMBER,01,02,03,04,05,06,07,08,09,10," _
& "11,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",",")

'Selection for campus names
sub sel_campus_onchange
  Dim CampusName
  clear_combo sel_room
  select case sel_campus.value
    Case 0 'Campus
    Case 1 'Alamo
      CampusName = "AL"
      load_combo sel_room, alamo_rooms
    Case 2 'Apache
      CampusName = "AP"
      load_combo sel_room, apache_rooms
    Case 3 'Intermediate
      CampusName = "IN"
      load_combo sel_room, intermediate_rooms
    Case 4 'Middle School
      CampusName = "MS"
      load_combo sel_room, ms_rooms
    Case 5 'High School
      CampusName="HS"
      load_combo sel_room, hs_rooms
    Case 6 'Butz
      CampusName="BU"
      load_combo sel_room, butz_rooms
    Case 7 'Food Services
      CampusName="IN"
      load_combo sel_room, fs_rooms
    Case 8 'Central Office
      CampusName="CO"
      load_combo sel_room, co_rooms
    Case 9 'Bus Barn
      CampusName="BB"
      load_combo sel_room, bb_rooms
    Case 10 'Special Services
      CampusName="SS"
      load_combo sel_room, ss_rooms
    Case 11 'Technology
      CampusName="TC"
      load_combo sel_room, tech_rooms
    Case 12 'Maintenance
      CampusName="HS"
      load_combo sel_room, mai_rooms
  End select

  'You may be able to remove each CampusName='xx' section with some logic here
  'but we seem to be missing some elements (for Food Services, Special Services, Technology?)

  ComputerName.value = CampusName
end Sub

'Selection for campus rooms
sub sel_room_onchange
  Dim RoomNumber, rn
  clear_combo sel_computer
  if sel_room.value = 0 Then exit sub
  rn = sel_room.value
  load_combo sel_computer, com_type
  select case sel_campus.value
    case 1 'Alamo rooms
      select case true
        case rn < 11
    	RoomNumber = "RMA" & right("0" & rn,2)
        case rn < 20
          RoomNumber = "RMB" & right("0" & rn-10,2)
        case rn < 31
          RoomNumber = "RMC" & right("0" & rn-19,2)
        case rn < 42 
          RoomNumber = "RMD" & right("0" & rn-30,2)
        case else
          if rn = 42 Then RoomNumber = "RMCOU"
          if rn = 43 Then RoomNumber = "RMFRD"
          if rn = 44 Then RoomNumber = "RMNUR"
          if rn = 45 Then RoomNumber = "RMPRI"
          if rn = 46 Then RoomNumber = "RMSEC"
          if rn = 47 Then RoomNumber = "RMTCL"
          if rn = 48 Then RoomNumber = "RMMSC"
          if rn = 49 Then RoomNumber = "RMLIB"
          if rn = 50 Then RoomNumber = "RMGYM"
          if rn = 51 Then RoomNumber = "RMCAF"
          If rn = 52 Then RoomNumber = "ML001"
      end select
    case 2  'Apache Rooms
      select case true
        case rn < 26
          RoomNumber = "RM" & Right("00" & rn,3)
        case rn < 36
          RoomNumber = "RM3" & rn
        case else
	  if rn = 36 Then RoomNumber = "RMCOU"
	  if rn = 37 Then RoomNumber = "RMFRD"
	  if rn = 38 Then RoomNumber = "RMNUR"
	  if rn = 39 Then RoomNumber = "RMPRI"
	  if rn = 40 Then RoomNumber = "RMSEC"
	  if rn = 41 Then RoomNumber = "RMTCL"
	  if rn = 42 Then RoomNumber = "RMMSC"
	  if rn = 43 Then RoomNumber = "RMLIB"
	  if rn = 44 Then RoomNumber = "RMGYM"
	  if rn = 45 Then RoomNumber = "RMCAF"
	  If rn = 46 Then RoomNumber = "ML001"
	  If rn = 47 Then RoomNumber = "ML002"
      end select
    case 3  'Intermediate Rooms
      select case true
        case rn = 1
          RoomNumber = "RMDAR"
        case rn < 29
          RoomNumber = "RM" & Right("RM00" & rn,3)
        case else
 	  if rn = 29 Then RoomNumber = "RMCOU"
 	  if rn = 30 Then RoomNumber = "RMFRD"
 	  if rn = 31 Then RoomNumber = "RMNUR"
 	  if rn = 32 Then RoomNumber = "RMPRI"
 	  if rn = 33 Then RoomNumber = "RMSEC"
 	  if rn = 34 Then RoomNumber = "RMTCL"
 	  if rn = 35 Then RoomNumber = "RMMSC"
 	  if rn = 36 Then RoomNumber = "RMLIB"
 	  if rn = 37 Then RoomNumber = "RMGYM"
 	  if rn = 38 Then RoomNumber = "RMISS"
 	  If rn = 39 Then RoomNumber = "ML001"
 	  if rn = 40 Then RoomNumber = "RMCAF"
        end select
    case 4  'Middle School Rooms
      select case true
        case rn < 10
          RoomNumber = "RM" & right("10" & rn,3)
        case rn > 9 And rn < 52
          RoomNumber = "RM" & right("1" & rn,3)
       case else
  	  if rn = 52 Then RoomNumber = "RMCOU"
	  if rn = 53 Then RoomNumber = "RMFRD"
      If rn = 54 Then RoomNumber = "RMNUR"
      If rn = 55 Then RoomNumber = "RMPRI"
      If rn = 56 Then RoomNumber = "RMAPR"
      If rn = 57 Then RoomNumber = "RMSEC"
      If rn = 58 Then RoomNumber = "RMTCL"
      If rn = 59 Then RoomNumber = "RMBND"
      If rn = 60 Then RoomNumber = "RMCHR"
      If rn = 61 Then RoomNumber = "RMLIB"
      If rn = 62 Then RoomNumber = "RMBGM"
      If rn = 63 Then RoomNumber = "RMWGM"
      If rn = 64 Then RoomNumber = "RMISS"
      If rn = 65 Then RoomNumber = "ML001"
      If rn = 66 Then RoomNumber = "TRKTM"
      If rn = 67 Then RoomNumber = "RMCAF"
      end select 
    case 5  'High School Rooms
      select case True
        Case rn < 53
          RoomNumber = "RM" & Right("00" & rn,3)
        case Else
          if rn = 53 Then RoomNumber = "RMCOU"
          if rn = 54 Then RoomNumber = "RMFRD"
          if rn = 55 Then RoomNumber = "RMNUR"
          if rn = 56 Then RoomNumber = "RMPRI"
          if rn = 57 Then RoomNumber = "RMAPR"
          if rn = 58 Then RoomNumber = "RMSEC"
          if rn = 59 Then RoomNumber = "RMATT"
          if rn = 60 Then RoomNumber = "RMSSV"
          If rn = 61 Then RoomNumber = "RMPLI"
          if rn = 62 Then RoomNumber = "RMTCL"
          if rn = 63 Then RoomNumber = "RMBND"
          if rn = 64 Then RoomNumber = "RMCHR"
          if rn = 65 Then RoomNumber = "RMTHE"
          if rn = 66 Then RoomNumber = "RMAUD"
          if rn = 67 Then RoomNumber = "RMLIB"
          if rn = 68 Then RoomNumber = "RMATS"
          if rn = 69 Then RoomNumber = "FIELD"
          if rn = 70 Then RoomNumber = "FLMED"
          if rn = 71 Then RoomNumber = "RMHPE"
          if rn = 72 Then RoomNumber = "RMSWC"
          if rn = 73 Then RoomNumber = "RMATL"
          if rn = 74 Then RoomNumber = "RMBGM"
          if rn = 75 Then RoomNumber = "RMWGM"
          if rn = 76 Then RoomNumber = "RMHEC"
          if rn = 77 Then RoomNumber = "RMISS"
          if rn = 78 Then RoomNumber = "RMGCS"
          If rn = 79 Then RoomNumber = "TRKTM"
          If rn = 80 Then RoomNumber = "RMV01"
          If rn = 81 Then RoomNumber = "RMV02"
          If rn = 82 Then RoomNumber = "RMV03"
          If rn = 83 Then RoomNumber = "RMV04"
          If rn = 84 Then RoomNumber = "RMV05"
          If rn = 85 Then RoomNumber = "RMV06"
          If rn = 86 Then RoomNumber = "RMV07"
          If rn = 87 Then RoomNumber = "RMV08"          
          If rn = 88 Then RoomNumber = "MLLIB"
          If rn = 89 Then RoomNumber = "MLCAT"
          If rn = 90 Then RoomNumber = "MLENS"
          If rn = 91 Then RoomNumber = "MLMAS"
          if rn = 92 Then RoomNumber = "RMCAF"
          if rn = 93 Then RoomNumber = "RMPOL"
      end select 
    case 6  'Butz Rooms
      if rn= 1 then RoomNumber = "RMBLD"
      if rn = 2 then RoomNumber = "RMBLS"
      if rn = 3 then RoomNumber = "RMPRI"
      if rn = 4 then RoomNumber = "RMTCL"
      if rn = 5 then RoomNumber = "RMCUR"
      if rn = 6 then RoomNumber = "RMDAE"
      if rn = 7 then RoomNumber = "RMDCD"
      if rn = 8 then RoomNumber = "RMTSC"
      if rn = 9 then RoomNumber = "RMDCT"
      if rn = 10 then RoomNumber = "RMDPC"
      if rn = 11 then RoomNumber = "RMMIR"
      if rn = 12 then RoomNumber = "RMMRA"
      if rn = 13 then RoomNumber = "RMNUR"
      if rn = 14 then RoomNumber = "RMCAF"
    case 7  'Food Services Rooms
      if rn = 1 Then RoomNumber = "RMFDS"
    case 8  'Central Office Rooms
      if rn = 1 Then RoomNumber = "RMAPC"
      if rn = 2 Then RoomNumber = "RMASU"
      if rn = 3 Then RoomNumber = "RMASC"
      if rn = 4 Then RoomNumber = "RMBMA"
      if rn = 5 Then RoomNumber = "RMGUE"
      if rn = 6 Then RoomNumber = "RMPRC"
      if rn = 7 Then RoomNumber = "RMSUP"
      if rn = 8 Then RoomNumber = "RMASU"
    case 9  'Bus Barn Rooms
      if rn = 1 Then RoomNumber = "RMOFC"
      if rn = 2 Then RoomNumber = "RMATT"
    case 10  'Special Services Rooms
      RoomNumber = "RM" & Right("00" & rn+30,3)
    case 11  'Technology Rooms
      if rn = 1 Then RoomNumber = "NETAD"
      if rn = 2 Then RoomNumber = "FRTDK"
      if rn = 3 Then RoomNumber = "SYSAD"
      if rn = 4 Then RoomNumber = "TECHD"
      if rn = 5 Then RoomNumber = "WEBMR"
      if rn = 6 Then RoomNumber = "WASPC"
      if rn = 7 Then RoomNumber = "TECH1"
      if rn = 8 Then RoomNumber = "TECH2"
      if rn = 9 Then RoomNumber = "RMTLE"
      if rn = 10 Then RoomNumber = "RMTLW"
    case 12   'Maintenance
      if rn = 1 Then RoomNumber = "MAINT"
      If rn = 2 Then RoomNumber = "ELMNT"
      If rn = 3 Then RoomNumber = "WRHSE"
  end select
  ComputerName.value = Left(ComputerName.value,2) & RoomNumber
end Sub
'Selection for computer type
  dim DeviceType
Sub sel_computer_onchange
  clear_combo sel_level
  if sel_computer.value=0 then exit sub
  load_combo sel_level, com_level
    If sel_computer.value = 1 Then
    DeviceType = "D"
  ElseIf sel_computer.value = 2 Then
    DeviceType = "L"
  Else
  	DeviceType = "N"
  End If
  ComputerName.value = Left(ComputerName.value,7) & DeviceType
end Sub

'Selection for level number
sub sel_level_onchange
  dim PersonType
  clear_combo sel_number
  if sel_level.value=0 then exit sub
  load_combo sel_number, com_num
    If sel_level.value = 1 Then
    PersonType = "T"
  ElseIf sel_level.value = 2 Then
    PersonType = "S"
  Else
  	PersonType = "C"
  End If
  ComputerName.value = Left(Computername.value,8) & PersonType
end Sub

'Select for number
sub sel_number_onchange
  ComputerName.value = Left(ComputerName.value,9) & Right("0" & sel_number.value, 2)
  If Right(ComputerName.value,2) > 9 Then
  	ComputerName.value = Left(ComputerName.value,9) & Right(sel_number.value, 2)
  End If
'Select for computer number
'sub sel_number_onchange
'	Dim ComNum, cn
'	If sel_number.value = 0 Then Exit Sub
'	cn = sel_number.value
'	load_combo sel_number , com_num
'	Select case sel_number.value
'	Case 1 'Teacher Numbers
'      select case True
'        Case cn < 7
'          ComNum = Right("0" & cn,2)
'      end select 
'	Case 2 'Student Numbers
'      select case True
'        Case cn < 53
'          ComNum = right("0" & cn-50,2)
'      end select 
'  ComputerName.value = Left(ComputerName.value,9) & ComNum
'end Sub
  ''''''''''''''''''''
Dim objNetwork, strNewComputer, strDomain
Dim objTrans, strComputerDN

Const ADS_NAME_INITTYPE_GC = 3
Const ADS_NAME_TYPE_NT4 = 3
Const ADS_NAME_TYPE_1779 = 1

' Prompt for NetBIOS name of computer.
strNewComputer = ComputerName.value

' Retrieve NetBIOS name of the domain.
Set objNetwork = CreateObject("Wscript.Network")
strDomain = objNetwork.UserDomain

' Use NameTranslate to convert NT name into DN.
Set objTrans = CreateObject("NameTranslate")
' Initialize by locating GC.
objTrans.Init ADS_NAME_INITTYPE_GC, ""

' Use Set method to specify NT format of name.
' Be sure to append the "$" to the NetBIOS name of the computer.
' Trap error if object does not exist.
On Error Resume Next
objTrans.Set ADS_NAME_TYPE_NT4, strDomain & "\" & strNewComputer & "$"
If (Err.Number = 0) Then
  On Error GoTo 0
  ' Computer exists.
  ' Use Get method to retrieve DN.
  strComputerDN = objTrans.Get(ADS_NAME_TYPE_1779)
  DataArea.InnerHTML = "Computer name already exists in Active Directory!" & "<br>" & "Contact admins before renaming computer!"
  DataArea2.InnerHTML = ""
    document.GetElementByID("Rename").disabled = true
Else
  On Error GoTo 0
  DataArea2.InnerHTML = "WARNING! WILL REBOOT COMPUTER!"
  DataArea.InnerHTML = ""
    document.GetElementByID("Rename").disabled = false
End If
''''''''''''''''''''''
'  document.GetElementByID("Rename").disabled = false
end sub

Sub RenamePC
  Dim strComputer, strDomainUser, strDomainPasswd, strLocalUser, strLocalPasswd, NewComputerName, uName, uPassword
  Dim iResponse : iResponse = Msgbox("Rename " & oldComputerName.value & " to " & Computername.value & "?", _
        vbYesNo, "Proceed with rename?")
  If iResponse = vbNo Then
    Msgbox "No changes will be made."
    exit sub
  End If
strComputer=OldComputerName.value
'strNewComputer = ComputerName.value
strDomainUser = document.getElementById("uName").value & "@fsisd.local"
strDomainPasswd = document.getElementById("uPassword").value
strLocalUser = strComputer & "\administrator"
strLocalPasswd = "XXXXXX" 
' ------ END CONFIGURATION --------- 

'########################### 
' Connect to Computer 
'###########################
Dim objWMILocator, objWMIComputer, objWMIComputerSystem, rc, WScript, objWMIService, colOperatingSystems, objOperatingSystem
Set objWMILocator = CreateObject("WbemScripting.SWbemLocator") 
objWMILocator.Security_.AuthenticationLevel = 6 
Set objWMIComputer = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd) 
Set objWMIComputerSystem = objWMIComputer.Get( "Win32_ComputerSystem.Name='" & strComputer & "'") 
'########################### 
' Rename Computer 
'########################### 
rc = objWMIComputerSystem.Rename(strNewComputer, strDomainPasswd, strDomainUser) 
if rc <> 0 then 
Msgbox "Rename failed with error: " & rc 
else 
Msgbox "Successfully renamed " & strComputer & " to " & strNewComputer 
Msgbox "Rebooting..." 
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate,(Shutdown)}!\\" & _
        strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
    objOperatingSystem.Reboot()
Next

End if 

'  Next
end sub

sub disableButton()
  document.GetElementByID("Rename").disabled = true
end sub
</script>

<body bgcolor="white" onload="disableButton()">
<p>
<table>
	<tr>
		<td>
			<font color="white" size="5"><b>Old Computer Name:</b></font>
		</td>
		<td>
			<input type=text id="OldComputerName" name=OldComputerName size=45>
		</td>
	</tr>
	<tr>
		<td colspan="2">
			<font color="white" size="3"><b>If a needed computer name is not available, please let admins know to add it.</b></font>
		</td>
	</tr>
	<tr>
		<td>
			<font color="white" size="5"><b>New Computer Name:</b></font>
		</td>
		<td>
			<input type=text id="ComputerName" name=ComputerName size=45 readonly>
		</td>
	</tr>
	<tr>
		<td>
			<font color="white" size="5"><b>Your Username:</b></font>
		</td>
		<td>
			<input type=text name=uName size=45>
		</td>
	</tr>
	<tr>
		<td>
			<font color="white" size="5"><b>Your Password:</b></font>
		</td>
		<td>
			<input type=password name=uPassword size=45>
		</td>
	</tr>
</table>
 <span id = "DataArea" style="color: white; font-weight: bold; font-size: 30;"></span>
 <span id = "DataArea2" style="color: white; font-weight: bold; font-size: 48;"></span>
 <br>
<button onclick="RenamePC" id="Rename">Rename Computer</button>
</body>
</html>

Open in new window

Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Gabriel CliftonNet Admin
Top Expert 2012

Author

Commented:
Looks interesting and I am up for a challenge. How could this be done without the use of a separate file?
Gabriel CliftonNet Admin
Top Expert 2012

Author

Commented:
Also, here is something I just discovered. I don't know when it got screwed up or what, but now when I try to run this on a remote computer, I get:
Script Error
Line: 647
Char: 1
Error: Invalid method Parameter(s)

If I run this on the machine I am trying to rename, I get:
Script Error
Line: 642
Char: 1
Error: User credentials cannot be used for local connections

WHAT DID I DO?
Gabriel CliftonNet Admin
Top Expert 2012

Author

Commented:
Ok, I Figured out the problem on remote machine but not local yet.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Gabriel CliftonNet Admin
Top Expert 2012

Author

Commented:
Thanks a million.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Gabriel CliftonNet Admin
Top Expert 2012

Author

Commented:
Yes, the remote reboot works very well.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Gabriel CliftonNet Admin
Top Expert 2012

Author

Commented:
Ok, this is going good for the excel to script, long and tedious though. I have tested it so far and had issues: if I try to rename a remote computer it tells me Error: Client connection to WINMGMT needs to be encrypted, and if I rename locally it tells me Error: Invalid method Parameter(s) on the lines starting the rename function. I changed the sub RenamePC back to last code and it worked on remote only.

This is not a big rush for me right now because I am about to go out of town for the weekend.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Hi, I'm not in a position to test the rename code this weekend, but I have noticed a typo the WMI code I changed, and have corrected it.  Can you try again when you get a chance?

If it doesn't work, I'll test it out with a test machine and make sure it works before I post again.

Rob.
Gabriel CliftonNet Admin
Top Expert 2012

Author

Commented:
Works remotely perfectly, works locally if I remember to run it from an elevated command prompt. Is there any way to skip the elevated command line?
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Gabriel CliftonNet Admin
Top Expert 2012

Author

Commented:
WOW, this is going great so far. Quick question. I am going cross-eyed going through the excel sheet trying to make sure this goes with that but not the other, is there a way I can add a quick innerhtml to display the rst*.Fields(0) so I can visually see the "C1 R2 T2 U3" to help me visually know where I am going?
Gabriel CliftonNet Admin
Top Expert 2012

Author

Commented:
Update on progress, so far on the excel sheet I have all campuses, rooms, computer type, user type, computer number minimum combos. Now I am trying to go through it and put the computer number limit for each room combo. As it sits right now I am at about 90,000 lines in the HTA. Quite a bit of work on all our part and I thank you for your help so far, but in the end I believe this will be well worth it. Also, I found out the RoomText column has a character limit, not a big deal I just abbreviated those rooms. It just got me when I was testing and I kept getting Multi-step operation generated errors. I am still pounding hard and my eyes are hitting me for looking at all those lines for so long.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Hmmmm.....sorry about all that.....I didn't realise you would go that big!  As for the character limit, you will see in the Module code for CreateRecordsetCode in the Excel file, this line
adVarChar, 30, adFldIsNullable

you can change the 30 in those lines up to 255, but that will affect all fields (since we make all fields the same length and type).  Sorry, I probably should have told you that....

I will have a look at provide a "preview" in the Excel file itself....
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Gabriel CliftonNet Admin
Top Expert 2012

Author

Commented:
Thank you so much for your help. It took me that long to finish it up, 63000+ lines. I am going to soon post spin offs of this soon if you want to help out on that. This has made my boss happy because the chances of naming a computer wrong have been minimized, although I wish eliminated.

As usual since this was a work in progress I gave points down the board for each section of help.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Wow, that's a hefty size!  At least it's all self contained, with some validation.  You probably would have benefited from utilising a separate file, since it would have been easier to modify, but at least we've got something working that you have more control over.

Thanks for the grade.

Rob.
Gabriel CliftonNet Admin
Top Expert 2012

Author

Commented:
Thank you for the help. Twice I have needed help with HTAs and twice you got me finished. (The last one quit working, but that is for some other time.)

One quick question for you, I am trying to attach the HTA to our scripted OS install and I have it on the last automatic login and it is giving me permissions errors. Do I just need to take it out and only use it as a domain user?
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
It will need to run as a domain user because it is querying AD.  For that task, you may need to make use of PSExec to launch the HTA as a domain user.
Gabriel CliftonNet Admin
Top Expert 2012

Author

Commented:
No problem, thank you again

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
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
Empower Your Career
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

Ask ANY Question

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

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

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

OR

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.