Batch script to HTA script

I have a batch script that I use that works well, but I am wanting to convert it into a HTA script with a few extra features, but I always have trouble doing that. Basically, I work at a school district and when it is time for state testing I have a batch script that lists the computer labs that are used for the testing. I select the lab I need and the script reads all of the computers in the appropriate OU and renames them to the testing naming scheme, wait for the computers to be moved to the testing OU (for a new set of group policies), performs a gpupdate and reboots the computer twice to ensure group policies are implemented. I would like to add the ability to check individual computers to rename with a check all button as most labs have 40+ computers and sometimes a few computers are going to be used and sometimes all. The script will add the original computer name to a file on the computers hard drive so that it can be renamed back. I would also like a separate tab that will do the reverse. Display all of the computers in the campuses testing OU with old and new name so you can select which ones to rename back. The biggest issue I can think of on that one is unlike the regular OUs where each lab has its own OU, on the testing OU each campus has a single OU for all of the computers and the distinction between the computers would be in the name, ie, campus a lab 1 would have a 1 in the name. Provided there can be 40+ computers per lab and 2 to six labs per campus, that list can be extremely long on the bigger campuses so I would like it to separate the labs in the display. The batch scripts I have will for testing will rename all computers in the corresponding OU without the ability to choose so if I do not want to rename all computers in an OU I have to do it manually. Any help would be greatly appreciated.

@echo off

:start

cls
echo.   
echo          =================================================
echo                         Main Menu
echo          =================================================
echo		a. Campus 1 C01 K-1 Lab
echo		b. Campus 1 D01 2-3 Lab
echo		c. Campus 2 Room 006 Lab
echo		d. Campus 2 Room 017 Lab
echo		e. Campus 2 Room 326 Lab
echo		f. Campus 3 Room 001 Lab
echo		g. Campus 3 Room 012
echo		h. Campus 3 Room 027 Lab
echo		i. Campus 3 Room 028 Lab
echo		j. Campus 4 Room 110 Lab
echo		k. Campus 4 Room 111 Lab
echo		l. Campus 5 Room 11 Lab
echo		m. Campus 5 Room 12 Lab
echo		n. Campus 5 Room 13 Lab
echo		o. Campus 5 Room 48 Lab
echo		p. Campus 5 GCS Lab
echo		q. Campus 6 East Lab
echo		r. Campus 6 West Lab
echo		0. Exit
echo          =================================================

:: SET /P prompts for input and sets the variable
:: to whatever the user types
SET Choice=
SET /P Choice=Type the letter and press Enter: 
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%Choice%'=='' SET Choice=%Choice:~0,1%
ECHO.
:: /I makes the IF comparison case-insensitive
IF /I '%Choice%'=='a' Set COU="OU=Lab 1,OU=Campus 1,DC=domain,DC=local" && Set cmps=AL && set tnvou="OU=Campus 1,OU=TESTNAV,DC=domain,DC=local" && set lab=1 && goto testrn
IF /I '%Choice%'=='b' Set COU="OU=Lab 2,OU=Campus 1,DC=domain,DC=local" && Set cmps=AL && set tnvou="OU=Campus 1,OU=TESTNAV,DC=domain,DC=local" && set lab=2 && goto testrn
IF /I '%Choice%'=='c' Set COU="OU=Lab 1,OU=Campus 2,DC=domain,DC=local" && Set cmps=AP && set tnvou="OU=Campus 2,OU=TESTNAV,DC=domain,DC=local" && set lab=1 && goto testrn
IF /I '%Choice%'=='d' Set COU="OU=Lab 2,OU=Campus 2,DC=domain,DC=local" && Set cmps=AP && set tnvou="OU=Campus 2,OU=TESTNAV,DC=domain,DC=local" && set lab=2 && goto testrn
IF /I '%Choice%'=='e' Set COU="OU=Lab 3,OU=Campus 2,DC=domain,DC=local" && Set cmps=AP && set tnvou="OU=Campus 2,OU=TESTNAV,DC=domain,DC=local" && set lab=3 && goto testrn
IF /I '%Choice%'=='f' Set COU="OU=Lab 1,OU=Campus 3,DC=domain,DC=local" && Set cmps=IN && set tnvou="OU=Campus 3,OU=TESTNAV,DC=domain,DC=local" && set lab=1 && goto testrn
IF /I '%Choice%'=='g' Set COU="OU=Lab 2,OU=Campus 3,DC=domain,DC=local" && Set cmps=IN && set tnvou="OU=Campus 3,OU=TESTNAV,DC=domain,DC=local" && set lab=2 && goto testrn
IF /I '%Choice%'=='h' Set COU="OU=Lab 3,OU=Campus 3,DC=domain,DC=local" && Set cmps=IN && set tnvou="OU=Campus 3,OU=TESTNAV,DC=domain,DC=local" && set lab=3 && goto testrn
IF /I '%Choice%'=='i' Set COU="OU=Lab 4,OU=Campus 3,DC=domain,DC=local" && Set cmps=IN && set tnvou="OU=Campus 3,OU=TESTNAV,DC=domain,DC=local" && set lab=4 && goto testrn
IF /I '%Choice%'=='j' Set COU="OU=Lab 1,OU=Campus 4,DC=domain,DC=local" && Set cmps=MS && set tnvou="OU=Campus 4,OU=TESTNAV,DC=domain,DC=local" && set lab=1 && goto testrn
IF /I '%Choice%'=='k' Set COU="OU=Lab 2,OU=Campus 4,DC=domain,DC=local" && Set cmps=MS && set tnvou="OU=Campus 4,OU=TESTNAV,DC=domain,DC=local" && set lab=2 && goto testrn
IF /I '%Choice%'=='l' Set COU="OU=Lab 1,OU=Campus 5,DC=domain,DC=local" && Set cmps=HS && set tnvou="OU=Campus 5,OU=TESTNAV,DC=domain,DC=local" && set lab=1 && goto testrn
IF /I '%Choice%'=='m' Set COU="OU=Lab 2,OU=Campus 5,DC=domain,DC=local" && Set cmps=HS && set tnvou="OU=Campus 5,OU=TESTNAV,DC=domain,DC=local" && set lab=2 && goto testrn
IF /I '%Choice%'=='n' Set COU="OU=Lab 3,OU=Campus 5,DC=domain,DC=local" && Set cmps=HS && set tnvou="OU=Campus 5,OU=TESTNAV,DC=domain,DC=local" && set lab=3 && goto testrn
IF /I '%Choice%'=='o' Set COU="OU=Lab 4,OU=Campus 5,DC=domain,DC=local" && Set cmps=HS && set tnvou="OU=Campus 5,OU=TESTNAV,DC=domain,DC=local" && set lab=4 && goto testrn
IF /I '%Choice%'=='p' Set COU="OU=Lab 5,OU=Campus 5,DC=domain,DC=local" && Set cmps=HS && set tnvou="OU=Campus 5,OU=TESTNAV,DC=domain,DC=local" && set lab=5 && goto testrn
IF /I '%Choice%'=='q' Set COU="OU=Lab 1,OU=Campus 6,DC=domain,DC=local" && Set cmps=TC && set tnvou="OU=Technology,OU=TESTNAV,DC=domain,DC=local" && set lab=1 && goto testrn
IF /I '%Choice%'=='r' Set COU="OU=Lab 2,OU=Campus 6,DC=domain,DC=local" && Set cmps=TC && set tnvou="OU=Technology,OU=TESTNAV,DC=domain,DC=local" && set lab=2 && goto testrn
IF /I '%Choice%'=='0' GOTO :eof

ECHO "%Choice%" is not valid. Please try again.
pause
goto start

:testrn
for /f "Tokens=*" %%s in ('dsquery computer %COU% -o rdn -limit 0 ^|sort') do call :sub1 %%s
:timestart
set tme=%time:~4,1%
set mnt=false
if /i %tme% EQU 5 set mnt=true
if /i %tme% EQU 0 set mnt=true
if /i %mnt% NEQ true Echo. && Echo Waiting for computers to move in AD && ping 127.0.0.1 -n 30 >nul && goto timestart
if /i %mnt% EQU true goto sub3
pause
exit /b

:sub1

set cmpnme=%1
set cmpnme=%cmpnme:"=%
set tnnm=%cmpnme:~-4%
set tnnm=%tnnm: =%
set cmps=%cmps: =%
set lab=%lab: =%
echo.
echo Writing current computer name and testnav computer name to file.
echo %cmpnme%> "\\%cmpnme%\c$\compname.txt"
echo %cmpnme%,TESTNAV%cmps%%lab%-%tnnm% && echo %cmpnme%,TESTNAV%cmps%%lab%-%tnnm%> \\%cmpnme%\c$\TESTNAV%cmps%%lab%-%tnnm%.csv
for /f "tokens=* delims=," %%g in (\\%cmpnme%\c$\%cmpnme%.csv) do call :sub2 %%g
exit /B

:sub2
Echo Renaming Computer for TestNav naming scheme.
for /f "tokens=1,2 delims=," %%m in ("%*") do netdom renamecomputer %%m /newname:%%n /ud:domain\username /pd:password /force /reboot
exit /B

:sub3
for /f "Tokens=*" %%d in ('dsquery computer %tnvou% -o rdn -limit 0 ^|sort') do call :sub4 %%d
exit /b

:sub4
set /a looper=1
:ploop
set ptr=%1
set ptr=%ptr:"=%
:pingwait
ping %ptr% -n 1 2>nul 1>nul
if /i %errorlevel% EQU 1 goto pingwait
psexec \\%ptr% gpupdate /force && shutdown /m \\%ptr% -f -r -t 0
if %looper% GEQ 2 exit /b
set looper+=1
goto ploop

Open in new window

LVL 13
Gabriel CliftonNet AdminAsked:
Who is Participating?
 
RobSampsonCommented:
Hi, I don't have the same issue, but I remember we have seen that before, although looking back, it doesn't look we did anything specifically to fix it.  I think as long as you tick at least one box on the Rename From tab, it should work OK.

Here is a slightly revised version, but the functionality still appears to work in terms of the check boxes with the correct operation.

<html> 
<head> 
<title>Rename Computer Labs for state testing</title> 

<HTA:Application 
ID = "HTA" 
ApplicationName = "RenLab" 
Border = "dialog" 
BorderStyle = "normal" 
Caption = "yes" 
ContextMenu="yes" 
ICON="\\Server\Share\panther.ICO"
InnerBorder="no" 
MaximizeButton = "no" 
MinimizeButton = "no" 
Navigable="yes" 
Scroll="yes" 
SrollFlat="no" 
Selection="yes" 
ShowInTaskBar = "yes" 
SingleInstance = "yes" 
SysMenu = "yes" 
Version = "1.0" 
> 
<style>
.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; 
} 
.tabsNotSelected { 
background-color: wheat; 
border: solid 1px black; 
} 
.tabsSelected { 
background-color: white; 
border-color: black black white black; 
border-style: solid solid solid solid; 
border-width: 1px 1px 1px 1px; 
} 
</style>
<script language="VBscript"> 
Dim sItem 
Dim aPanels 
Dim el 
Dim iPanelCount 
iPanelCount = 2
Dim intColCount
intColCount = 4
Dim strHTAPath

Sub Window_OnLoad

	ElevatedCheck
	width = "750"
	height = "750"
	' 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 
	
    If Mid(document.location, 6, 3) = "///" Then
    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)
    Else
    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)
    End If
		    
	'Original OU
	AddRenameToOption selRenameTo, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,dc=local|TESTNAVAL1-YYYY"
	AddRenameToOption selRenameTo, "Alamo D01 2-3 Lab", "OU=Alamo Room D01 Student,OU=RM D01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,dc=local|TESTNAVAL2-YYYY"
	
	AddRenameToOption selRenameTo, "Apache Room 006 Lab", "OU=Apache Lab Room 006 Student,OU=RM 06 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,dc=local|TESTNAVAP1-YYYY"
	AddRenameToOption selRenameTo, "Apache Room 017 Lab", "OU=Apache Lab Room 017 Student,OU=Apache Lab Room 017,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,dc=local|TESTNAVAP2-YYYY"
	AddRenameToOption selRenameTo, "Apache Room 326 Lab", "OU=Apache Lab Room 326 Student,OU=RM 326 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,dc=local|TESTNAVAP3-YYYY"
	
	AddRenameToOption selRenameTo, "Intermediate Room 001 Lab", "OU=Intermediate Lab Room 001 Student,OU=RM 01 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN1-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Room 012 Lab", "OU=Intermediate Lab Room 012 Student,OU=RM 12 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN2-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Room 027 Lab", "OU=Intermediate Lab Room 027 Student,OU=RM 27 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN3-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Room 028 Lab", "OU=Intermediate Lab Room 028 Student,OU=RM 28 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN4-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Mobile Lab", "OU=Mobile Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN5-YYYY"
	
	AddRenameToOption selRenameTo, "Middle School Room 110 Lab", "OU=Middle School 110 Lab Student,OU=RM 110 Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS1-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 111 Lab", "OU=Middle School 111 Lab Student,OU=RM 111 Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS2-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 118 Lab", "OU=Middle School Math Lab Student,OU=RM 118 Math Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS3-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 125 Lab", "OU=Middle School Science Lab Student,OU=RM 125 Science Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS4-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 126 Lab", "OU=Middle School Robotics Lab Student,OU=RM 126 Robotics Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS5-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 127 Lab", "OU=Middle School Spec-Ed Lab Student,OU=RM 127 Spec-Ed Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS6-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 130 Lab", "OU=Middle School Reading Lab Teacher,OU=RM 130 Reading Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS7-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 141 Lab", "OU=Student,OU=RM 141 Mobile Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS8-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room GCS Lab", "OU=Middle School GCS Lab Student,OU=RM GCS Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS9-YYYY"
	
	AddRenameToOption selRenameTo, "High School Room 11 Lab", "OU=HS Lab Room 11 Student,OU=RM 11 Panther Den Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS1-YYYY"
	AddRenameToOption selRenameTo, "High School Room 12 Lab", "OU=HS Lab Room 12 Student,OU=RM 12 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS2-YYYY"
	AddRenameToOption selRenameTo, "High School Room 13 Lab", "OU=High School Room 013 Student,OU=Rm 013 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS3-YYYY"
	AddRenameToOption selRenameTo, "High School Room 47 Lab", "OU=HS Lab Room 47 Student,OU=RM 47 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS6-YYYY"
	AddRenameToOption selRenameTo, "High School Room 48 Lab", "OU=HS Lab Room 48 Student,OU=RM 48 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS4-YYYY"
	AddRenameToOption selRenameTo, "High School Room 148 Lab", "OU=HS GCS Lab Student,OU=RM GCS Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS5-YYYY"
	AddRenameToOption selRenameTo, "High School Room 149 Lab", "OU=HS GCS Lab Student,OU=RM GCS Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS7-YYYY"
	
	AddRenameToOption selRenameTo, "Technology East Lab", "OU=East Computers,OU=East Lab,OU=Training Lab,OU=Technology Center,OU=Locations,DC=domain,dc=local|TESTNAVTC1-YYYY"
	AddRenameToOption selRenameTo, "Technology West Lab", "OU=West Computers,OU=West Lab,OU=Training Lab,OU=Technology Center,OU=Locations,DC=domain,dc=local|TESTNAVTC2-YYYY"
	
	'Testing OU
	AddRenameToOption selRenameFrom, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameFrom, "Alamo C01 K-1 Lab", "OU=Alamo,OU=TESTNAV,DC=domain,dc=local|ALRMC01YYYY"
	AddRenameToOption selRenameFrom, "Alamo D01 2-3 Lab", "OU=Alamo,OU=TESTNAV,DC=domain,dc=local|ALRMD01YYYY"
	
	AddRenameToOption selRenameFrom, "Apache Room 006 Lab", "OU=Apache,OU=TESTNAV,DC=domain,dc=local|APRM006YYYY"
	AddRenameToOption selRenameFrom, "Apache Room 017 Lab", "OU=Apache,OU=TESTNAV,DC=domain,dc=local|APRM017YYYY"
	AddRenameToOption selRenameFrom, "Apache Room 326 Lab", "OU=Apache,OU=TESTNAV,DC=domain,dc=local|APRM326YYYY"
	
	AddRenameToOption selRenameFrom, "Intermediate Room 001 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM001YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Room 012 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM012YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Room 027 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM027YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Room 028 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM028YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Mobile Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INML001YYYY"
	
	AddRenameToOption selRenameFrom, "Middle School Room 110 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM110YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 111 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM111YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 118 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM118YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 125 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM125YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 126 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM126YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 127 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM127YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 130 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM130YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 141 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM141YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 148 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM148YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 149 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM149YYYY"
	
	AddRenameToOption selRenameFrom, "High School Room 11 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM011YYYY"
	AddRenameToOption selRenameFrom, "High School Room 12 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM012YYYY"
	AddRenameToOption selRenameFrom, "High School Room 13 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM013YYYY"
	AddRenameToOption selRenameFrom, "High School Room 47 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM047YYYY"
	AddRenameToOption selRenameFrom, "High School Room 48 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM048YYYY"
	AddRenameToOption selRenameFrom, "High School GCS Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRMGCSYYYY"
	
	AddRenameToOption selRenameFrom, "Technology East Lab", "OU=Technology,OU=TESTNAV,DC=domain,dc=local|TCLATLEYYYY"
	AddRenameToOption selRenameFrom, "Technology West Lab", "OU=Technology,OU=TESTNAV,DC=domain,dc=local|TCLATLWYYYY"
End Sub

Sub ElevatedCheck
	'Source: http://www.thegbach.com/elevatedHta.html
	Set objShell = CreateObject("WScript.Shell")
	Set objShellApp = CreateObject("Shell.Application")
	strElevated = False
	strHTADir = document.location.pathname
	Set objWhoami = objShell.Exec("whoami /groups")
	strWhoami = objWhoami.StdOut.ReadAll
	If InStr(1, strWhoami,"S-1-16-12288",vbTextCompare) Then
	strElevated = True
	Else
		objShellApp.ShellExecute"mshta.exe",Chr(34) & strHTADir & Chr(34) & " runasadministrator","","runas",1
		window.close()
	End If 
End Sub

SUB Check_M_All(checkNum) 
   ON ERROR RESUME NEXT 
       checkNum.Checked = TRUE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.length - 1 
               checkNum(i).checked = TRUE 
           Next 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
 SUB Uncheck_M_All(checkNum)
   ON ERROR RESUME NEXT 
       checkNum.Checked = FALSE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.Length - 1 
               checkNum(i).Checked = FALSE 
           NEXT 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
Private Sub Panel(tab) 
	For i = 1 To iPanelCount 
		If i = tab Then 
			document.getElementById("tab" & i).className = "tabs tabsSelected" 
			document.getElementById("panel" & i).style.display = "block" 
		Else 
			document.getElementById("tab" & i).className = "tabs tabsNotSelected" 
			document.getElementById("panel" & i).style.display = "none" 
		End If 
	Next 
End Sub 

Sub AddRenameToOption(objObject, strText, strValue)
	Set objOption = Document.CreateElement("OPTION")
	objOption.Text = strText
	objOption.Value = strValue
	objObject.Add(objOption)
End Sub

'Tab 1
Sub TestSub
	strText = selRenameTo.Item(selRenameTo.SelectedIndex).Text
	strValue = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Value, "|")(0)
	strNaming = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Value, "|")(1)
	'MsgBox strText & vbCrLf & strValue
	Set objOU = GetObject("LDAP://" & strValue)
	strNames = ""
	intCol = 0
	strNames = "<table cellspacing=10 cellpadding=0 border=0>"
	For Each objObject In objOU
		If objObject.class = "computer" Then
			strCheckBoxCode = ""
			If intCol = 0 Then
				strCheckBoxCode = "<tr>"
			End If
			strCheckBoxCode = strCheckBoxCode & "<td><font color=""white""><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum"" value=""" & objObject.distinguishedName & "|" & strNaming & """>" & Mid(objObject.Name, 4) & "</font></td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode = strCheckBoxCode & "</tr>"
				intCol = 0
			End If
			If strNames = "" Then
				strNames = strCheckBoxCode
			Else
				strNames = strNames & vbCrLf & strCheckBoxCode
			End If
		End If
	Next
	strNames = strNames & vbCrLf & "</table>"
    instPath.InnerHTML = strNames
End Sub

'Tab 2
Sub TestSub2
	strText2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Text
	strValue2 = Split(selRenameFrom.Item(selRenameFrom.SelectedIndex).Value, "|")(0)
	strNaming2 = Split(selRenameFrom.Item(selRenameFrom.SelectedIndex).Value, "|")(1)
'	MsgBox strText2 & vbCrLf & strValue2
	Set objOU2 = GetObject("LDAP://" & strValue2)
	strNames2 = ""
	intCol = 0
	strNames2 = "<table cellspacing=10 cellpadding=0 border=0>"
	For Each objObject In objOU2
		If objObject.class = "computer" Then
			strCheckBoxCode2 = ""
			If intCol = 0 Then
				strCheckBoxCode2 = "<tr>"
			End If
			strCheckBoxCode2 = strCheckBoxCode2 & "<td><font color=""white""><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum2"" value=""" & objObject.distinguishedName & "|" & strNaming2 & """>" & Mid(objObject.Name, 4) & "</font></td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode2 = strCheckBoxCode2 & "</tr>"
				intCol = 0
			End If
			If strNames2 = "" Then
				strNames2 = strCheckBoxCode2
			Else
				strNames2 = strNames2 & vbCrLf & strCheckBoxCode2
			End If
		End If
	Next
	strNames2 = strNames2 & vbCrLf & "</table>"
    instPath2.InnerHTML = strNames2
End Sub

Sub RenameTo(checknum)
	Set objShell = CreateObject("WScript.Shell")
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	blnComputerRenamed = False
	Set dctToRename = CreateObject("Scripting.Dictionary")
	dctToRename.CompareMode = vbTextCompare
	blnShutdown = MsgBox("Do you want to shut down non-selected computers in this OU?", vbYesNo, "Shutdown computers?")
	FOR i = 0 TO checkNum.length - 1 
		If checknum(i).checked = True Then
			'MsgBox "Renaming " & checknum(i).id & vbCrLf& checknum(i).value & vbCrLf & " to " & strNewComputer
			strComputer = checknum(i).id
			strDN = Split(checknum(i).value, "|")(0)
			strParentOU = Split(Mid(checknum(i).value,INSTR(checknum(i).value,",")+1,LEN(checknum(i).value)-INSTR(checknum(i).value,",")), "|")(0)
			strNamingConvention = Split(Mid(checknum(i).value,INSTR(checknum(i).value,",")+1,LEN(checknum(i).value)-INSTR(checknum(i).value,",")), "|")(1)
			If Ping(strComputer) = True Then
				MsgBox "1. " & strComputer & vbCrLf & "2. " & strDN & vbCrLf & "3. " & strParentOU & vbCrLf & "3. " & strNamingConvention
				strNewPCName = RenameSinglePC(strComputer, strParentOU, strNamingConvention)
				blnComputerRenamed = True
				dctToRename.Add strComputer, strNewPCName
			Else
				objShell.Popup strComputer & " is not online.  Cannot rename computer.", 2, strComputer & " not online"
				checknum(i).checked = False
			End If
		Else
			If blnShutdown = vbYes Then
				objShell.Popup "Shutting down " & checknum(i).id, 1, checknum(i).id
				objShell.Run "cmd /c shutdown /s /t 00 /m " & checknum(i).id
			End If
		End If
	Next
	'Exit Sub ' ***
	If blnComputerRenamed = True Then
		dteEndTime = DateAdd("s", 300, Now)
		While DateDiff("s", Now, dteEndTime) > 0
			intWait = DateDiff("s", Now, dteEndTime)
			If DateDiff("s", Now, dteEndTime) > 30 Then intWait = 30
			objShell.Popup "Waiting " & DateDiff("s", Now, dteEndTime) & " seconds.", intWait, "Waiting for computers to be placed in the correct OU..."
		Wend
		strPSExec = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "PSExec.exe"
		If objFSO.FileExists(strPSExec) = True Then
			For Each strPC In dctToRename
				objShell.Popup "Running gpupdate on " & dctToRename(strPC), 1, "GPUpdate on " & dctToRename(strPC)
				objShell.Run "cmd /c " & objFSO.GetFile(strPSExec).ShortPath & " -accepteula \\" & dctToRename(strPC) & " gpupdate /force", 0, True
				objShell.Run "cmd /c shutdown /r /t 00 /m " & dctToRename(strPC)
			Next
		Else
			MsgBox "Unable to find " & strPSExec & " to run GPUpdate"
		End If
	End If
End Sub

Function RenameSinglePC(strComputer, strOU, strConvention)
	strDomainUser = document.getElementById("uName").value & "@domain.local"
	strDomainPasswd = document.getElementById("uPassword").value
	strLocalUser = strComputer & "\administrator"
	strLocalPasswd = "password"
	arrLabParts = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Text, " ")
       'strNewComputer = "TESTNAV" & Left(selRenameTo.Item(selRenameTo.SelectedIndex).Text, 2) & arrLabParts(UBound(arrLabParts) - 1) & "-" & Right(strComputer, 4)
    strNewComputer = Replace(strConvention, "YYYY", Right(strComputer, 4))
	'MsgBox strNewComputer
	'Exit Function
	'########################### 
	' Connect to Computer 
	'###########################
	Dim objWMILocator, objWMIComputer, objWMIComputerSystem, rc, objWMIService, colOperatingSystems, objOperatingSystem, objNetwork, objComputer
	Set objNetwork = CreateObject("WScript.Network")
	'Set objWMIComputer = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd) 
	'Set objWMIComputerSystem = objWMIComputer.Get( "Win32_ComputerSystem.Name='" & strComputer & "'") 
	If LCase(strComputer) = LCase(objNetwork.ComputerName) Then
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, authenticationLevel=pktPrivacy, (Shutdown)}!\\" & strComputer & "\root\cimv2") 
	Else
		Set objWMILocator = CreateObject("WbemScripting.SWbemLocator") 
		objWMILocator.Security_.AuthenticationLevel = 6 
		Set objWMIService = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd)
	End If
	'########################### 
	' Rename Computer 
	'########################### 
	Set objWMIComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem Where Name='" & strComputer & "'")
	For Each objWMIComputerSystem In objWMIComputer
		' There will only ever be one element in this collection
		rc = objWMIComputerSystem.Rename(strNewComputer, strDomainPasswd, strDomainUser) 
		if rc <> 0 then 
			Msgbox "Failed to rename " & strComputer & " to " & strNewComputer & " with error: " & rc 
		else 
			Msgbox "Successfully renamed " & strComputer & " to " & strNewComputer
			'########################### 
			' Place text files on the CURRENT computer that you are running this management from
			'###########################
			'Set objFSO = CreateObject("Scripting.FileSystemObject")
			'strLogFolder = "C:\PCs_Renamed\"
			'If objFSO.FolderExists(strLogFolder) = False Then objFSO.CreateTextFile strLogFolder
			'Set objFile = objFSO.CreateTextFile(strLogFolder & strNewComputer & ".txt", True)
			'objFile.Write strComputer & ";" & strOU
			'objFile.Close
			'########################### 
			' Reboot computer
			'###########################
			'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
	If rc <> 0 Then
		RenameSinglePC = "FAILED"
	Else
		RenameSinglePC = strNewComputer
	End If
End Function

sub disableButton()
  document.GetElementByID("RenameFrom").disabled = True
  document.GetElementByID("RenameTo").disabled = true
end Sub

Sub RenameFrom(checknum2)
	Set objShell = CreateObject("WScript.Shell")
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	blnComputerRenamed2 = False
	Set dctToRename = CreateObject("Scripting.Dictionary")
	dctToRename.CompareMode = vbTextCompare
	blnShutdown = MsgBox("Do you want to shut down non-selected computers in this OU?", vbYesNo, "Shutdown computers?")
	For i = 0 TO checkNum2.Length - 1 
		If checknum2(i).checked = True Then
'			MsgBox "Renaming " & checknum2(i).id & vbCrLf& checknum2(i).value & vbCrLf & " to " & strNewComputer
			strComputer2 = checknum2(i).id
			strDN2 = Split(checknum2(i).value, "|")(0)
			strParentOU2 = Split(Mid(checknum2(i).value,INSTR(checknum2(i).value,",")+1,LEN(checknum2(i).value)-INSTR(checknum2(i).value,",")), "|")(0)
			strNamingConvention2 = Split(Mid(checknum2(i).value,INSTR(checknum2(i).value,",")+1,LEN(checknum2(i).value)-INSTR(checknum2(i).value,",")), "|")(1)
			If Ping(strComputer2) = True Then
				MsgBox "1. " & strComputer2 & vbCrLf & "2. " & strDN2 & vbCrLf & "3. " & strParentOU2 & vbCrLf & "4. " & strNamingConvention2
				strNewPCName2 = RenameSinglePC(strComputer2, strParentOU2, strNamingConvention2)
				blnComputerRenamed2 = True
				dctToRename.Add strComputer2, strNewPCName2
			Else
				objShell.Popup strComputer2 & " is not online.  Cannot rename computer.", 2, strComputer2 & " not online"
				checknum2(i).checked = False
			End If
		Else
			If blnShutdown = vbYes Then
				objShell.Popup "Shutting down " & checknum2(i).id, 1, checknum2(i).id
				objShell.Run "cmd /c shutdown /s /t 00 /m " & checknum2(i).id
			End If
		End If
	Next
	'Exit Sub ' ***
	If blnComputerRenamed = True Then
		dteEndTime = DateAdd("s", 300, Now)
		While DateDiff("s", Now, dteEndTime) > 0
			intWait = DateDiff("s", Now, dteEndTime)
			If DateDiff("s", Now, dteEndTime) > 30 Then intWait = 30
			objShell.Popup "Waiting " & DateDiff("s", Now, dteEndTime) & " seconds.", intWait, "Waiting for computers to be placed in the correct OU..."
		Wend
		strPSExec = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "PSExec.exe"
		If objFSO.FileExists(strPSExec) = True Then
			For Each strPC In dctToRename
				objShell.Popup "Running gpupdate on " & dctToRename(strPC), 1, "GPUpdate on " & dctToRename(strPC)
				objShell.Run "cmd /c " & objFSO.GetFile(strPSExec).ShortPath & " -accepteula \\" & dctToRename(strPC) & " gpupdate /force", 0, True
				objShell.Run "cmd /c shutdown /r /t 00 /m " & dctToRename(strPC)
			Next
		Else
			MsgBox "Unable to find " & strPSExec & " to run GPUpdate"
		End If
	End If
End Sub

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

</script> 

</head> 


<body bgcolor="blue"> 
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650"> 
<tr valign="top"> 
<td colspan="2"> 
<span class="tabs tabsSelected" id="tab1" onclick="panel(1)">Rename Computers for Testing</span> 
<span class="tabs tabsNotSelected" id="tab2" onclick="panel(2)">Rename Computers back from Testing</span>
<!-- Tab 1 -->
<div class="panel" id="panel1" style="display:block"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<td style="text-align:right;font-size:0.9em;font-weight:bold;font-style:oblique;color:#888888;">
				Created by Gabriel Clifton
			</td>
		</tr>
	</table>
<!--Add your controls here-->
<select size="1" onChange="TestSub" name="selRenameTo" id="selRenameTo"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll" value="Check All" onclick="Check_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="uchckAll" value="Un-Check All" onclick="UNCheck_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="RenameTo" value="Rename To" onclick="RenameTo(document.myform.checkNum)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform" method="post">
            <span  id="instPath"></span>
        </font></form>
    </TH>
    </tr>
 </table>
  <table>
 	<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>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

<!-- Tab 2 -->
<div class="panel" id="panel2" style="display:none"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<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>

<!--Add your controls here-->
<select size="1" onChange="TestSub2" name="selRenameFrom" id="selRenameFrom"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename back</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll2" value="Check All" onclick="Check_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="uchckAll2" value="Un-Check All" onclick="Uncheck_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="RenameFrom" value="Rename From" onclick="RenameFrom(document.myform2.checkNum2)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform2" method="post">
            <span  id="instPath2"></span>
        </font></form>
    </TH>
    </tr>
 </table>
 <table>
 	<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>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

</body> 
</html>

Open in new window

0
 
David Johnson, CD, MVPOwnerCommented:
first you have to convert the batch file to vbscript  

work in progress
<html>
<head>
<title>Main Menu</title>
<HTA:APPLICATION
  APPLICATIONNAME="My HTML application"
  ID="MyHTMLapplication"
  SCROLL = "yes"
  SINGLEINSTANCE = "yes"
  VERSION="1.0"/>
  
</head>

<script language="VBScript">

Sub Window_OnLoad
  'This method will be called when the application loads
  'Add your code here
End Sub


Sub TestSub

For Each objButton in RadioOption
            If objButton.Checked Then
                selection = objButton.Value
            End If
        Next
               Select Case Selection
                Case "1"
	                strCOU="OU=Lab 1,OU=Campus 1,DC=domain,DC=local"
	                strcmps="AL"
	                strtnvou="OU=Campus 1,OU=TESTNAV,DC=domain,DC=local"
	                strlab=1 
             End Select   
             'do something hereSelect Case {testexpression}
          
    End Sub
</script>
<body bgcolor="white">

<!--Add your controls here-->
 <input type="radio" name="RadioOption" value="1">Campus 1 C01 K-1 Lab<BR>
 <input type="radio" name="RadioOption" value="2">Campus 1 D01 2-3 Lab<BR>
 <input type="radio" name="RadioOption" value="3">Campus 2 Room 006 Lab<BR>
 <input type="radio" name="RadioOption" value="4">Campus 2 Room 017 Lab<BR>
 <input type="radio" name="RadioOption" value="5">Campus 2 Room 326 Lab<BR>
 <input type="radio" name="RadioOption" value="6">Campus 3 Room 001<BR>
 <input type="radio" name="RadioOption" value="7">Campus 3 Room 027 Lab<BR>    
 <input type="radio" name="RadioOption" value="8">Campus 4 Room 110 Lab<BR>
 <input type="radio" name="RadioOption" value="9">Campus 4 Room 111 Lab<BR>
 <input type="radio" name="RadioOption" value="10">Campus 5 Room 11 Lab<BR>
 <input type="radio" name="RadioOption" value="11">Campus 5 Room 12 Lab<BR>
 <input type="radio" name="RadioOption" value="12">Campus 5 Room 13 Lab<BR>
 <input type="radio" name="RadioOption" value="13">Campus 5 Room 48 Lab<BR>
 <input type="radio" name="RadioOption" value="14">Campus 5 GCS Lab<BR>    
 <input type="radio" name="RadioOption" value="14">Campus 6 East Lab<BR>
 <input type="radio" name="RadioOption" value="15">Campus 6 West Lab<BR>
 <input type="radio" name="RadioOption" value="0">Exit<BR>  
  <input id=runbutton  class="button" type="button" value="Run Script" name="run_button"  onClick="TestSub">
 <!--{{InsertControlsHere}}-Do not remove this line-->
</body>
</html>

Open in new window

0
 
Gabriel CliftonNet AdminAuthor Commented:
Translating the logic I am most familiar with, batch script, to something that I can read and fairly understand and have difficulty writing, vbscript is what is troubling me the most. Yes, I understand the best logic for anything Microsoft is there is no logic. I have been playing with your code and right now I have it with some modifications like changing the radio to dropdown for choosing the campus because I did not want the HTA screen to get too big when we add the display / choose computers from OU. I also added the tabbed navigation, but for some reason I cannot get the dropdown menu for tab 2 off of tab 1 and vice versa.

<html>
<head>
<title>Main Menu</title>
<HTA:APPLICATION
	ICON="\\server\share\panther.ICO"
	APPLICATIONNAME="RenLab"
	ID="objRenLab" 
	VERSION="1.2"
	BORDER="dialog"
	SCROLL="no" 
	MAXIMIZEBUTTON="no"
	SINGLEINSTANCE="no"
	CONTEXTMENU="no"
	WINDOWSTATE="normal"/>

<style>
..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>
</head>

<script language="VBScript">
	Sub Window_onLoad
	width = "800"
	height = "700"
	' 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 
	window.moveTo intLeft, intTop
'		VersionInfo.InnerHTML = "Version: " & objRenLab.Version
	End Sub
	
' Subroutine to run when form is loaded.  Set to display panel1 at launch.
sub onLoad()
 document.GetElementById("panel1").style.display = "block"
end sub


' Subroutine to change panels.  The do loop will need adjusted for the amount of tabs present.
sub selPanel(number)
 i = 1
 do while i <= 2
      if i = number then
     document.GetElementById("panel" & Cstr(i)).style.display = "block"
      document.GetElementById("tab" & Cstr(i)).className = "tabs tabs1"
        else
           document.GetElementById("panel" & Cstr(i)).style.display = "none"
     document.GetElementById("tab" & Cstr(i)).className = "tabs tabs0"
        end if
    i = i + 1
    loop
end sub

Sub TestSub

For Each objOption in RadioOption
            If objOption.Selected Then
                selection = objOption.Value
            End If
        Next
               Select Case Selection
                Case "1"
	                strCOU="OU=Lab 1,OU=Campus 1,DC=domain,DC=local"
	                strcmps="AL"
	                strtnvou="OU=Campus 1,OU=TESTNAV,DC=domain,DC=local"
	                strlab=1 
             End Select   
             'do something hereSelect Case {testexpression}
          ' This MsgBox is for testing only, remove when in production
          MsgBox strCOU & vbCrLf & strcmps & vbCrLf & strtnvou & vbCrLf & strlab
          
    End Sub
    
Sub TestSub2

For Each objOption in RadioOption2
            If objOption.Selected Then
                selection = objOption.Value
            End If
        Next
               Select Case Selection
                Case "1"
	                strCOU="OU=Campus 1,OU=TESTNAV,DC=domain,DC=local"
	                strcmps="AL"
	                strtnvou="OU=Lab 1,OU=Campus 1,DC=domain,DC=local"
	                strlab=1 
             End Select   
             'do something hereSelect Case {testexpression}
          ' This MsgBox is for testing only, remove when in production
          MsgBox strCOU & vbCrLf & strcmps & vbCrLf & strtnvou & vbCrLf & strlab
          
    End Sub
    
</script>
<body bgcolor="blue" onload="onLoad()">

<!--=========================================================================-->
<!--This is the tab bar section at the top.  Add another td for more tabs.
<!--Don't forget to add a corresponding panel!
<!--=========================================================================-->
<table class="nav">
 <tr valign="top">
  <td class="tabs tabs1" id="tab1" onclick="selPanel(1)">Rename Computers for Testing</td>
  <td class="tabs tabs0" id="tab2" onclick="selPanel(2)">Rename Computers back from Testing</td>
 </tr>
</table>


<!--=========================================================================-->
<!-- This is the panel section in the main body.  Put the code for your
<!-- panel between the div tags.  Add more div tags for more panels.  
<!-- Don't forget to add the corresponding tab!
<!--=========================================================================-->
<div id="divbody">
<div cellpadding="0" class="panel" id ="panel1" style="display:block">
<table border="0" width="100%"  cellspacing="0" cellpadding="0">
    <tr>
        <td width="33%" valign="top"><img src="\\server\share\Logo_Large.png" alt="Panther" width="110" height="110"></td>
        <td width="34%" valign="top">
        <font size="6" 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\Logo_Large.png" alt="Panther" width="110" height="110"></td>
  </tr>
</table>
	<table style="width:100%;">
		<tr>
			<td style="text-align:right;font-size:0.9em;font-weight:bold;font-style:oblique;color:#888888;">
				Created by Gabriel Clifton
			</td>
		</tr>
	</table>
	<hr>
	</div>
	<br>
	<span style="position:absolute;bottom:10px;font-weight:bold;font-style:italic;font-size:0.9em;color:#888888;" id="VersionInfo">
	</span>
</div>

<br>
<br>

<!--Add your controls here-->
<select size="1" name="RadioOption" onChange="TestSub">
 <option value="0">Select Lab<BR>
 <option value="1">Campus 1 C01 K-1 Lab<BR>
 <option value="2">Campus 1 D01 2-3 Lab<BR>
 <option value="3">Campus 2 Room 006 Lab<BR>
 <option value="4">Campus 2 Room 017 Lab<BR>
 <option value="5">Campus 2 Room 326 Lab<BR>
 <option value="6">Campus 3 Room 001<BR>
 <option value="7">Campus 3 Room 027 Lab<BR>    
 <option value="8">Campus 4 Room 110 Lab<BR>
 <option value="9">Campus 4 Room 111 Lab<BR>
 <option value="10">Campus 5 Room 11 Lab<BR>
 <option value="11">Campus 5 Room 12 Lab<BR>
 <option value="12">Campus 5 Room 13 Lab<BR>
 <option value="13">Campus 5 Room 48 Lab<BR>
 <option value="14">Campus 5 GCS Lab<BR>    
 <option value="14">Campus 6 East Lab<BR>
 <option value="15">Campus 6 West Lab<BR>
 <option value="0">Exit<BR>  
</select>
 <!--{{InsertControlsHere}}-Do not remove this line-->
 
<!-- Tab 2 -->
<div cellpadding="0" class="panel" id ="panel2" style="display:none">
<table border="0" width="100%"  cellspacing="0" cellpadding="0">
    <tr>
        <td width="33%" valign="top"><img src="\\server\share\Logo_Large.png" alt="Panther" width="110" height="110"></td>
        <td width="34%" valign="top">
        <font size="6" 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\Logo_Large.png" alt="Panther" width="110" height="110"></td>
  </tr>
</table>
	<table style="width:100%;">
		<tr>
			<td style="text-align:right;font-size:0.9em;font-weight:bold;font-style:oblique;color:#888888;">
				Created by Gabriel Clifton
			</td>
		</tr>
	</table>
	<hr>
	</div>
	<br>
	<span style="position:absolute;bottom:10px;font-weight:bold;font-style:italic;font-size:0.9em;color:#888888;" id="VersionInfo">
	</span>
</div>

<!--Add your controls here-->
<select size="1" name="RadioOption2" onChange="TestSub2">
 <option value="0">Select Lab<BR>
 <option value="1">Campus 1 C01 K-1 Lab<BR>
 <option value="2">Campus 1 D01 2-3 Lab<BR>
 <option value="3">Campus 2 Room 006 Lab<BR>
 <option value="4">Campus 2 Room 017 Lab<BR>
 <option value="5">Campus 2 Room 326 Lab<BR>
 <option value="6">Campus 3 Room 001<BR>
 <option value="7">Campus 3 Room 027 Lab<BR>    
 <option value="8">Campus 4 Room 110 Lab<BR>
 <option value="9">Campus 4 Room 111 Lab<BR>
 <option value="10">Campus 5 Room 11 Lab<BR>
 <option value="11">Campus 5 Room 12 Lab<BR>
 <option value="12">Campus 5 Room 13 Lab<BR>
 <option value="13">Campus 5 Room 48 Lab<BR>
 <option value="14">Campus 5 GCS Lab<BR>    
 <option value="14">Campus 6 East Lab<BR>
 <option value="15">Campus 6 West Lab<BR>
 <option value="0">Exit<BR>  
</select>
 <!--{{InsertControlsHere}}-Do not remove this line-->

<br>
<br>
</body>
</html>

Open in new window

0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
David Johnson, CD, MVPOwnerCommented:
had to comment out line 65 and 66 due to script errors
      window.resizeTo width,height
'      window.moveTo intLeft, intTop
'            VersionInfo.InnerHTML = "Version: " & objRenLab.Version
      End Sub
0
 
Gabriel CliftonNet AdminAuthor Commented:
66 was already commented out because of errors, but for me 65 works with no issues.
0
 
Gabriel CliftonNet AdminAuthor Commented:
Sorry, now looking at my prior post. Line 65 already commented out, 64 working.
0
 
Gabriel CliftonNet AdminAuthor Commented:
OK, I have reworked the code and the tabs are working as they are supposed to, now I have to work on the functionality.

<html> 
<head> 
<title>Rename Computer Labs for state testing</title> 
<HTA:Application 
ID = "HTA" 
ApplicationName = "RenLab" 
Border = "dialog" 
BorderStyle = "normal" 
Caption = "yes" 
ContextMenu="yes" 
ICON="\\server\share\panther.ICO"
InnerBorder="no" 
MaximizeButton = "no" 
MinimizeButton = "no" 
Navigable="yes" 
Scroll="yes" 
SrollFlat="no" 
Selection="yes" 
ShowInTaskBar = "yes" 
SingleInstance = "yes" 
SysMenu = "yes" 
Version = "1.0" 
> 
<style>
.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; 
} 
.tabsNotSelected { 
background-color: wheat; 
border: solid 1px black; 
} 
.tabsSelected { 
background-color: white; 
border-color: black black white black; 
border-style: solid solid solid solid; 
border-width: 1px 1px 1px 1px; 
} 
</style>
<script language="VBscript"> 
Dim sItem 
Dim aPanels 
Dim el 
Dim iPanelCount 
iPanelCount = 2
Private Sub Panel(tab) 
For i = 1 To iPanelCount 
If i = tab Then 
document.getElementById("tab" & i).className = "tabs tabsSelected" 
document.getElementById("panel" & i).style.display = "block" 
Else 
document.getElementById("tab" & i).className = "tabs tabsNotSelected" 
document.getElementById("panel" & i).style.display = "none" 
End If 
Next 
End Sub 
Sub AddCheck 
strHTML = panelContents2.InnerHTML 
strHTML = strHTML & "<input id=" & intCheckCount & " type=" & Chr(34) & "CheckBox" & Chr(34) & _ 
" name=" & Chr(34) & "chkEnabled" & Chr(34) & "value= " & Chr(34) & "CheckBox" & intCheckCount & Chr(34) & " onClick=" & Chr(34) & _ 
"NewCheckSubroutine" & Chr(34) & ">" & " <BR>" 
panelContents2.InnerHTML = strHTML 
End Sub 

'Tab 1
Sub TestSub

For Each objOption in RadioOption
            If objOption.Selected Then
                selection = objOption.Value
            End If
        Next
               Select Case Selection
                Case "1"
	                strCOU="OU=Lab 1,OU=Campus 1,DC=domain,DC=local"
	                strcmps="AL"
	                strtnvou="OU=Campus 1,OU=TESTNAV,DC=domain,DC=local"
	                strlab=1 
             End Select   
             'do something hereSelect Case {testexpression}
          ' This MsgBox is for testing only, remove when in production
          MsgBox strCOU & vbCrLf & strcmps & vbCrLf & strtnvou & vbCrLf & strlab
          
    End Sub
    
'Tab 2
Sub TestSub2

For Each objOption2 in RadioOption2
            If objOption2.Selected Then
                selection = objOption2.Value
            End If
        Next
               Select Case Selection
                Case "1"
	                strCOU="OU=Campus 1,OU=TESTNAV,DC=domain,DC=local"
	                strcmps="AL"
	                strtnvou="OU=Lab 1,OU=Campus 1,DC=domain,DC=local"
	                strlab=1 
             End Select   
             'do something hereSelect Case {testexpression}
          ' This MsgBox is for testing only, remove when in production
          MsgBox strCOU & vbCrLf & strcmps & vbCrLf & strtnvou & vbCrLf & strlab

    End Sub
    
</script> 

</head> 


<body bgcolor="blue"> 
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650"> 
<tr valign="top"> 
<td colspan="2"> 
<span class="tabs tabsSelected" id="tab1" onclick="panel(1)">Rename Computers for Testing</span> 
<span class="tabs tabsNotSelected" id="tab2" onclick="panel(2)">Rename Computers back from Testing</span>
<!-- Tab 1 -->
<div class="panel" id="panel1" style="display:block"> 
<table border="0" width="100%"  cellspacing="0" cellpadding="0">
    <tr>
        <td width="33%" valign="top"><img src="\\server\share\Logo_Large.png" alt="Panther" width="110" height="110"></td>
        <td width="34%" valign="top">
        <font size="6" 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\Logo_Large.png" alt="Panther" width="110" height="110"></td>
  </tr>
</table>

	<table style="width:100%;">
		<tr>
			<td style="text-align:right;font-size:0.9em;font-weight:bold;font-style:oblique;color:#888888;">
				Created by Gabriel Clifton
			</td>
		</tr>
	</table>
<!--Add your controls here-->
<select size="1" name="RadioOption" onChange="TestSub">
 <option value="0">Select Lab<BR>
 <option value="1">Campus 1 C01 K-1 Lab<BR>
 <option value="2">Campus 1 D01 2-3 Lab<BR>
 <option value="3">Campus 2 Room 006 Lab<BR>
 <option value="4">Campus 2 Room 017 Lab<BR>
 <option value="5">Campus 2 Room 326 Lab<BR>
 <option value="6">Campus 3 Room 001<BR>
 <option value="7">Campus 3 Room 027 Lab<BR>    
 <option value="8">Campus 4 Room 110 Lab<BR>
 <option value="9">Campus 4 Room 111 Lab<BR>
 <option value="10">Campus 5 Room 11 Lab<BR>
 <option value="11">Campus 5 Room 12 Lab<BR>
 <option value="12">Campus 5 Room 13 Lab<BR>
 <option value="13">Campus 5 Room 48 Lab<BR>
 <option value="14">Campus 5 GCS Lab<BR>    
 <option value="14">Campus 6 East Lab<BR>
 <option value="15">Campus 6 West Lab<BR>
 <option value="0">Exit<BR>  
</select>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

<!-- Tab 2 -->
<div class="panel" id="panel2" style="display:none"> 
<table border="0" width="100%"  cellspacing="0" cellpadding="0">
    <tr>
        <td width="33%" valign="top"><img src="\\server\share\Logo_Large.png" alt="Panther" width="110" height="110"></td>
        <td width="34%" valign="top">
        <font size="6" 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\Logo_Large.png" alt="Panther" width="110" height="110"></td>
  </tr>
</table>

	<table style="width:100%;">
		<tr>
			<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>

<!--Add your controls here-->
<select size="1" name="RadioOption2" onChange="TestSub2">
 <option value="0">Select Lab<BR>
 <option value="1">Campus 1 C01 K-1 Lab<BR>
 <option value="2">Campus 1 D01 2-3 Lab<BR>
 <option value="3">Campus 2 Room 006 Lab<BR>
 <option value="4">Campus 2 Room 017 Lab<BR>
 <option value="5">Campus 2 Room 326 Lab<BR>
 <option value="6">Campus 3 Room 001<BR>
 <option value="7">Campus 3 Room 027 Lab<BR>    
 <option value="8">Campus 4 Room 110 Lab<BR>
 <option value="9">Campus 4 Room 111 Lab<BR>
 <option value="10">Campus 5 Room 11 Lab<BR>
 <option value="11">Campus 5 Room 12 Lab<BR>
 <option value="12">Campus 5 Room 13 Lab<BR>
 <option value="13">Campus 5 Room 48 Lab<BR>
 <option value="14">Campus 5 GCS Lab<BR>    
 <option value="14">Campus 6 East Lab<BR>
 <option value="15">Campus 6 West Lab<BR>
 <option value="0">Exit<BR>  
</select>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

</div> 
</td> 
</tr> 
</table> 
</body> 
</html> 

Open in new window

0
 
David Johnson, CD, MVPOwnerCommented:
good going.. have you a flow chart or something so I would know when the various functions are called and what they should return?
0
 
Gabriel CliftonNet AdminAuthor Commented:
Thank you for your help. The state testing program is very finicky about what can run in the background which is why I rename them and move them to a testing OU to limit what is running. And rename back to cancel those restrictions. Before, we used to just image the computers with only what is required for the testing and have them move to the testing OU, then reimage them back. Now we have labs that have solid state drives and I did not want to put that much extra writing on them considering some of the labs are used for testing four times a year.

Not good at creating flow charts or even working them out, but I will do my best. What I am looking for here is:

Tab 1
User selects lab from drop down list.
Once the user selects the lab, the script reads the computers in that labs OU and lists them in the HTA with multi-select check boxes, if possible with a check all and clear all button. This is because sometimes when they are testing, they may use one computer or they may use them all.
When the user clicks the rename button, it automatically writes the original computer name to a text file named compname.txt in the root of the C drive, renames the computer to my testing naming scheme which is TESTNAV(First two letters campus name)(Lab number)-(Keep last four characters of the original name).
When the computer is renamed in AD, I have a vbscript that will go through my computer OUs and move computers to their correct OU based on the computer name, this happens every five minutes on the 0 and 5 so the HTA script needs to wait for that script to move the computers to the testing OU.
Once the HTA has waited, is should check that the computers are pingable, run a GPUPDATE /FORCE on those computers and reboot, check that the computer is pingable again, then GPUPDATE /FORCE / reboot again. I have found that the second reboot is necessary for the auto-login to work, I just prefer the second gpupdate. One issue I have seen with my batch script on this part is that sometimes, just because the computer is pingable, it is not always in a state that can accept gpupdates so I have to manually run the gpupdate and reboot so I would like an error check if the gpupdate fails, wait and try again, maximum retries something like 5. I would like it to list any computers that failed the gpupdate so the tech knows to find out why and hit those manually.

Tab 2
Tab 2 will be the same as tab 1 but do the opposite. When the tech selects the computer lab, it will display the computers in the testing OU that were originally in that lab and let you select which computers to rename back to original name which is now stored in C:\compname.txt. Wait for the computers to move back into their original OU, gpupdate and reboot twice to undo the changes that the testing OU sets including the auto-login.

My labs have their own OUs which makes identifying which computers in that lab easy, at the moment all of my testing computers for each campus are in a single OU which makes reading the computer name important on figuring out which goes where.

I hope I have explained myself thoroughly enough, I tried to type this as everyone was telling me what they need for the day.

Currently my batch script is working for me with the exception of it is all computers and i have not put the gpupdate error check in yet.
0
 
Gabriel CliftonNet AdminAuthor Commented:
So far, I have come up with this to list the computers in an OU with multi select check boxes but I cannot get it to work with the rest of the script.

<head>
 
 <title>MULTI-CheckBox TEST</title>
 <HTA:APPLICATION
     ICON=""
     APPLICATIONNAME=""
     SCROLL="NO"
     SINGLEINSTANCE="yes"
     NAVIGABLE="yes"
     CAPTION="YES"
 >
 </HTA:APPLICATION>
 </head>
 <script language="VBScript">
 
SUB Check_M_All(checkNum)
    ON ERROR RESUME NEXT
        checkNum.Checked = TRUE
        IF ERR.Number <> 0 THEN
            FOR i = 0 TO checkNum.length - 1
                checkNum(i).checked = TRUE
            NEXT
        END IF
    ON ERROR GOTO 0
 END SUB
 
 SUB UNCheck_M_All(checkNum)
    ON ERROR RESUME NEXT
        checkNum.Checked = FALSE
        IF ERR.Number <> 0 THEN
            FOR i = 0 TO checkNum.Length - 1
                checkNum(i).Checked = FALSE
            NEXT
        END IF
    ON ERROR GOTO 0
 END SUB
 

 '<<<<<<<<<<<<<<<<<<<<<<<<<<->>>>>>>>>>>>>>>>>>>>>>>>>>>
 '            Open Operations
 '<<<<<<<<<<<<<<<<<<<<<<<<<<->>>>>>>>>>>>>>>>>>>>>>>>>>>
 SUB bodyLoaded()
    x1 = (window.screen.width - 700) / 2
    y1 = (window.screen.height - 1050) / 2
    If x1 < 0 Then x2 = 0
    If y1 < 0 Then y2 = 0
    window.ResizeTo 700,1050 'WIDTH, HEIGHT'
    window.moveTo x2,y2

strCOU="OU=Lab 1,OU=Campus 1,DC=domain,DC=local"

Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCOmmand.ActiveConnection = objConnection
objCommand.CommandText = _
"Select Name, Location from 'LDAP://" & strCOU & "' " _
& "Where objectCategory='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Sort on") = "Name"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
        msg = msg & vbcr & "<input type=""checkbox"" id=""" & objRecordSet.Fields("Name").Value & """ name=""checkNum"" value=""" & valName & objRecordSet.Fields("Name").Value & """>" & valName & objRecordSet.Fields("Name").Value & "<br>"
objRecordSet.MoveNext
Loop

    instPath.InnerHTML = msg

 END SUB
 
 </script>
 <body onLoad="bodyLoaded()" STYLE="font:13 pt arial; color:black" bgcolor="buttonface">
 <table border="0" width="100%">
    <tr width="100%">
        <TH width="100%" height="3" align="center"><B>Computers to rename</B></TH>
        <input type="button" name="chckAll" value="Check All" onclick="Check_M_All(document.myform.checkNum)">
        <input type="button" name="uchckAll" value="Un-Check All" onclick="UNCheck_M_All(document.myform.checkNum)">
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left">
        <form name="myform" method="post">
            <span  id="instPath"></span>
        </form>
    </TH>
    </tr>
 </table>
 </body>

Open in new window

0
 
Gabriel CliftonNet AdminAuthor Commented:
I am still needing this, is there any further help on this?
0
 
Gabriel CliftonNet AdminAuthor Commented:
The reasoning for HTA, first, appearance, though not critically important as functionality. Second, That is the only way I can think of, other that C, that would allow me to select a computer lab, display all computers in lab and then select individual computers to rename as a group. For state testing, these computers get renamed and moved to a separate OU for out testing Group Policies. Sometimes there is only one computer in a lab that needs to be renamed (which if only one is needed we will have two as backup), and sometimes all of them. The batch script I currently use will rename all of the computers in the lab which if fine, but renaming forty-five computers when only ten are needed. I can't just take the first X number of computers in a lab and rename it because if the lab is not full, they like to space out the students as much as possible so it is possible to have three or more unused computers in between the testing computers. Finally, this should be as easy as possible for my technicians to use, they are primarily just hardware people, but they are the ones at each school and will know which computers are going to be used. It would be nice, though not necessary, if it could ask for the room, lab, how many computers are going to be used and the script automatically calculates the spacing in between with two spares. IE, twenty-five computers in lab, three students testing, two spares, every fifth computer are automatically checked but still allowing those and others to be checked / unchecked.

I am open to any and all suggestions.
0
 
RobSampsonCommented:
Hi, I have taken your latest two scripts and combined them into a working example.  I have simplified it a bit, so you should be able to see how it is working by examining the code.

Let's start there....this looks like it could take a while to get right.

Regards,

Rob.

<html> 
<head> 
<title>Rename Computer Labs for state testing</title> 
<HTA:Application 
ID = "HTA" 
ApplicationName = "RenLab" 
Border = "dialog" 
BorderStyle = "normal" 
Caption = "yes" 
ContextMenu="yes" 
ICON="\\server\share\panther.ICO"
InnerBorder="no" 
MaximizeButton = "no" 
MinimizeButton = "no" 
Navigable="yes" 
Scroll="yes" 
SrollFlat="no" 
Selection="yes" 
ShowInTaskBar = "yes" 
SingleInstance = "yes" 
SysMenu = "yes" 
Version = "1.0" 
> 
<style>
.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; 
} 
.tabsNotSelected { 
background-color: wheat; 
border: solid 1px black; 
} 
.tabsSelected { 
background-color: white; 
border-color: black black white black; 
border-style: solid solid solid solid; 
border-width: 1px 1px 1px 1px; 
} 
</style>
<script language="VBscript"> 

Dim sItem 
Dim aPanels 
Dim el 
Dim iPanelCount 
iPanelCount = 2

Sub Window_OnLoad
	AddRenameToOption selRenameTo, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameTo, "Campus 1 C01 K-1 Lab", "OU=Campus 1,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 1 D01 2-3 Lab", "OU=Campus 2,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 2 Room 006 Lab", "OU=Campus 3,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 2 Room 017 Lab", "OU=Campus 4,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 2 Room 326 Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 3 Room 001 Lab", "OU=Campus 6,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 3 Room 027 Lab", "OU=Campus 7,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 4 Room 110 Lab", "OU=Campus 8,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 4 Room 111 Lab", "OU=Campus 9,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 Room 11 Lab", "OU=Campus 10,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 Room 12 Lab", "OU=Campus 11,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 Room 13 Lab", "OU=Campus 12,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 Room 48 Lab", "OU=Campus 13,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 GCS Lab", "OU=Campus 14,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 6 East Lab", "OU=Campus 15,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 6 West Lab", "OU=Campus 16,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameFrom, "Campus 1 C01 K-1 Lab", "OU=Campus 1,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 1 D01 2-3 Lab", "OU=Campus 2,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 2 Room 006 Lab", "OU=Campus 3,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 2 Room 017 Lab", "OU=Campus 4,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 2 Room 326 Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 3 Room 001 Lab", "OU=Campus 6,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 3 Room 027 Lab", "OU=Campus 7,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 4 Room 110 Lab", "OU=Campus 8,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 4 Room 111 Lab", "OU=Campus 9,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 Room 11 Lab", "OU=Campus 10,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 Room 12 Lab", "OU=Campus 11,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 Room 13 Lab", "OU=Campus 12,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 Room 48 Lab", "OU=Campus 13,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 GCS Lab", "OU=Campus 14,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 6 East Lab", "OU=Campus 15,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 6 West Lab", "OU=Campus 16,OU=TESTNAV,DC=domain,DC=local"
End Sub

Private Sub Panel(tab) 
	For i = 1 To iPanelCount 
		If i = tab Then 
			document.getElementById("tab" & i).className = "tabs tabsSelected" 
			document.getElementById("panel" & i).style.display = "block" 
		Else 
			document.getElementById("tab" & i).className = "tabs tabsNotSelected" 
			document.getElementById("panel" & i).style.display = "none" 
		End If 
	Next 
End Sub 

Sub AddRenameToOption(objObject, strText, strValue)
	Set objOption = Document.CreateElement("OPTION")
	objOption.Text = strText
	objOption.Value = strValue
	objObject.Add(objOption)
End Sub

Sub AddCheck
	strHTML = panelContents2.InnerHTML 
	strHTML = strHTML & "<input id=" & intCheckCount & " type=" & Chr(34) & "CheckBox" & Chr(34) & _ 
		" name=" & Chr(34) & "chkEnabled" & Chr(34) & "value= " & Chr(34) & "CheckBox" & intCheckCount & Chr(34) & " onClick=" & Chr(34) & _ 
		"NewCheckSubroutine" & Chr(34) & ">" & " <BR>" 
	panelContents2.InnerHTML = strHTML 
End Sub 

'Tab 1
Sub TestSub
	strText = selRenameTo.Item(selRenameTo.SelectedIndex).Text
	strValue = selRenameTo.Item(selRenameTo.SelectedIndex).Value
	MsgBox strText & vbCrLf & strValue
	Set objOU = GetObject("LDAP://" & strValue)
	strNames = ""
	For Each objObject In objOU
		If objObject.class = "computer" Then
			If strNames = "" Then
				strNames = "<input type=""checkbox"" id=""" & objObject.Name & """ name=""checkNum"" value=""" & objObject.Name & """>" & objObject.Name & "<br>"
			Else
				strNames = strNames & vbCrLf & "<input type=""checkbox"" id=""" & objObject.Name & """ name=""checkNum"" value=""" & objObject.Name & """>" & objObject.Name & "<br>"
			End If
		End If
	Next
    instPath.InnerHTML = strNames
End Sub

'Tab 2
Sub TestSub2
	strText = selRenameTo.Item(selRenameFrom.SelectedIndex).Text
	strValue = selRenameTo.Item(selRenameFrom.SelectedIndex).Value
	MsgBox strText & vbCrLf & strValue
End Sub

SUB Check_M_All(checkNum)
    ON ERROR RESUME NEXT
        checkNum.Checked = TRUE
        IF ERR.Number <> 0 THEN
            FOR i = 0 TO checkNum.length - 1
                checkNum(i).checked = TRUE
            NEXT
        END IF
    ON ERROR GOTO 0
 End SUB
 
 Sub UNCheck_M_All(checkNum)
    ON ERROR RESUME NEXT
        checkNum.Checked = FALSE
        IF ERR.Number <> 0 THEN
            FOR i = 0 TO checkNum.Length - 1
                checkNum(i).Checked = FALSE
            NEXT
        End IF
    ON Error GOTO 0
 END Sub
</script> 

</head> 


<body bgcolor="blue"> 
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650"> 
<tr valign="top"> 
<td colspan="2"> 
<span class="tabs tabsSelected" id="tab1" onclick="panel(1)">Rename Computers for Testing</span> 
<span class="tabs tabsNotSelected" id="tab2" onclick="panel(2)">Rename Computers back from Testing</span>
<!-- Tab 1 -->
<div class="panel" id="panel1" style="display:block"> 
<table border="0" width="100%"  cellspacing="0" cellpadding="0">
    <tr>
        <td width="33%" valign="top"><img src="\\server\share\Logo_Large.png" alt="Panther" width="110" height="110"></td>
        <td width="34%" valign="top">
        <font size="6" 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\Logo_Large.png" alt="Panther" width="110" height="110"></td>
  </tr>
</table>

	<table style="width:100%;">
		<tr>
			<td style="text-align:right;font-size:0.9em;font-weight:bold;font-style:oblique;color:#888888;">
				Created by Gabriel Clifton
			</td>
		</tr>
	</table>
<!--Add your controls here-->
<select size="1" onChange="TestSub" name="selRenameTo" id="selRenameTo"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="2" width="100%" height="3" align="center"><B>Computers to rename</B></TH>
    </tr>
    <tr>
        <td>
        	<input type="button" name="chckAll" value="Check All" onclick="Check_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="uchckAll" value="Un-Check All" onclick="UNCheck_M_All(document.myform.checkNum)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left">
        <form name="myform" method="post">
            <span  id="instPath"></span>
        </form>
    </TH>
    </tr>
 </table>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

<!-- Tab 2 -->
<div class="panel" id="panel2" style="display:none"> 
<table border="0" width="100%"  cellspacing="0" cellpadding="0">
    <tr>
        <td width="33%" valign="top"><img src="\\server\share\Logo_Large.png" alt="Panther" width="110" height="110"></td>
        <td width="34%" valign="top">
        <font size="6" 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\Logo_Large.png" alt="Panther" width="110" height="110"></td>
  </tr>
</table>

	<table style="width:100%;">
		<tr>
			<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>

<!--Add your controls here-->
<select size="1" onChange="TestSub2" name="selRenameFrom" id="selRenameFrom"> 
</select>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

</div> 
</td> 
</tr> 
</table> 
</body> 
</html> 

Open in new window

0
 
Gabriel CliftonNet AdminAuthor Commented:
I do like where this is heading. Trying to get second tab to work right now. Is there a way to automatically wrap the long list of computers into colomns?
0
 
Gabriel CliftonNet AdminAuthor Commented:
The first and second tab are reading correctly, but now the check all / uncheck all do not work.
Tab 1
Sub TestSub
	strText = selRenameTo.Item(selRenameTo.SelectedIndex).Text
	strValue = selRenameTo.Item(selRenameTo.SelectedIndex).Value
	MsgBox strText & vbCrLf & strValue
	Set objOU = GetObject("LDAP://" & strValue)
	strNames = ""
	For Each objObject In objOU
		If objObject.class = "computer" Then
			If strNames = "" Then
				strNames = "<input type=""checkbox"" id=""" & objObject.Name & """ name=""checkNum"" value=""" & objObject.Name & """>" & objObject.Name & "<br>"
			Else
				strNames = strNames & vbCrLf & "<input type=""checkbox"" id=""" & objObject.Name & """ name=""checkNum"" value=""" & objObject.Name & """>" & objObject.Name & "<br>"
			End If
		End If
	Next
    instPath.InnerHTML = strNames
End Sub

Open in new window


<select size="1" onChange="TestSub" name="selRenameTo" id="selRenameTo"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="2" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll" value="Check All" onclick="Check_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="uchckAll" value="Un-Check All" onclick="UNCheck_M_All(document.myform.checkNum)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform" method="post">
            <span  id="instPath"></span>
        </font></form>
    </TH>
    </tr>
 </table>

Open in new window

Tab 2
Sub TestSub2
	strText2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Text
	strValue2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Value
	MsgBox strText2 & vbCrLf & strValue2
	Set objOU2 = GetObject("LDAP://" & strValue2)
	strNames2 = ""
	For Each objObject In objOU2
		If objObject.class = "computer" Then
			If strNames2 = "" Then
				strNames2 = "<input type=""checkbox"" id=""" & objObject.Name & """ name=""checkNum2"" value=""" & objObject.Name & """>" & objObject.Name & "<br>"
			Else
				strNames2 = strNames2 & vbCrLf & "<input type=""checkbox"" id=""" & objObject.Name & """ name=""checkNum2"" value=""" & objObject.Name & """>" & objObject.Name & "<br>"
			End If
		End If
	Next
    instPath2.InnerHTML = strNames2
End Sub

Open in new window


<select size="1" onChange="TestSub2" name="selRenameFrom" id="selRenameFrom"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="2" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename back</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll2" value="Check All" onclick="Check_M_All2(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="uchckAll2" value="Un-Check All" onclick="UNCheck_M_All2(document.myform2.checkNum2)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform2" method="post">
            <span  id="instPath2"></span>
        </font></form>
    </TH>
    </tr>
 </table>

Open in new window


I am pretty sure I did something stupid.
0
 
Gabriel CliftonNet AdminAuthor Commented:
OK, I got the check all to work by adding
SUB Check_M_All(checkNum) 
   ON ERROR RESUME NEXT 
       checkNum.Checked = TRUE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.length - 1 
               checkNum(i).checked = TRUE 
           NEXT 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
 SUB UNCheck_M_All(checkNum) 
   ON ERROR RESUME NEXT 
       checkNum.Checked = FALSE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.Length - 1 
               checkNum(i).Checked = FALSE 
           NEXT 
       END IF 
   ON ERROR GOTO 0 
 END SUB 

Open in new window

0
 
Gabriel CliftonNet AdminAuthor Commented:
I have this in another HTA for a different purpose that I will attempt to integrate.
'########################### 
' Connect to Computer 
'###########################
Dim objWMILocator, objWMIComputer, objWMIComputerSystem, rc, objWMIService, colOperatingSystems, objOperatingSystem, objNetwork, objComputer
Set objNetwork = CreateObject("WScript.Network")
'Set objWMIComputer = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd) 
'Set objWMIComputerSystem = objWMIComputer.Get( "Win32_ComputerSystem.Name='" & strComputer & "'") 
If LCase(strComputer) = LCase(objNetwork.ComputerName) Then
	Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, authenticationLevel=pktPrivacy, (Shutdown)}!\\" & strComputer & "\root\cimv2") 

' Call always gets only one Win32_ComputerSystem object. 
For Each objComputer in objWMIService.InstancesOf("Win32_ComputerSystem")
ReturnCode = objComputer.Rename(strComputer) 
Next
Else
	Set objWMILocator = CreateObject("WbemScripting.SWbemLocator") 
	objWMILocator.Security_.AuthenticationLevel = 6 
	Set objWMIService = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd)
End If
'########################### 
' Rename Computer 
'########################### 
Set objWMIComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem Where Name='" & strComputer & "'")
For Each objWMIComputerSystem In objWMIComputer
	' There will only ever be one element in this collection
	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

Open in new window


If successful, the only thing left would be to wait for computers to reboot, gpupdate them and reboot again. If not, well...
0
 
RobSampsonCommented:
To make the computers list in four columns, add this at the top above Window_OnLoad
Dim intColCount
intColCount = 4

Open in new window


and then change your TestSub to this
Sub TestSub
	strText = selRenameTo.Item(selRenameTo.SelectedIndex).Text
	strValue = selRenameTo.Item(selRenameTo.SelectedIndex).Value
	'MsgBox strText & vbCrLf & strValue
	Set objOU = GetObject("LDAP://" & strValue)
	strNames = ""
	intCol = 0
	strNames = "<table cellspacing=0 cellpadding=0 border=0>"
	For Each objObject In objOU
		If objObject.class = "computer" Then
			strCheckBoxCode = ""
			If intCol = 0 Then
				strCheckBoxCode = "<tr>"
			End If
			strCheckBoxCode = strCheckBoxCode & "<td><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum"" value=""" & Mid(objObject.Name, 4) & """>" & Mid(objObject.Name, 4) & "</td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode = strCheckBoxCode & "</tr>"
				intCol = 0
			End If
			If strNames = "" Then
				strNames = strCheckBoxCode
			Else
				strNames = strNames & vbCrLf & strCheckBoxCode
			End If
		End If
	Next
	strNames = strNames & vbCrLf & "</table>"
    instPath.InnerHTML = strNames
End Sub

Open in new window


You will need to copy that structure to TestSub2 as well.

In order to continue making changes with the correct version of the code, it would be best if you post your full code as we go, and we can work on that with any new changes.

Regards,

Rob.
0
 
RobSampsonCommented:
The checkbox code will need to be changed to be able to identify the selected computer objects, but I'll make that fix once I see your full code again, and we'll add a "Rename Selected" button.

Rob.
0
 
Gabriel CliftonNet AdminAuthor Commented:
Here you go
<html> 
<head> 
<title>Rename Computer Labs for state testing</title> 

<HTA:Application 
ID = "HTA" 
ApplicationName = "RenLab" 
Border = "dialog" 
BorderStyle = "normal" 
Caption = "yes" 
ContextMenu="yes" 
ICON="\\Server\Share\panther.ICO"
InnerBorder="no" 
MaximizeButton = "no" 
MinimizeButton = "no" 
Navigable="yes" 
Scroll="yes" 
SrollFlat="no" 
Selection="yes" 
ShowInTaskBar = "yes" 
SingleInstance = "yes" 
SysMenu = "yes" 
Version = "1.0" 
> 
<style>
.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; 
} 
.tabsNotSelected { 
background-color: wheat; 
border: solid 1px black; 
} 
.tabsSelected { 
background-color: white; 
border-color: black black white black; 
border-style: solid solid solid solid; 
border-width: 1px 1px 1px 1px; 
} 
</style>
<script language="VBscript"> 
Dim sItem 
Dim aPanels 
Dim el 
Dim iPanelCount 
iPanelCount = 2
Dim intColCount
intColCount = 4

Sub Window_OnLoad

	ElevatedCheck
	width = "750"
	height = "750"
	' 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 
	
	'Original OU
	AddRenameToOption selRenameTo, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameTo, "Campus 1 C01 K-1 Lab", "OU=Campus 1,OU=Lab OU 1,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 1 D01 2-3 Lab", "OU=Campus 1,OU=Lab OU 2,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Campus 2 Room 006 Lab", "OU=Campus 2,OU=Lab OU 1,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 2 Room 017 Lab", "OU=Campus 2,OU=Lab OU 2,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 2 Room 326 Lab", "OU=Campus 2,OU=Lab OU 3,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Campus 3 Room 001 Lab", "OU=Campus 3,OU=Lab OU 1,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 3 Room 027 Lab", "OU=Campus 3,OU=Lab OU 2,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 3 Room 028 Lab", "OU=Campus 3,OU=Lab OU 2,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 3 Mobile Lab", "OU=Campus 3,OU=Lab OU 2,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Campus 4 Room 110 Lab", "OU=Campus 4,OU=Lab OU 1,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 4 Room 111 Lab", "OU=Campus 4,OU=Lab OU 2,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Campus 5 Room 11 Lab", "OU=Campus 5,OU=Lab OU 3,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 Room 12 Lab", "OU=Campus 5,OU=Lab OU 4,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 Room 13 Lab", "OU=Campus 5,OU=Lab OU 5,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 Room 48 Lab", "OU=Campus 5,OU=Lab OU 6,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 GCS Lab", "OU=Campus 5,OU=Lab OU 7,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Campus 6 East Lab", "OU=Campus 6,OU=Lab OU 1,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 6 West Lab", "OU=Campus 6,OU=Lab OU 2,DC=domain,DC=local"
	
	'Testing OU
	AddRenameToOption selRenameFrom, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameFrom, "Campus 1 C01 K-1 Lab", "OU=Campus 1,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 1 D01 2-3 Lab", "OU=Campus 1,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Campus 2 Room 006 Lab", "OU=Campus 2,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 2 Room 017 Lab", "OU=Campus 2,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 2 Room 326 Lab", "OU=Campus 2,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Campus 3 Room 001 Lab", "OU=Campus 3,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 3 Room 027 Lab", "OU=Campus 3,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 3 Room 028 Lab", "OU=Campus 3,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 3 Mobile Lab", "OU=Campus 3,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Campus 4 Room 110 Lab", "OU=Campus 4,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 4 Room 111 Lab", "OU=Campus 4,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Campus 5 Room 11 Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 Room 12 Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 Room 13 Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 Room 48 Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 GCS Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Campus 6 East Lab", "OU=Campus 6,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 6 West Lab", "OU=Campus 6,OU=TESTNAV,DC=domain,DC=local"
End Sub

Sub ElevatedCheck
	'Source: http://www.thegbach.com/elevatedHta.html
	Set objShell = CreateObject("WScript.Shell")
	Set objShellApp = CreateObject("Shell.Application")
	strElevated = False
	strHTADir = document.location.pathname
	Set objWhoami = objShell.Exec("whoami /groups")
	strWhoami = objWhoami.StdOut.ReadAll
	If InStr(1, strWhoami,"S-1-16-12288",vbTextCompare) Then
	strElevated = True
	Else
		objShellApp.ShellExecute"mshta.exe",Chr(34) & strHTADir & Chr(34) & " runasadministrator","","runas",1
		window.close()
	End If 
End Sub

SUB Check_M_All(checkNum) 
   ON ERROR RESUME NEXT 
       checkNum.Checked = TRUE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.length - 1 
               checkNum(i).checked = TRUE 
           NEXT 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
 SUB UNCheck_M_All(checkNum) 
   ON ERROR RESUME NEXT 
       checkNum.Checked = FALSE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.Length - 1 
               checkNum(i).Checked = FALSE 
           NEXT 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
Private Sub Panel(tab) 
	For i = 1 To iPanelCount 
		If i = tab Then 
			document.getElementById("tab" & i).className = "tabs tabsSelected" 
			document.getElementById("panel" & i).style.display = "block" 
		Else 
			document.getElementById("tab" & i).className = "tabs tabsNotSelected" 
			document.getElementById("panel" & i).style.display = "none" 
		End If 
	Next 
End Sub 

Sub AddRenameToOption(objObject, strText, strValue)
	Set objOption = Document.CreateElement("OPTION")
	objOption.Text = strText
	objOption.Value = strValue
	objObject.Add(objOption)
End Sub

Sub AddCheck
	strHTML = panelContents2.InnerHTML 
	strHTML = strHTML & "<input id=" & intCheckCount & " type=" & Chr(34) & "CheckBox" & Chr(34) & _ 
		" name=" & Chr(34) & "chkEnabled" & Chr(34) & "value= " & Chr(34) & "CheckBox" & intCheckCount & Chr(34) & " onClick=" & Chr(34) & _ 
		"NewCheckSubroutine" & Chr(34) & ">" & " <BR>" 
	panelContents2.InnerHTML = strHTML 
End Sub 

'Tab 1
Sub TestSub
	strText = selRenameTo.Item(selRenameTo.SelectedIndex).Text
	strValue = selRenameTo.Item(selRenameTo.SelectedIndex).Value
	'MsgBox strText & vbCrLf & strValue
	Set objOU = GetObject("LDAP://" & strValue)
	strNames = ""
	intCol = 0
	strNames = "<table cellspacing=0 cellpadding=0 border=0>"
	For Each objObject In objOU
		If objObject.class = "computer" Then
			strCheckBoxCode = ""
			If intCol = 0 Then
				strCheckBoxCode = "<tr>"
			End If
			strCheckBoxCode = strCheckBoxCode & "<td><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum"" value=""" & Mid(objObject.Name, 4) & """>" & Mid(objObject.Name, 4) & "</td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode = strCheckBoxCode & "</tr>"
				intCol = 0
			End If
			If strNames = "" Then
				strNames = strCheckBoxCode
			Else
				strNames = strNames & vbCrLf & strCheckBoxCode
			End If
		End If
	Next
	strNames = strNames & vbCrLf & "</table>"
    instPath.InnerHTML = strNames
End Sub

'Tab 2
Sub TestSub2
	strText2 = selRenameTo.Item(selRenameFrom.SelectedIndex).Text
	strValue2 = selRenameTo.Item(selRenameFrom.SelectedIndex).Value
	'MsgBox strText2 & vbCrLf & strValue2
	Set objOU2 = GetObject("LDAP://" & strValue)
	strNames2 = ""
	intCol = 0
	strNames2 = "<table cellspacing=0 cellpadding=0 border=0>"
	For Each objObject In objOU2
		If objObject.class = "computer" Then
			strCheckBoxCode2 = ""
			If intCol = 0 Then
				strCheckBoxCode2 = "<tr>"
			End If
			strCheckBoxCode2 = strCheckBoxCode2 & "<td><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum2"" value=""" & Mid(objObject.Name, 4) & """>" & Mid(objObject.Name, 4) & "</td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode2 = strCheckBoxCode2 & "</tr>"
				intCol = 0
			End If
			If strNames2 = "" Then
				strNames2 = strCheckBoxCode2
			Else
				strNames2 = strNames2 & vbCrLf & strCheckBoxCode2
			End If
		End If
	Next
	strNames2 = strNames2 & vbCrLf & "</table>"
    instPath2.InnerHTML = strNames2
End Sub

'Sub TestSub2
'	strText2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Text
'	strValue2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Value
'	MsgBox strText2 & vbCrLf & strValue2
'	Set objOU2 = GetObject("LDAP://" & strValue2)
'	strNames2 = ""
'	For Each objObject In objOU2
'		If objObject.class = "computer" Then
'			If strNames2 = "" Then
'				strNames2 = "<input type=""checkbox"" id=""" & objObject.Name & """ name=""checkNum2"" value=""" & objObject.Name & """>" & objObject.Name & "<br>"
'			Else
'				strNames2 = strNames2 & vbCrLf & "<input type=""checkbox"" id=""" & objObject.Name & """ name=""checkNum2"" value=""" & objObject.Name & """>" & objObject.Name & "<br>"
'			End If
'		End If
'	Next
'    instPath2.InnerHTML = strNames2
'End Sub

</script> 

</head> 


<body bgcolor="blue"> 
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650"> 
<tr valign="top"> 
<td colspan="2"> 
<span class="tabs tabsSelected" id="tab1" onclick="panel(1)">Rename Computers for Testing</span> 
<span class="tabs tabsNotSelected" id="tab2" onclick="panel(2)">Rename Computers back from Testing</span>
<!-- Tab 1 -->
<div class="panel" id="panel1" style="display:block"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<td style="text-align:right;font-size:0.9em;font-weight:bold;font-style:oblique;color:#888888;">
				Created by Gabriel Clifton
			</td>
		</tr>
	</table>
<!--Add your controls here-->
<select size="1" onChange="TestSub" name="selRenameTo" id="selRenameTo"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="2" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll" value="Check All" onclick="Check_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="uchckAll" value="Un-Check All" onclick="UNCheck_M_All(document.myform.checkNum)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform" method="post">
            <span  id="instPath"></span>
        </font></form>
    </TH>
    </tr>
 </table>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

<!-- Tab 2 -->
<div class="panel" id="panel2" style="display:none"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<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>

<!--Add your controls here-->
<select size="1" onChange="TestSub2" name="selRenameFrom" id="selRenameFrom"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="2" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename back</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll2" value="Check All" onclick="Check_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="uchckAll2" value="Un-Check All" onclick="UNCheck_M_All(document.myform2.checkNum2)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform2" method="post">
            <span  id="instPath2"></span>
        </font></form>
    </TH>
    </tr>
 </table>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

</body> 
</html> 

Open in new window

0
 
Gabriel CliftonNet AdminAuthor Commented:
Back to tab 2 not working, looking at it.
0
 
Gabriel CliftonNet AdminAuthor Commented:
Here is the fixed tab 2.

'Tab 2
Sub TestSub2
	strText2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Text
	strValue2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Value
	'MsgBox strText2 & vbCrLf & strValue2
	Set objOU2 = GetObject("LDAP://" & strValue2)
	strNames2 = ""
	intCol = 0
	strNames2 = "<table cellspacing=0 cellpadding=0 border=0>"
	For Each objObject In objOU2
		If objObject.class = "computer" Then
			strCheckBoxCode2 = ""
			If intCol = 0 Then
				strCheckBoxCode2 = "<tr>"
			End If
			strCheckBoxCode2 = strCheckBoxCode2 & "<td><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum2"" value=""" & Mid(objObject.Name, 4) & """>" & Mid(objObject.Name, 4) & "</td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode2 = strCheckBoxCode2 & "</tr>"
				intCol = 0
			End If
			If strNames2 = "" Then
				strNames2 = strCheckBoxCode2
			Else
				strNames2 = strNames2 & vbCrLf & strCheckBoxCode2
			End If
		End If
	Next
	strNames2 = strNames2 & vbCrLf & "</table>"
    instPath2.InnerHTML = strNames2
End Sub

Open in new window

I hope I doing this right, I have been known for changing something that seems wrong, but isn't.
0
 
RobSampsonCommented:
Hi, that is working fine. I have added the "Rename To" and "Rename From" buttons, which don't do anything except return the DN of each computer you have checked (which might be needed if you need to know where they are).

Regards,

Rob.

<html> 
<head> 
<title>Rename Computer Labs for state testing</title> 

<HTA:Application 
ID = "HTA" 
ApplicationName = "RenLab" 
Border = "dialog" 
BorderStyle = "normal" 
Caption = "yes" 
ContextMenu="yes" 
ICON="\\Server\Share\panther.ICO"
InnerBorder="no" 
MaximizeButton = "no" 
MinimizeButton = "no" 
Navigable="yes" 
Scroll="yes" 
SrollFlat="no" 
Selection="yes" 
ShowInTaskBar = "yes" 
SingleInstance = "yes" 
SysMenu = "yes" 
Version = "1.0" 
> 
<style>
.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; 
} 
.tabsNotSelected { 
background-color: wheat; 
border: solid 1px black; 
} 
.tabsSelected { 
background-color: white; 
border-color: black black white black; 
border-style: solid solid solid solid; 
border-width: 1px 1px 1px 1px; 
} 
</style>
<script language="VBscript"> 
Dim sItem 
Dim aPanels 
Dim el 
Dim iPanelCount 
iPanelCount = 2
Dim intColCount
intColCount = 4

Sub Window_OnLoad

	ElevatedCheck
	width = "750"
	height = "750"
	' 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 
	
	'Original OU
	AddRenameToOption selRenameTo, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameTo, "Campus 1 C01 K-1 Lab", "OU=Campus 1,OU=Lab OU 1,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 1 D01 2-3 Lab", "OU=Campus 1,OU=Lab OU 2,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Campus 2 Room 006 Lab", "OU=Campus 2,OU=Lab OU 1,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 2 Room 017 Lab", "OU=Campus 2,OU=Lab OU 2,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 2 Room 326 Lab", "OU=Campus 2,OU=Lab OU 3,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Campus 3 Room 001 Lab", "OU=Campus 3,OU=Lab OU 1,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 3 Room 027 Lab", "OU=Campus 3,OU=Lab OU 2,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 3 Room 028 Lab", "OU=Campus 3,OU=Lab OU 2,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 3 Mobile Lab", "OU=Campus 3,OU=Lab OU 2,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Campus 4 Room 110 Lab", "OU=Campus 4,OU=Lab OU 1,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 4 Room 111 Lab", "OU=Campus 4,OU=Lab OU 2,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Campus 5 Room 11 Lab", "OU=Campus 5,OU=Lab OU 3,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 Room 12 Lab", "OU=Campus 5,OU=Lab OU 4,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 Room 13 Lab", "OU=Campus 5,OU=Lab OU 5,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 Room 48 Lab", "OU=Campus 5,OU=Lab OU 6,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 GCS Lab", "OU=Campus 5,OU=Lab OU 7,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Campus 6 East Lab", "OU=Campus 6,OU=Lab OU 1,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 6 West Lab", "OU=Campus 6,OU=Lab OU 2,DC=domain,DC=local"
	
	'Testing OU
	AddRenameToOption selRenameFrom, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameFrom, "Campus 1 C01 K-1 Lab", "OU=Campus 1,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 1 D01 2-3 Lab", "OU=Campus 1,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Campus 2 Room 006 Lab", "OU=Campus 2,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 2 Room 017 Lab", "OU=Campus 2,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 2 Room 326 Lab", "OU=Campus 2,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Campus 3 Room 001 Lab", "OU=Campus 3,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 3 Room 027 Lab", "OU=Campus 3,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 3 Room 028 Lab", "OU=Campus 3,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 3 Mobile Lab", "OU=Campus 3,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Campus 4 Room 110 Lab", "OU=Campus 4,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 4 Room 111 Lab", "OU=Campus 4,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Campus 5 Room 11 Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 Room 12 Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 Room 13 Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 Room 48 Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 GCS Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Campus 6 East Lab", "OU=Campus 6,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 6 West Lab", "OU=Campus 6,OU=TESTNAV,DC=domain,DC=local"
End Sub

Sub ElevatedCheck
	'Source: http://www.thegbach.com/elevatedHta.html
	Set objShell = CreateObject("WScript.Shell")
	Set objShellApp = CreateObject("Shell.Application")
	strElevated = False
	strHTADir = document.location.pathname
	Set objWhoami = objShell.Exec("whoami /groups")
	strWhoami = objWhoami.StdOut.ReadAll
	If InStr(1, strWhoami,"S-1-16-12288",vbTextCompare) Then
	strElevated = True
	Else
		objShellApp.ShellExecute"mshta.exe",Chr(34) & strHTADir & Chr(34) & " runasadministrator","","runas",1
		window.close()
	End If 
End Sub

SUB Check_M_All(checkNum) 
   'ON ERROR RESUME NEXT 
   '    checkNum.Checked = TRUE 
   '    IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.length - 1 
               checkNum(i).checked = TRUE 
           Next 
   '    END IF 
   'ON ERROR GOTO 0 
 END SUB 
 
 SUB Uncheck_M_All(checkNum)
   'ON ERROR RESUME NEXT 
   '    checkNum.Checked = FALSE 
   '    IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.Length - 1 
               checkNum(i).Checked = FALSE 
           NEXT 
   '    END IF 
   'ON ERROR GOTO 0 
 END SUB 
 
Private Sub Panel(tab) 
	For i = 1 To iPanelCount 
		If i = tab Then 
			document.getElementById("tab" & i).className = "tabs tabsSelected" 
			document.getElementById("panel" & i).style.display = "block" 
		Else 
			document.getElementById("tab" & i).className = "tabs tabsNotSelected" 
			document.getElementById("panel" & i).style.display = "none" 
		End If 
	Next 
End Sub 

Sub AddRenameToOption(objObject, strText, strValue)
	Set objOption = Document.CreateElement("OPTION")
	objOption.Text = strText
	objOption.Value = strValue
	objObject.Add(objOption)
End Sub

'Sub AddCheck
'	strHTML = panelContents2.InnerHTML 
'	strHTML = strHTML & "<input id=" & intCheckCount & " type=" & Chr(34) & "CheckBox" & Chr(34) & _ 
'		" name=" & Chr(34) & "chkEnabled" & Chr(34) & "value= " & Chr(34) & "CheckBox" & intCheckCount & Chr(34) & " onClick=" & Chr(34) & _ 
'		"NewCheckSubroutine" & Chr(34) & ">" & " <BR>" 
'	panelContents2.InnerHTML = strHTML 
'End Sub 

'Tab 1
Sub TestSub
	strText = selRenameTo.Item(selRenameTo.SelectedIndex).Text
	strValue = selRenameTo.Item(selRenameTo.SelectedIndex).Value
	'MsgBox strText & vbCrLf & strValue
	Set objOU = GetObject("LDAP://" & strValue)
	strNames = ""
	intCol = 0
	strNames = "<table cellspacing=0 cellpadding=0 border=0>"
	For Each objObject In objOU
		If objObject.class = "computer" Then
			strCheckBoxCode = ""
			If intCol = 0 Then
				strCheckBoxCode = "<tr>"
			End If
			strCheckBoxCode = strCheckBoxCode & "<td><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum"" value=""" & objObject.distinguishedName & """>" & Mid(objObject.Name, 4) & "</td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode = strCheckBoxCode & "</tr>"
				intCol = 0
			End If
			If strNames = "" Then
				strNames = strCheckBoxCode
			Else
				strNames = strNames & vbCrLf & strCheckBoxCode
			End If
		End If
	Next
	strNames = strNames & vbCrLf & "</table>"
    instPath.InnerHTML = strNames
End Sub

'Tab 2
Sub TestSub2
	strText2 = selRenameTo.Item(selRenameFrom.SelectedIndex).Text
	strValue2 = selRenameTo.Item(selRenameFrom.SelectedIndex).Value
	'MsgBox strText2 & vbCrLf & strValue2
	Set objOU2 = GetObject("LDAP://" & strValue2)
	strNames2 = ""
	intCol = 0
	strNames2 = "<table cellspacing=0 cellpadding=0 border=0>"
	For Each objObject In objOU2
		If objObject.class = "computer" Then
			strCheckBoxCode2 = ""
			If intCol = 0 Then
				strCheckBoxCode2 = "<tr>"
			End If
			strCheckBoxCode2 = strCheckBoxCode2 & "<td><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum2"" value=""" & objObject.distinguishedName & """>" & Mid(objObject.Name, 4) & "</td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode2 = strCheckBoxCode2 & "</tr>"
				intCol = 0
			End If
			If strNames2 = "" Then
				strNames2 = strCheckBoxCode2
			Else
				strNames2 = strNames2 & vbCrLf & strCheckBoxCode2
			End If
		End If
	Next
	strNames2 = strNames2 & vbCrLf & "</table>"
    instPath2.InnerHTML = strNames2
End Sub

Sub RenameTo(checknum)
	FOR i = 0 TO checkNum.length - 1 
		If checknum(i).checked = True Then
			MsgBox "Renaming " & checknum(i).id & " (" & checknum(i).value & ") to something"
		End If
	Next
End Sub

Sub RenameFrom
	FOR i = 0 TO checkNum.length - 1 
		If checknum(i).checked = True Then
			MsgBox "Renaming " & checknum(i).value & " back to something"
		End If
	Next
End Sub

'Sub TestSub2
'	strText2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Text
'	strValue2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Value
'	MsgBox strText2 & vbCrLf & strValue2
'	Set objOU2 = GetObject("LDAP://" & strValue2)
'	strNames2 = ""
'	For Each objObject In objOU2
'		If objObject.class = "computer" Then
'			If strNames2 = "" Then
'				strNames2 = "<input type=""checkbox"" id=""" & objObject.Name & """ name=""checkNum2"" value=""" & objObject.Name & """>" & objObject.Name & "<br>"
'			Else
'				strNames2 = strNames2 & vbCrLf & "<input type=""checkbox"" id=""" & objObject.Name & """ name=""checkNum2"" value=""" & objObject.Name & """>" & objObject.Name & "<br>"
'			End If
'		End If
'	Next
'    instPath2.InnerHTML = strNames2
'End Sub

</script> 

</head> 


<body bgcolor="blue"> 
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650"> 
<tr valign="top"> 
<td colspan="2"> 
<span class="tabs tabsSelected" id="tab1" onclick="panel(1)">Rename Computers for Testing</span> 
<span class="tabs tabsNotSelected" id="tab2" onclick="panel(2)">Rename Computers back from Testing</span>
<!-- Tab 1 -->
<div class="panel" id="panel1" style="display:block"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<td style="text-align:right;font-size:0.9em;font-weight:bold;font-style:oblique;color:#888888;">
				Created by Gabriel Clifton
			</td>
		</tr>
	</table>
<!--Add your controls here-->
<select size="1" onChange="TestSub" name="selRenameTo" id="selRenameTo"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll" value="Check All" onclick="Check_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="uchckAll" value="Un-Check All" onclick="UNCheck_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="RenameTo" value="Rename To" onclick="RenameTo(document.myform.checkNum)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform" method="post">
            <span  id="instPath"></span>
        </font></form>
    </TH>
    </tr>
 </table>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

<!-- Tab 2 -->
<div class="panel" id="panel2" style="display:none"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<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>

<!--Add your controls here-->
<select size="1" onChange="TestSub2" name="selRenameFrom" id="selRenameFrom"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename back</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll2" value="Check All" onclick="Check_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="uchckAll2" value="Un-Check All" onclick="Uncheck_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="RenameFrom" value="Rename From" onclick="RenameFrom(document.myform.checkNum2)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform2" method="post">
            <span  id="instPath2"></span>
        </font></form>
    </TH>
    </tr>
 </table>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

</body> 
</html> 

Open in new window

0
 
Gabriel CliftonNet AdminAuthor Commented:
Looks good so far, I did move the RenameTo and RenameFrom subs to under the Check_M_All instead of under the tab two area and changed the RenameFrom code a little to make it work for me.
Sub RenameFrom(checknum2)
           FOR i = 0 TO checkNum2.Length - 1 
		If checknum2(i).checked = True Then
			MsgBox "Renaming " & checknum2(i).id & " (" & checknum2(i).value & ") back to something"
		End If
	Next
End Sub

Open in new window


Will not need the MsgBox in the end, but will be good for testing the script.

Little left to do.
0
 
Gabriel CliftonNet AdminAuthor Commented:
I really hate putting a rush on this, but we are going to be staying the renaming tomorrow May 1st. if we can't get this by then, then we will still rename manually.
0
 
RobSampsonCommented:
OK, its Friday morning here for me (7:40am) so I'll have a quick look at incorporating your rename code that you have into it, but I won't be able to test it.  If it is functioning code though, it should work fine.
0
 
Gabriel CliftonNet AdminAuthor Commented:
OK, you are ~15 hours ahead of me. I don't want to pressure you or make you do this if you should be doing something else, if it does not work we can do this manually. We will start using this at 3:00PM here. Now for me is 04/30/2015 16:51 (4:51 PM).
0
 
RobSampsonCommented:
I'm going to make the computer names store on the "management" PC that you run this from, so you must run the rename back (when we get to it) from the same computer when that happens.  By looking at your rename code, I worry that you may not have permissions store that information on each PC.

Rob.
0
 
RobSampsonCommented:
You're also not moving them to an OU yet.....is that going to be a constant place?
0
 
RobSampsonCommented:
So without testing it, this *should* rename each PC, and reboot.  I probably won't get more time at work today, since I'm snowed under with workload, but if we get more time I would be able to place a "marker" on each PC to perform the gpupdate and reboot again.

<html> 
<head> 
<title>Rename Computer Labs for state testing</title> 

<HTA:Application 
ID = "HTA" 
ApplicationName = "RenLab" 
Border = "dialog" 
BorderStyle = "normal" 
Caption = "yes" 
ContextMenu="yes" 
ICON="\\Server\Share\panther.ICO"
InnerBorder="no" 
MaximizeButton = "no" 
MinimizeButton = "no" 
Navigable="yes" 
Scroll="yes" 
SrollFlat="no" 
Selection="yes" 
ShowInTaskBar = "yes" 
SingleInstance = "yes" 
SysMenu = "yes" 
Version = "1.0" 
> 
<style>
.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; 
} 
.tabsNotSelected { 
background-color: wheat; 
border: solid 1px black; 
} 
.tabsSelected { 
background-color: white; 
border-color: black black white black; 
border-style: solid solid solid solid; 
border-width: 1px 1px 1px 1px; 
} 
</style>
<script language="VBscript"> 
Dim sItem 
Dim aPanels 
Dim el 
Dim iPanelCount 
iPanelCount = 2
Dim intColCount
intColCount = 4

Sub Window_OnLoad

	ElevatedCheck
	width = "750"
	height = "750"
	' 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 
	
	'Original OU
	AddRenameToOption selRenameTo, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameTo, "Campus 1 C01 K-1 Lab", "OU=Campus 1,OU=Lab OU 1,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 1 D01 2-3 Lab", "OU=Campus 1,OU=Lab OU 2,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Campus 2 Room 006 Lab", "OU=Campus 2,OU=Lab OU 1,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 2 Room 017 Lab", "OU=Campus 2,OU=Lab OU 2,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 2 Room 326 Lab", "OU=Campus 2,OU=Lab OU 3,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Campus 3 Room 001 Lab", "OU=Campus 3,OU=Lab OU 1,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 3 Room 027 Lab", "OU=Campus 3,OU=Lab OU 2,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 3 Room 028 Lab", "OU=Campus 3,OU=Lab OU 2,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 3 Mobile Lab", "OU=Campus 3,OU=Lab OU 2,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Campus 4 Room 110 Lab", "OU=Campus 4,OU=Lab OU 1,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 4 Room 111 Lab", "OU=Campus 4,OU=Lab OU 2,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Campus 5 Room 11 Lab", "OU=Campus 5,OU=Lab OU 3,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 Room 12 Lab", "OU=Campus 5,OU=Lab OU 4,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 Room 13 Lab", "OU=Campus 5,OU=Lab OU 5,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 Room 48 Lab", "OU=Campus 5,OU=Lab OU 6,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 5 GCS Lab", "OU=Campus 5,OU=Lab OU 7,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Campus 6 East Lab", "OU=Campus 6,OU=Lab OU 1,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Campus 6 West Lab", "OU=Campus 6,OU=Lab OU 2,DC=domain,DC=local"
	
	'Testing OU
	AddRenameToOption selRenameFrom, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameFrom, "Campus 1 C01 K-1 Lab", "OU=Campus 1,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 1 D01 2-3 Lab", "OU=Campus 1,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Campus 2 Room 006 Lab", "OU=Campus 2,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 2 Room 017 Lab", "OU=Campus 2,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 2 Room 326 Lab", "OU=Campus 2,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Campus 3 Room 001 Lab", "OU=Campus 3,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 3 Room 027 Lab", "OU=Campus 3,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 3 Room 028 Lab", "OU=Campus 3,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 3 Mobile Lab", "OU=Campus 3,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Campus 4 Room 110 Lab", "OU=Campus 4,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 4 Room 111 Lab", "OU=Campus 4,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Campus 5 Room 11 Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 Room 12 Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 Room 13 Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 Room 48 Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 5 GCS Lab", "OU=Campus 5,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Campus 6 East Lab", "OU=Campus 6,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Campus 6 West Lab", "OU=Campus 6,OU=TESTNAV,DC=domain,DC=local"
End Sub

Sub ElevatedCheck
	'Source: http://www.thegbach.com/elevatedHta.html
	Set objShell = CreateObject("WScript.Shell")
	Set objShellApp = CreateObject("Shell.Application")
	strElevated = False
	strHTADir = document.location.pathname
	Set objWhoami = objShell.Exec("whoami /groups")
	strWhoami = objWhoami.StdOut.ReadAll
	If InStr(1, strWhoami,"S-1-16-12288",vbTextCompare) Then
	strElevated = True
	Else
		objShellApp.ShellExecute"mshta.exe",Chr(34) & strHTADir & Chr(34) & " runasadministrator","","runas",1
		window.close()
	End If 
End Sub

SUB Check_M_All(checkNum) 
   'ON ERROR RESUME NEXT 
   '    checkNum.Checked = TRUE 
   '    IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.length - 1 
               checkNum(i).checked = TRUE 
           Next 
   '    END IF 
   'ON ERROR GOTO 0 
 END SUB 
 
 SUB Uncheck_M_All(checkNum)
   'ON ERROR RESUME NEXT 
   '    checkNum.Checked = FALSE 
   '    IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.Length - 1 
               checkNum(i).Checked = FALSE 
           NEXT 
   '    END IF 
   'ON ERROR GOTO 0 
 END SUB 
 
 Sub RenameTo(checknum)
	FOR i = 0 TO checkNum.length - 1 
		If checknum(i).checked = True Then
			MsgBox "Renaming " & checknum(i).id & " (" & checknum(i).value & ") to something"
			RenameSinglePCTo checknum(i).id, checknum(i).value
		End If
	Next
End Sub

Sub RenameFrom(checknum2)
	FOR i = 0 TO checkNum2.Length - 1 
		If checknum2(i).checked = True Then
			MsgBox "Renaming " & checknum2(i).id & " (" & checknum2(i).value & ") back to something"
		End If
	Next
End Sub

Private Sub Panel(tab) 
	For i = 1 To iPanelCount 
		If i = tab Then 
			document.getElementById("tab" & i).className = "tabs tabsSelected" 
			document.getElementById("panel" & i).style.display = "block" 
		Else 
			document.getElementById("tab" & i).className = "tabs tabsNotSelected" 
			document.getElementById("panel" & i).style.display = "none" 
		End If 
	Next 
End Sub 

Sub AddRenameToOption(objObject, strText, strValue)
	Set objOption = Document.CreateElement("OPTION")
	objOption.Text = strText
	objOption.Value = strValue
	objObject.Add(objOption)
End Sub

'Sub AddCheck
'	strHTML = panelContents2.InnerHTML 
'	strHTML = strHTML & "<input id=" & intCheckCount & " type=" & Chr(34) & "CheckBox" & Chr(34) & _ 
'		" name=" & Chr(34) & "chkEnabled" & Chr(34) & "value= " & Chr(34) & "CheckBox" & intCheckCount & Chr(34) & " onClick=" & Chr(34) & _ 
'		"NewCheckSubroutine" & Chr(34) & ">" & " <BR>" 
'	panelContents2.InnerHTML = strHTML 
'End Sub 

'Tab 1
Sub TestSub
	strText = selRenameTo.Item(selRenameTo.SelectedIndex).Text
	strValue = selRenameTo.Item(selRenameTo.SelectedIndex).Value
	'MsgBox strText & vbCrLf & strValue
	Set objOU = GetObject("LDAP://" & strValue)
	strNames = ""
	intCol = 0
	strNames = "<table cellspacing=0 cellpadding=0 border=0>"
	For Each objObject In objOU
		If objObject.class = "computer" Then
			strCheckBoxCode = ""
			If intCol = 0 Then
				strCheckBoxCode = "<tr>"
			End If
			strCheckBoxCode = strCheckBoxCode & "<td><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum"" value=""" & objObject.distinguishedName & """>" & Mid(objObject.Name, 4) & "</td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode = strCheckBoxCode & "</tr>"
				intCol = 0
			End If
			If strNames = "" Then
				strNames = strCheckBoxCode
			Else
				strNames = strNames & vbCrLf & strCheckBoxCode
			End If
		End If
	Next
	strNames = strNames & vbCrLf & "</table>"
    instPath.InnerHTML = strNames
End Sub

'Tab 2
Sub TestSub2
	strText2 = selRenameTo.Item(selRenameFrom.SelectedIndex).Text
	strValue2 = selRenameTo.Item(selRenameFrom.SelectedIndex).Value
	'MsgBox strText2 & vbCrLf & strValue2
	Set objOU2 = GetObject("LDAP://" & strValue2)
	strNames2 = ""
	intCol = 0
	strNames2 = "<table cellspacing=0 cellpadding=0 border=0>"
	For Each objObject In objOU2
		If objObject.class = "computer" Then
			strCheckBoxCode2 = ""
			If intCol = 0 Then
				strCheckBoxCode2 = "<tr>"
			End If
			strCheckBoxCode2 = strCheckBoxCode2 & "<td><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum2"" value=""" & objObject.distinguishedName & """>" & Mid(objObject.Name, 4) & "</td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode2 = strCheckBoxCode2 & "</tr>"
				intCol = 0
			End If
			If strNames2 = "" Then
				strNames2 = strCheckBoxCode2
			Else
				strNames2 = strNames2 & vbCrLf & strCheckBoxCode2
			End If
		End If
	Next
	strNames2 = strNames2 & vbCrLf & "</table>"
    instPath2.InnerHTML = strNames2
End Sub

'Sub TestSub2
'	strText2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Text
'	strValue2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Value
'	MsgBox strText2 & vbCrLf & strValue2
'	Set objOU2 = GetObject("LDAP://" & strValue2)
'	strNames2 = ""
'	For Each objObject In objOU2
'		If objObject.class = "computer" Then
'			If strNames2 = "" Then
'				strNames2 = "<input type=""checkbox"" id=""" & objObject.Name & """ name=""checkNum2"" value=""" & objObject.Name & """>" & objObject.Name & "<br>"
'			Else
'				strNames2 = strNames2 & vbCrLf & "<input type=""checkbox"" id=""" & objObject.Name & """ name=""checkNum2"" value=""" & objObject.Name & """>" & objObject.Name & "<br>"
'			End If
'		End If
'	Next
'    instPath2.InnerHTML = strNames2
'End Sub

Sub RenameSinglePCTo(strComputer, strDN)
	strLocalUser = "localuser"
	strLocalPasswd = "localpassword"
	strDomainUser = "domain\domainuser"
	strDomainPasswd = "domainpassword"
	arrLabParts = Split(selRenameTo.Text, " ")
	strNewComputer = "TESTNAV" & Left(selRenameTo.Text) & arrLabParts(UBound(arrLabParts) - 1)) & "-" & Right(strComputer, 4)
	'########################### 
	' Connect to Computer 
	'###########################
	Dim objWMILocator, objWMIComputer, objWMIComputerSystem, rc, objWMIService, colOperatingSystems, objOperatingSystem, objNetwork, objComputer
	Set objNetwork = CreateObject("WScript.Network")
	'Set objWMIComputer = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd) 
	'Set objWMIComputerSystem = objWMIComputer.Get( "Win32_ComputerSystem.Name='" & strComputer & "'") 
	If LCase(strComputer) = LCase(objNetwork.ComputerName) Then
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, authenticationLevel=pktPrivacy, (Shutdown)}!\\" & strComputer & "\root\cimv2") 
	Else
		Set objWMILocator = CreateObject("WbemScripting.SWbemLocator") 
		objWMILocator.Security_.AuthenticationLevel = 6 
		Set objWMIService = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd)
	End If
	'########################### 
	' Rename Computer 
	'########################### 
	Set objWMIComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem Where Name='" & strComputer & "'")
	For Each objWMIComputerSystem In objWMIComputer
		' There will only ever be one element in this collection
		rc = objWMIComputerSystem.Rename(strNewComputer, strDomainPasswd, strDomainUser) 
		if rc <> 0 then 
			Msgbox "Rename failed with error: " & rc 
		else 
			Msgbox "Successfully renamed " & strComputer & " to " & strNewComputer
			'########################### 
			' Place text files on the CURRENT computer that you are running this management from
			'###########################
			Set objFSO = CreateObject("Scripting.FileSystemObject")
			strLogFolder = "C:\PCs_Renamed\"
			If objFSO.FolderExists(strLogFolder) = False Then objFSO.CreateTextFile strLogFolder
			Set objFile = objFSO.CreateTextFile(strLogFolder & strNewComputer & ".txt", True)
			objFile.Write strComputer & ";" & strDN
			objFile.Close
			'########################### 
			' Reboot computer
			'###########################
			'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("RenameFrom").disabled = True
  document.GetElementByID("RenameTo").disabled = true
end Sub

</script> 

</head> 


<body bgcolor="blue"> 
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650"> 
<tr valign="top"> 
<td colspan="2"> 
<span class="tabs tabsSelected" id="tab1" onclick="panel(1)">Rename Computers for Testing</span> 
<span class="tabs tabsNotSelected" id="tab2" onclick="panel(2)">Rename Computers back from Testing</span>
<!-- Tab 1 -->
<div class="panel" id="panel1" style="display:block"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<td style="text-align:right;font-size:0.9em;font-weight:bold;font-style:oblique;color:#888888;">
				Created by Gabriel Clifton
			</td>
		</tr>
	</table>
<!--Add your controls here-->
<select size="1" onChange="TestSub" name="selRenameTo" id="selRenameTo"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll" value="Check All" onclick="Check_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="uchckAll" value="Un-Check All" onclick="UNCheck_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="RenameTo" value="Rename To" onclick="RenameTo(document.myform.checkNum)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform" method="post">
            <span  id="instPath"></span>
        </font></form>
    </TH>
    </tr>
 </table>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

<!-- Tab 2 -->
<div class="panel" id="panel2" style="display:none"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<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>

<!--Add your controls here-->
<select size="1" onChange="TestSub2" name="selRenameFrom" id="selRenameFrom"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename back</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll2" value="Check All" onclick="Check_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="uchckAll2" value="Un-Check All" onclick="Uncheck_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="RenameFrom" value="Rename From" onclick="RenameFrom(document.myform.checkNum2)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform2" method="post">
            <span  id="instPath2"></span>
        </font></form>
    </TH>
    </tr>
 </table>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

</body> 
</html> 

Open in new window


Regards,

Rob.
0
 
Gabriel CliftonNet AdminAuthor Commented:
Thanks, looking at it, trying to look quickly because I have to finish moving. As far as storing the names on the individual pc, so far have had no issues, the techs have local admin permission on the systems themselves.
0
 
Gabriel CliftonNet AdminAuthor Commented:
Also, I have a script that runs on our DC that reads all computer names and moves them to the appropriate OU, It runs every five minutes on the 0 and 5s.
0
 
Gabriel CliftonNet AdminAuthor Commented:
I am leaving for the day, but I have not figured out yet why here I get: Object doesn't support this property or method: 'selRenameTo.Text'

      arrLabParts = Split(selRenameTo.Text, " ")
      strNewComputer = "TESTNAV" & Left(selRenameTo.Text) & arrLabParts(UBound(arrLabParts) - 1)) & "-" & Right(strComputer, 4)

I thought possibly it was

      arrLabParts = Split(selRenameTo.Text, " ")
      strNewComputer = "TESTNAV" & Left(selRenameTo.Text, 2) & arrLabParts(UBound(arrLabParts) - 1)) & "-" & Right(strComputer, 4)

But that did not work
0
 
RobSampsonCommented:
Ah, sorry, it should be
arrLabParts = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Text, " ")
       strNewComputer = "TESTNAV" & Left(selRenameTo.Item(selRenameTo.SelectedIndex).Text) & arrLabParts(UBound(arrLabParts) - 1)) & "-" & Right(strComputer, 4)

I still haven't had time to test it.  See how that goes.

Regards,

Rob.
0
 
Gabriel CliftonNet AdminAuthor Commented:
It is having an issue here, & arrLabParts(UBound(arrLabParts) - 1)), if I take that out there is no issue. With it in I get an Expected end of statement error.
0
 
RobSampsonCommented:
Looks like Bracket issues
arrLabParts = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Text, " ")
       strNewComputer = "TESTNAV" & Left(selRenameTo.Item(selRenameTo.SelectedIndex).Text, 2) & arrLabParts(UBound(arrLabParts) - 1) & "-" & Right(strComputer, 4)

Open in new window

On my phone so hopefully the syntax is right.
0
 
Gabriel CliftonNet AdminAuthor Commented:
OK, the errors are gone, but nothing is happening when I click the rename to button. No logs, no messages.
0
 
Gabriel CliftonNet AdminAuthor Commented:
Maybe it is the way I am reading the code, but cannot figure out how Sub RenameSinglePCTo(strComputer, strDN) is being called to actually rename the computers. I did notice that strComputer and strDN are being used in the rename part but never created. I have tried to get it to work but can't.
0
 
Gabriel CliftonNet AdminAuthor Commented:
OK, just fixed that issue, the only issue that arose out of it is the computer name length, it generated a computer name that was 16 characters long. Now, need to fix the computer name length and the rename back side of the script.
0
 
RobSampsonCommented:
Ok. Post your current code again, and I'll take a look. I thought the TESTNAV might be too long. Can you shorten that?
0
 
Gabriel CliftonNet AdminAuthor Commented:
I am away from my desk at the moment, will post the code when I get back. I have been using testnav for a couple of years but I can shorten it to tstnv
0
 
RobSampsonCommented:
It uses the second last "word" as the lab number, and it's probably the "mobile" ones that take it over 15 characters. What do you usually call those?
0
 
Gabriel CliftonNet AdminAuthor Commented:
Normal scheme is testnaval1-ds01 and testnavhs2-ls05 where we take testnav add two letter campus name lab number which is actually not the lab room number but a number 1-X that I assigned for this only, followed by -and
0
 
Gabriel CliftonNet AdminAuthor Commented:
Last four characters of computer name which ds would be desktop student and ls would be laptop student
0
 
Gabriel CliftonNet AdminAuthor Commented:
Here we go
<html> 
<head> 
<title>Rename Computer Labs for state testing</title> 

<HTA:Application 
ID = "HTA" 
ApplicationName = "RenLab" 
Border = "dialog" 
BorderStyle = "normal" 
Caption = "yes" 
ContextMenu="yes" 
ICON="\\Server\Share\panther.ICO"
InnerBorder="no" 
MaximizeButton = "no" 
MinimizeButton = "no" 
Navigable="yes" 
Scroll="yes" 
SrollFlat="no" 
Selection="yes" 
ShowInTaskBar = "yes" 
SingleInstance = "yes" 
SysMenu = "yes" 
Version = "1.0" 
> 
<style>
.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; 
} 
.tabsNotSelected { 
background-color: wheat; 
border: solid 1px black; 
} 
.tabsSelected { 
background-color: white; 
border-color: black black white black; 
border-style: solid solid solid solid; 
border-width: 1px 1px 1px 1px; 
} 
</style>
<script language="VBscript"> 
Dim sItem 
Dim aPanels 
Dim el 
Dim iPanelCount 
iPanelCount = 2
Dim intColCount
intColCount = 4

Sub Window_OnLoad

	ElevatedCheck
	width = "750"
	height = "750"
	' 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 
	
	'Original OU
	AddRenameToOption selRenameTo, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Alamo D01 2-3 Lab", "OU=Alamo Room D01 Student,OU=RM D01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Apache Room 006 Lab", "OU=Apache Lab Room 006 Student,OU=RM 06 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Apache Room 017 Lab", "OU=Apache Lab Room 017 Student,OU=Apache Lab Room 017,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Apache Room 326 Lab", "OU=Apache Lab Room 326 Student,OU=RM 326 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Intermediate Room 001 Lab", "OU=Intermediate Lab Room 001 Student,OU=RM 01 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Intermediate Room 012 Lab", "OU=Intermediate Lab Room 012 Student,OU=RM 12 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Intermediate Room 027 Lab", "OU=Intermediate Lab Room 027 Student,OU=RM 27 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Intermediate Room 028 Lab", "OU=Intermediate Lab Room 028 Student,OU=RM 28 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Intermediate Mobile Lab", "OU=Mobile Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Middle School Room 110 Lab", "OU=Middle School 110 Lab Student,OU=RM 110 Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room 111 Lab", "OU=Middle School 111 Lab Student,OU=RM 111 Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room 118 Lab", "OU=Middle School Math Lab Student,OU=RM 118 Math Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room 125 Lab", "OU=Middle School Science Lab Student,OU=RM 125 Science Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room 126 Lab", "OU=Middle School Robotics Lab Student,OU=RM 126 Robotics Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room 127 Lab", "OU=Middle School Spec-Ed Lab Student,OU=RM 127 Spec-Ed Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room 130 Lab", "OU=Middle School Reading Lab Teacher,OU=RM 130 Reading Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room 141 Lab", "OU=Student,OU=RM 141 Mobile Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room GCS Lab", "OU=Middle School GCS Lab Student,OU=RM GCS Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "High School Room 11 Lab", "OU=HS Lab Room 11 Student,OU=RM 11 Panther Den Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "High School Room 12 Lab", "OU=HS Lab Room 12 Student,OU=RM 12 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "High School Room 13 Lab", "OU=High School Room 013 Student,OU=Rm 013 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "High School Room 47 Lab", "OU=HS Lab Room 47 Student,OU=RM 47 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "High School Room 48 Lab", "OU=HS Lab Room 48 Student,OU=RM 48 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "High School GCS Lab", "OU=HS GCS Lab Student,OU=RM GCS Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Technology East Lab", "OU=East Computers,OU=East Lab,OU=Training Lab,OU=Technology Center,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Technology West Lab", "OU=West Computers,OU=West Lab,OU=Training Lab,OU=Technology Center,OU=Locations,DC=domain,DC=local"
	
	'Testing OU
	AddRenameToOption selRenameFrom, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameFrom, "Alamo C01 K-1 Lab", "OU=Alamo,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Alamo D01 2-3 Lab", "OU=Alamo,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Apache Room 006 Lab", "OU=Apache,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Apache Room 017 Lab", "OU=Apache,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Apache Room 326 Lab", "OU=Apache,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Intermediate Room 001 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Intermediate Room 027 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Intermediate Room 028 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Intermediate Mobile Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Middle School Room 110 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Middle School Room 111 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "High School Room 11 Lab", "OU=High School,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "High School Room 12 Lab", "OU=High School,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "High School Room 13 Lab", "OU=High School,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "High School Room 48 Lab", "OU=High School,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "High School GCS Lab", "OU=High School,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Technology East Lab", "OU=Technology,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Technology West Lab", "OU=Technology,OU=TESTNAV,DC=domain,DC=local"
End Sub

Sub ElevatedCheck
	'Source: http://www.thegbach.com/elevatedHta.html
	Set objShell = CreateObject("WScript.Shell")
	Set objShellApp = CreateObject("Shell.Application")
	strElevated = False
	strHTADir = document.location.pathname
	Set objWhoami = objShell.Exec("whoami /groups")
	strWhoami = objWhoami.StdOut.ReadAll
	If InStr(1, strWhoami,"S-1-16-12288",vbTextCompare) Then
	strElevated = True
	Else
		objShellApp.ShellExecute"mshta.exe",Chr(34) & strHTADir & Chr(34) & " runasadministrator","","runas",1
		window.close()
	End If 
End Sub

SUB Check_M_All(checkNum) 
   ON ERROR RESUME NEXT 
       checkNum.Checked = TRUE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.length - 1 
               checkNum(i).checked = TRUE 
           Next 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
 SUB Uncheck_M_All(checkNum)
   ON ERROR RESUME NEXT 
       checkNum.Checked = FALSE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.Length - 1 
               checkNum(i).Checked = FALSE 
           NEXT 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
Private Sub Panel(tab) 
	For i = 1 To iPanelCount 
		If i = tab Then 
			document.getElementById("tab" & i).className = "tabs tabsSelected" 
			document.getElementById("panel" & i).style.display = "block" 
		Else 
			document.getElementById("tab" & i).className = "tabs tabsNotSelected" 
			document.getElementById("panel" & i).style.display = "none" 
		End If 
	Next 
End Sub 

Sub AddRenameToOption(objObject, strText, strValue)
	Set objOption = Document.CreateElement("OPTION")
	objOption.Text = strText
	objOption.Value = strValue
	objObject.Add(objOption)
End Sub

'Tab 1
Sub TestSub
	strText = selRenameTo.Item(selRenameTo.SelectedIndex).Text
	strValue = selRenameTo.Item(selRenameTo.SelectedIndex).Value
	'MsgBox strText & vbCrLf & strValue
	Set objOU = GetObject("LDAP://" & strValue)
	strNames = ""
	intCol = 0
	strNames = "<table cellspacing=10 cellpadding=0 border=0>"
	For Each objObject In objOU
		If objObject.class = "computer" Then
			strCheckBoxCode = ""
			If intCol = 0 Then
				strCheckBoxCode = "<tr>"
			End If
			strCheckBoxCode = strCheckBoxCode & "<td><font color=""white""><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum"" value=""" & objObject.distinguishedName & """>" & Mid(objObject.Name, 4) & "</font></td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode = strCheckBoxCode & "</tr>"
				intCol = 0
			End If
			If strNames = "" Then
				strNames = strCheckBoxCode
			Else
				strNames = strNames & vbCrLf & strCheckBoxCode
			End If
		End If
	Next
	strNames = strNames & vbCrLf & "</table>"
    instPath.InnerHTML = strNames
End Sub

'Tab 2
Sub TestSub2
	strText2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Text
	strValue2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Value
	'MsgBox strText2 & vbCrLf & strValue2
	Set objOU2 = GetObject("LDAP://" & strValue2)
	strNames2 = ""
	intCol = 0
	strNames2 = "<table cellspacing=10 cellpadding=0 border=0>"
	For Each objObject In objOU2
		If objObject.class = "computer" Then
			strCheckBoxCode2 = ""
			If intCol = 0 Then
				strCheckBoxCode2 = "<tr>"
			End If
			strCheckBoxCode2 = strCheckBoxCode2 & "<td><font color=""white""><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum2"" value=""" & objObject.distinguishedName & """>" & Mid(objObject.Name, 4) & "</font></td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode2 = strCheckBoxCode2 & "</tr>"
				intCol = 0
			End If
			If strNames2 = "" Then
				strNames2 = strCheckBoxCode2
			Else
				strNames2 = strNames2 & vbCrLf & strCheckBoxCode2
			End If
		End If
	Next
	strNames2 = strNames2 & vbCrLf & "</table>"
    instPath2.InnerHTML = strNames2
End Sub

Sub RenameTo(checknum)
	FOR i = 0 TO checkNum.length - 1 
		If checknum(i).checked = True Then
			MsgBox "Renaming " & checknum(i).id & vbCrLf& checknum(i).value & vbCrLf & " to " & strNewComputer
	strComputer = checknum(i).id
	strDN = Mid(checknum(i).value,INSTR(checknum(i).value,",")+1,LEN(checknum(i).value)-INSTR(checknum(i).value,","))
			MsgBox "1. " & strComputer & vbCrLf & "2. " & checknum(i).value & vbCrLf & "3. " & strDN
			Call RenameSinglePCTo(strComputer, strDN)
		End If
	Next
End Sub

Sub RenameSinglePCTo(strComputer, strDN)
strDomainUser = document.getElementById("uName").value & "@domain.local"
strDomainPasswd = document.getElementById("uPassword").value
strLocalUser = strComputer & "\administrator"
strLocalPasswd = "password" 
arrLabParts = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Text, " ")
       strNewComputer = "TESTNAV" & Left(selRenameTo.Item(selRenameTo.SelectedIndex).Text, 2) & arrLabParts(UBound(arrLabParts) - 1) & "-" & Right(strComputer, 4)
	MsgBox strNewComputer
	'########################### 
	' Connect to Computer 
	'###########################
	Dim objWMILocator, objWMIComputer, objWMIComputerSystem, rc, objWMIService, colOperatingSystems, objOperatingSystem, objNetwork, objComputer
	Set objNetwork = CreateObject("WScript.Network")
	'Set objWMIComputer = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd) 
	'Set objWMIComputerSystem = objWMIComputer.Get( "Win32_ComputerSystem.Name='" & strComputer & "'") 
	If LCase(strComputer) = LCase(objNetwork.ComputerName) Then
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, authenticationLevel=pktPrivacy, (Shutdown)}!\\" & strComputer & "\root\cimv2") 
	Else
		Set objWMILocator = CreateObject("WbemScripting.SWbemLocator") 
		objWMILocator.Security_.AuthenticationLevel = 6 
		Set objWMIService = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd)
	End If
	'########################### 
	' Rename Computer 
	'########################### 
	Set objWMIComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem Where Name='" & strComputer & "'")
	For Each objWMIComputerSystem In objWMIComputer
		' There will only ever be one element in this collection
		rc = objWMIComputerSystem.Rename(strNewComputer, strDomainPasswd, strDomainUser) 
		if rc <> 0 then 
			Msgbox "Rename failed with error: " & rc 
		else 
			Msgbox "Successfully renamed " & strComputer & " to " & strNewComputer
			'########################### 
			' Place text files on the CURRENT computer that you are running this management from
			'###########################
			Set objFSO = CreateObject("Scripting.FileSystemObject")
			strLogFolder = "C:\PCs_Renamed\"
			If objFSO.FolderExists(strLogFolder) = False Then objFSO.CreateTextFile strLogFolder
			Set objFile = objFSO.CreateTextFile(strLogFolder & strNewComputer & ".txt", True)
			objFile.Write strComputer & ";" & strDN
			objFile.Close
			'########################### 
			' Reboot computer
			'###########################
			'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("RenameFrom").disabled = True
  document.GetElementByID("RenameTo").disabled = true
end Sub

Sub RenameFrom(checknum2)
           FOR i = 0 TO checkNum2.Length - 1 
		If checknum2(i).checked = True Then
			MsgBox "Renaming " & checknum2(i).id & " (" & checknum2(i).value & ") back to " & strNewComputer
		End If
	Next
End Sub

</script> 

</head> 


<body bgcolor="blue"> 
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650"> 
<tr valign="top"> 
<td colspan="2"> 
<span class="tabs tabsSelected" id="tab1" onclick="panel(1)">Rename Computers for Testing</span> 
<span class="tabs tabsNotSelected" id="tab2" onclick="panel(2)">Rename Computers back from Testing</span>
<!-- Tab 1 -->
<div class="panel" id="panel1" style="display:block"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<td style="text-align:right;font-size:0.9em;font-weight:bold;font-style:oblique;color:#888888;">
				Created by Gabriel Clifton
			</td>
		</tr>
	</table>
<!--Add your controls here-->
<select size="1" onChange="TestSub" name="selRenameTo" id="selRenameTo"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll" value="Check All" onclick="Check_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="uchckAll" value="Un-Check All" onclick="UNCheck_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="RenameTo" value="Rename To" onclick="RenameTo(document.myform.checkNum)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform" method="post">
            <span  id="instPath"></span>
        </font></form>
    </TH>
    </tr>
 </table>
  <table>
 	<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>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

<!-- Tab 2 -->
<div class="panel" id="panel2" style="display:none"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<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>

<!--Add your controls here-->
<select size="1" onChange="TestSub2" name="selRenameFrom" id="selRenameFrom"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename back</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll2" value="Check All" onclick="Check_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="uchckAll2" value="Un-Check All" onclick="Uncheck_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="RenameFrom" value="Rename From" onclick="RenameFrom(document.myform2.checkNum2)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform2" method="post">
            <span  id="instPath2"></span>
        </font></form>
    </TH>
    </tr>
 </table>
 <table>
 	<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>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

</body> 
</html> 

Open in new window

0
 
Gabriel CliftonNet AdminAuthor Commented:
I think that if we change TESTNAV  in the computer name to TSTNV and assign each lab at each campus a number 1 - X and use that in the name, we could cut the name down to less than 15 charachters. The way the current scheme is, if I have 9 labs in one campus, I could have a computer name with 15 characters. TESTNAVMS9-DS20. Right now, my biggest campus has 20+ labs and that number is increasing, only 6 are currently are used for testing. Admins are already talking about having all students do online testing instead of a few which could lead to all labs being used in the future.
0
 
RobSampsonCommented:
Right, so to determine that programmatically, take these as an example of what we have listed:
	AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Apache Room 326 Lab", "OU=Apache Lab Room 326 Student,OU=RM 326 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Intermediate Mobile Lab", "OU=Mobile Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,DC=local"

Open in new window


Since the code currently takes the second last "word" as the lab number, It would name those as the following:
TESTNAVALK-1XXXX
TESTNAVAP326XXXX
TESTNAVINMOBILEXXXX

So, I suspect we need a way to tell the script what to name the new computer, since it will be different to that naming scheme.

Maybe we need to do something like
	AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,DC=local|TSTNVAL1-XYYYY"
	AddRenameToOption selRenameTo, "Apache Room 326 Lab", "OU=Apache Lab Room 326 Student,OU=RM 326 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,DC=local|TSTNVAP9-XYYYY"
	AddRenameToOption selRenameTo, "Intermediate Mobile Lab", "OU=Mobile Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,DC=local|TSTNVIN3-XYYYY"

Open in new window


where we add a pipe character, then the new name, where in the code you manually put in the N-X part, and the YYYY (leave that as is) will be automatically substituted with the last four characters of the original name.

Would that work?

Regards,

Rob.
0
 
Gabriel CliftonNet AdminAuthor Commented:
This should work
	AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,DC=local|TSTNVAL1-XYYYY"
	AddRenameToOption selRenameTo, "Apache Room 326 Lab", "OU=Apache Lab Room 326 Student,OU=RM 326 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,DC=local|TSTNVAP9-XYYYY"
	AddRenameToOption selRenameTo, "Intermediate Mobile Lab", "OU=Mobile Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,DC=local|TSTNVIN3-XYYYY"

Open in new window

That way we have more control over the name especially since the second to last word could be the same for some labs.
0
 
Gabriel CliftonNet AdminAuthor Commented:
I am still interested in getting this to work. I understand that busy schedules make it hard to help sometimes.
0
 
RobSampsonCommented:
Hi, sorry for my delay!  I know haven't contributed to this for nearly two months!  I'm in a new role now, so have been very very busy.

I can post this updated code, which should work to that idea posted above about putting |NAME-XYYYY in as a naming scheme.

See how it goes.

Regards,

Rob.

<html> 
<head> 
<title>Rename Computer Labs for state testing</title> 

<HTA:Application 
ID = "HTA" 
ApplicationName = "RenLab" 
Border = "dialog" 
BorderStyle = "normal" 
Caption = "yes" 
ContextMenu="yes" 
ICON="\\Server\Share\panther.ICO"
InnerBorder="no" 
MaximizeButton = "no" 
MinimizeButton = "no" 
Navigable="yes" 
Scroll="yes" 
SrollFlat="no" 
Selection="yes" 
ShowInTaskBar = "yes" 
SingleInstance = "yes" 
SysMenu = "yes" 
Version = "1.0" 
> 
<style>
.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; 
} 
.tabsNotSelected { 
background-color: wheat; 
border: solid 1px black; 
} 
.tabsSelected { 
background-color: white; 
border-color: black black white black; 
border-style: solid solid solid solid; 
border-width: 1px 1px 1px 1px; 
} 
</style>
<script language="VBscript"> 
Dim sItem 
Dim aPanels 
Dim el 
Dim iPanelCount 
iPanelCount = 2
Dim intColCount
intColCount = 4

Sub Window_OnLoad

	ElevatedCheck
	width = "750"
	height = "750"
	' 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 
	
	'Original OU
	AddRenameToOption selRenameTo, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Alamo D01 2-3 Lab", "OU=Alamo Room D01 Student,OU=RM D01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Apache Room 006 Lab", "OU=Apache Lab Room 006 Student,OU=RM 06 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Apache Room 017 Lab", "OU=Apache Lab Room 017 Student,OU=Apache Lab Room 017,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Apache Room 326 Lab", "OU=Apache Lab Room 326 Student,OU=RM 326 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Intermediate Room 001 Lab", "OU=Intermediate Lab Room 001 Student,OU=RM 01 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Intermediate Room 012 Lab", "OU=Intermediate Lab Room 012 Student,OU=RM 12 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Intermediate Room 027 Lab", "OU=Intermediate Lab Room 027 Student,OU=RM 27 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Intermediate Room 028 Lab", "OU=Intermediate Lab Room 028 Student,OU=RM 28 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Intermediate Mobile Lab", "OU=Mobile Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Middle School Room 110 Lab", "OU=Middle School 110 Lab Student,OU=RM 110 Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room 111 Lab", "OU=Middle School 111 Lab Student,OU=RM 111 Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room 118 Lab", "OU=Middle School Math Lab Student,OU=RM 118 Math Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room 125 Lab", "OU=Middle School Science Lab Student,OU=RM 125 Science Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room 126 Lab", "OU=Middle School Robotics Lab Student,OU=RM 126 Robotics Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room 127 Lab", "OU=Middle School Spec-Ed Lab Student,OU=RM 127 Spec-Ed Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room 130 Lab", "OU=Middle School Reading Lab Teacher,OU=RM 130 Reading Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room 141 Lab", "OU=Student,OU=RM 141 Mobile Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Middle School Room GCS Lab", "OU=Middle School GCS Lab Student,OU=RM GCS Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "High School Room 11 Lab", "OU=HS Lab Room 11 Student,OU=RM 11 Panther Den Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "High School Room 12 Lab", "OU=HS Lab Room 12 Student,OU=RM 12 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "High School Room 13 Lab", "OU=High School Room 013 Student,OU=Rm 013 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "High School Room 47 Lab", "OU=HS Lab Room 47 Student,OU=RM 47 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "High School Room 48 Lab", "OU=HS Lab Room 48 Student,OU=RM 48 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "High School GCS Lab", "OU=HS GCS Lab Student,OU=RM GCS Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,DC=local"
	
	AddRenameToOption selRenameTo, "Technology East Lab", "OU=East Computers,OU=East Lab,OU=Training Lab,OU=Technology Center,OU=Locations,DC=domain,DC=local"
	AddRenameToOption selRenameTo, "Technology West Lab", "OU=West Computers,OU=West Lab,OU=Training Lab,OU=Technology Center,OU=Locations,DC=domain,DC=local"
	
	'Testing OU
	AddRenameToOption selRenameFrom, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameFrom, "Alamo C01 K-1 Lab", "OU=Alamo,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Alamo D01 2-3 Lab", "OU=Alamo,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Apache Room 006 Lab", "OU=Apache,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Apache Room 017 Lab", "OU=Apache,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Apache Room 326 Lab", "OU=Apache,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Intermediate Room 001 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Intermediate Room 027 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Intermediate Room 028 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Intermediate Mobile Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Middle School Room 110 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Middle School Room 111 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "High School Room 11 Lab", "OU=High School,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "High School Room 12 Lab", "OU=High School,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "High School Room 13 Lab", "OU=High School,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "High School Room 48 Lab", "OU=High School,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "High School GCS Lab", "OU=High School,OU=TESTNAV,DC=domain,DC=local"
	
	AddRenameToOption selRenameFrom, "Technology East Lab", "OU=Technology,OU=TESTNAV,DC=domain,DC=local"
	AddRenameToOption selRenameFrom, "Technology West Lab", "OU=Technology,OU=TESTNAV,DC=domain,DC=local"
End Sub

Sub ElevatedCheck
	'Source: http://www.thegbach.com/elevatedHta.html
	Set objShell = CreateObject("WScript.Shell")
	Set objShellApp = CreateObject("Shell.Application")
	strElevated = False
	strHTADir = document.location.pathname
	Set objWhoami = objShell.Exec("whoami /groups")
	strWhoami = objWhoami.StdOut.ReadAll
	If InStr(1, strWhoami,"S-1-16-12288",vbTextCompare) Then
	strElevated = True
	Else
		objShellApp.ShellExecute"mshta.exe",Chr(34) & strHTADir & Chr(34) & " runasadministrator","","runas",1
		window.close()
	End If 
End Sub

SUB Check_M_All(checkNum) 
   ON ERROR RESUME NEXT 
       checkNum.Checked = TRUE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.length - 1 
               checkNum(i).checked = TRUE 
           Next 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
 SUB Uncheck_M_All(checkNum)
   ON ERROR RESUME NEXT 
       checkNum.Checked = FALSE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.Length - 1 
               checkNum(i).Checked = FALSE 
           NEXT 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
Private Sub Panel(tab) 
	For i = 1 To iPanelCount 
		If i = tab Then 
			document.getElementById("tab" & i).className = "tabs tabsSelected" 
			document.getElementById("panel" & i).style.display = "block" 
		Else 
			document.getElementById("tab" & i).className = "tabs tabsNotSelected" 
			document.getElementById("panel" & i).style.display = "none" 
		End If 
	Next 
End Sub 

Sub AddRenameToOption(objObject, strText, strValue)
	Set objOption = Document.CreateElement("OPTION")
	objOption.Text = strText
	objOption.Value = strValue
	objObject.Add(objOption)
End Sub

'Tab 1
Sub TestSub
	strText = selRenameTo.Item(selRenameTo.SelectedIndex).Text
	strValue = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Value, "|")(0)
	strNaming = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Value, "|")(1)
	'MsgBox strText & vbCrLf & strValue
	Set objOU = GetObject("LDAP://" & strValue)
	strNames = ""
	intCol = 0
	strNames = "<table cellspacing=10 cellpadding=0 border=0>"
	For Each objObject In objOU
		If objObject.class = "computer" Then
			strCheckBoxCode = ""
			If intCol = 0 Then
				strCheckBoxCode = "<tr>"
			End If
			strCheckBoxCode = strCheckBoxCode & "<td><font color=""white""><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum"" value=""" & objObject.distinguishedName & "|" & strNaming & """>" & Mid(objObject.Name, 4) & "</font></td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode = strCheckBoxCode & "</tr>"
				intCol = 0
			End If
			If strNames = "" Then
				strNames = strCheckBoxCode
			Else
				strNames = strNames & vbCrLf & strCheckBoxCode
			End If
		End If
	Next
	strNames = strNames & vbCrLf & "</table>"
    instPath.InnerHTML = strNames
End Sub

'Tab 2
Sub TestSub2
	strText2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Text
	strValue2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Value
	'MsgBox strText2 & vbCrLf & strValue2
	Set objOU2 = GetObject("LDAP://" & strValue2)
	strNames2 = ""
	intCol = 0
	strNames2 = "<table cellspacing=10 cellpadding=0 border=0>"
	For Each objObject In objOU2
		If objObject.class = "computer" Then
			strCheckBoxCode2 = ""
			If intCol = 0 Then
				strCheckBoxCode2 = "<tr>"
			End If
			strCheckBoxCode2 = strCheckBoxCode2 & "<td><font color=""white""><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum2"" value=""" & objObject.distinguishedName & """>" & Mid(objObject.Name, 4) & "</font></td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode2 = strCheckBoxCode2 & "</tr>"
				intCol = 0
			End If
			If strNames2 = "" Then
				strNames2 = strCheckBoxCode2
			Else
				strNames2 = strNames2 & vbCrLf & strCheckBoxCode2
			End If
		End If
	Next
	strNames2 = strNames2 & vbCrLf & "</table>"
    instPath2.InnerHTML = strNames2
End Sub

Sub RenameTo(checknum)
	FOR i = 0 TO checkNum.length - 1 
		If checknum(i).checked = True Then
			'MsgBox "Renaming " & checknum(i).id & vbCrLf& checknum(i).value & vbCrLf & " to " & strNewComputer
			strComputer = checknum(i).id
			strDN = Split(checknum(i).value, "|")(0)
			strParentOU = Split(Mid(checknum(i).value,INSTR(checknum(i).value,",")+1,LEN(checknum(i).value)-INSTR(checknum(i).value,",")), "|")(0)
			strNamingConvention = Split(Mid(checknum(i).value,INSTR(checknum(i).value,",")+1,LEN(checknum(i).value)-INSTR(checknum(i).value,",")), "|")(1)
			MsgBox "1. " & strComputer & vbCrLf & "2. " & strDN & vbCrLf & "3. " & strParentOU & vbCrLf & "3. " & strNamingConvention
			Call RenameSinglePCTo(strComputer, strParentOU, strNamingConvention)
		End If
	Next
End Sub

Sub RenameSinglePCTo(strComputer, strOU, strConvention)
	strDomainUser = document.getElementById("uName").value & "@domain.local"
	strDomainPasswd = document.getElementById("uPassword").value
	strLocalUser = strComputer & "\administrator"
	strLocalPasswd = "password" 
	arrLabParts = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Text, " ")
       'strNewComputer = "TESTNAV" & Left(selRenameTo.Item(selRenameTo.SelectedIndex).Text, 2) & arrLabParts(UBound(arrLabParts) - 1) & "-" & Right(strComputer, 4)
    strNewComputer = Replace(strConvention, "YYYY", Right(strComputer, 4))
	MsgBox strNewComputer
	'Exit Sub
	'########################### 
	' Connect to Computer 
	'###########################
	Dim objWMILocator, objWMIComputer, objWMIComputerSystem, rc, objWMIService, colOperatingSystems, objOperatingSystem, objNetwork, objComputer
	Set objNetwork = CreateObject("WScript.Network")
	'Set objWMIComputer = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd) 
	'Set objWMIComputerSystem = objWMIComputer.Get( "Win32_ComputerSystem.Name='" & strComputer & "'") 
	If LCase(strComputer) = LCase(objNetwork.ComputerName) Then
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, authenticationLevel=pktPrivacy, (Shutdown)}!\\" & strComputer & "\root\cimv2") 
	Else
		Set objWMILocator = CreateObject("WbemScripting.SWbemLocator") 
		objWMILocator.Security_.AuthenticationLevel = 6 
		Set objWMIService = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd)
	End If
	'########################### 
	' Rename Computer 
	'########################### 
	Set objWMIComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem Where Name='" & strComputer & "'")
	For Each objWMIComputerSystem In objWMIComputer
		' There will only ever be one element in this collection
		rc = objWMIComputerSystem.Rename(strNewComputer, strDomainPasswd, strDomainUser) 
		if rc <> 0 then 
			Msgbox "Rename failed with error: " & rc 
		else 
			Msgbox "Successfully renamed " & strComputer & " to " & strNewComputer
			'########################### 
			' Place text files on the CURRENT computer that you are running this management from
			'###########################
			Set objFSO = CreateObject("Scripting.FileSystemObject")
			strLogFolder = "C:\PCs_Renamed\"
			If objFSO.FolderExists(strLogFolder) = False Then objFSO.CreateTextFile strLogFolder
			Set objFile = objFSO.CreateTextFile(strLogFolder & strNewComputer & ".txt", True)
			objFile.Write strComputer & ";" & strOU
			objFile.Close
			'########################### 
			' Reboot computer
			'###########################
			'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("RenameFrom").disabled = True
  document.GetElementByID("RenameTo").disabled = true
end Sub

Sub RenameFrom(checknum2)
           FOR i = 0 TO checkNum2.Length - 1 
		If checknum2(i).checked = True Then
			MsgBox "Renaming " & checknum2(i).id & " (" & checknum2(i).value & ") back to " & strNewComputer
		End If
	Next
End Sub

</script> 

</head> 


<body bgcolor="blue"> 
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650"> 
<tr valign="top"> 
<td colspan="2"> 
<span class="tabs tabsSelected" id="tab1" onclick="panel(1)">Rename Computers for Testing</span> 
<span class="tabs tabsNotSelected" id="tab2" onclick="panel(2)">Rename Computers back from Testing</span>
<!-- Tab 1 -->
<div class="panel" id="panel1" style="display:block"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<td style="text-align:right;font-size:0.9em;font-weight:bold;font-style:oblique;color:#888888;">
				Created by Gabriel Clifton
			</td>
		</tr>
	</table>
<!--Add your controls here-->
<select size="1" onChange="TestSub" name="selRenameTo" id="selRenameTo"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll" value="Check All" onclick="Check_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="uchckAll" value="Un-Check All" onclick="UNCheck_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="RenameTo" value="Rename To" onclick="RenameTo(document.myform.checkNum)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform" method="post">
            <span  id="instPath"></span>
        </font></form>
    </TH>
    </tr>
 </table>
  <table>
 	<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>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

<!-- Tab 2 -->
<div class="panel" id="panel2" style="display:none"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<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>

<!--Add your controls here-->
<select size="1" onChange="TestSub2" name="selRenameFrom" id="selRenameFrom"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename back</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll2" value="Check All" onclick="Check_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="uchckAll2" value="Un-Check All" onclick="Uncheck_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="RenameFrom" value="Rename From" onclick="RenameFrom(document.myform2.checkNum2)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform2" method="post">
            <span  id="instPath2"></span>
        </font></form>
    </TH>
    </tr>
 </table>
 <table>
 	<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>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

</body> 
</html> 

Open in new window

0
 
Gabriel CliftonNet AdminAuthor Commented:
Sorry, I happen to be on vacation this week. I will look at it when I get back to the office.
0
 
Gabriel CliftonNet AdminAuthor Commented:
I am lost. I ran your current script and upon selecting a computer lab, I get an error on line 199 which is
'Tab 1
Sub TestSub
	strText = selRenameTo.Item(selRenameTo.SelectedIndex).Text
	strValue = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Value, "|")(0)
	strNaming = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Value, "|")(1)

Open in new window


Error
Line: 199
Column: 2
Error: Subscript out of range: '[number:1]'
Code: 800A0009

So I changed the strNaming line from (1) to (0) and now I get a new error when trying to rename computer.

Error
Line 296
column 3
Error The RPC server is unavailable.
code 800706BA

But it looks like it is trying to rename the computer to the original computer name, ie rename comp1 to comp1.
0
 
RobSampsonCommented:
Hi, have you added the naming convention to the AddRenameTo lines with the pipe at the end and the convention as in comment id 40766775? It sounds like you haven't add those which is why you get subscript out of range.

Rob.
0
 
Gabriel CliftonNet AdminAuthor Commented:
OK, I may not be understanding that part right, I have tried:
      AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,DC=local"|NAME

      AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,DC=local", |NAME

      AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,DC=local", | NAME

      AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,DC=local", | "NAME"

      AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,DC=local", "|NAME"

And it is not working
0
 
RobSampsonCommented:
It will go inside the quotes after DC=local so
      AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,DC=local|NAME"

Rob.
0
 
Gabriel CliftonNet AdminAuthor Commented:
AHHHHH, perfect. Now if I could figure out why I am getting and error for line 296 this section will be complete.

Line 296
column 3
Error The RPC server is unavailable
code 800706BA
Source SWbemLocator
System The RPC server is unavailable.

No Windows firewall and RPC service is running.
0
 
Gabriel CliftonNet AdminAuthor Commented:
Well it turns out that the system that I was testing this on was having the issue. Tested on other systems this morning and all is well it appears.
0
 
Gabriel CliftonNet AdminAuthor Commented:
Right now I am looking at the rename back side which is giving an error.

Line: 341
Column: 12
Error: Object doesn't support this property or method: 'checknum2.length'
Code: 800A01B6
0
 
RobSampsonCommented:
Hi, I hadn't done anything with the Rename From part, but I have just written this version of the RenameFrom sub.  Can you try this out?

Sub RenameFrom(checknum2)
	For i = 0 TO checkNum2.Length - 1 
		If checknum2(i).checked = True Then
			'MsgBox "Renaming " & checknum2(i).id & " (" & checknum2(i).value & ") back to " & strNewComputer
			'strOldNameFile = "C:\PCs_Renamed\" & checknum2(i).value & ".txt"
			strOldNameFile = "\\" & checknum2(i).value & "\C$\PCs_Renamed\" & checknum2(i).value & ".txt"
			If objFSO.FileExists(strOldNameFile) = True Then
				Set objFile = objFSO.OpenTextFile(strOldNameFile, 1, False)
				strLine = objFile.ReadLine
				objFile.Close
				strOldComputer = Split(strLine, ";")(0)
				strOldOU = Split(strLine, ";")(1)
				MsgBox "Renaming " & checknum2(i).value & " back to " & strOldComputer & vbCrLf & "Original OU: " & strOldOU
			Else
				MsgBox "Cannot find file containing old PC name for " & checknum2(i).value & vbCrLf & strOldNameFile
			End If
		End If
	Next
End Sub

Open in new window


Note that that expects the file C:\PCs_Renamed\<oldpcname>.txt to have been written to the PC that was renamed.

Regards,

Rob.
0
 
Gabriel CliftonNet AdminAuthor Commented:
OK, changed it, but I am getting an error.
Line: 347
Column: 4
Error: Object reguired: 'objFSO
Code: 800A01A8

So I added             Set objFSO = CreateObject("Scripting.FileSystemObject")
before that line which got me further, but now it cannot find the file because it is looking for the wrong name. It is looking for this: \\CN=TestName, OU=TestOU,DC=Domain,DC=Local\C$\PCsRenamed\CN=TestName, OU=TestOU,DC=Domain,DC=Local.txt

Which you have the file being written to the computer running the script on when naming the computer to the testing format and reading the file from the testing computer on rename back. I did copy the file to the testing computer. Now this leads me to a question for you. Is it easier to write this so that on naming computer back, instead of reading the info from a file, it reads based on | like on naming to or if computer testing name is this then name back to that.
0
 
RobSampsonCommented:
>> on naming computer back, instead of reading the info from a file, it reads based on | like on naming to or if computer testing name is this then name back to that.

Yes, provided that you want those names to be of a similar standard convention, then that would work fine.  Again, we can keep the last four characters of the computer name if that makes then unique.

Do you still want to keep the log in the PCs_Renamed folder?  We probably don't need that anymore.

I will start writing a new version without that log, and post it soon.

Rob.
0
 
RobSampsonCommented:
Actually, we don't need to do much.

Use this as the RenameFrom sub, and it should pick up the naming convention from the AddRenameToOption selRenameFrom
lines where you add the original naming convention.

Sub RenameFrom(checknum2)
	For i = 0 TO checkNum2.Length - 1 
		If checknum2(i).checked = True Then
			'MsgBox "Renaming " & checknum2(i).id & vbCrLf& checknum2(i).value & vbCrLf & " to " & strNewComputer
			strComputer = checknum2(i).id
			strDN = Split(checknum2(i).value, "|")(0)
			strParentOU = Split(Mid(checknum2(i).value,INSTR(checknum2(i).value,",")+1,LEN(checknum2(i).value)-INSTR(checknum2(i).value,",")), "|")(0)
			strNamingConvention = Split(Mid(checknum2(i).value,INSTR(checknum2(i).value,",")+1,LEN(checknum2(i).value)-INSTR(checknum2(i).value,",")), "|")(1)
			MsgBox "1. " & strComputer & vbCrLf & "2. " & strDN & vbCrLf & "3. " & strParentOU & vbCrLf & "3. " & strNamingConvention
			Call RenameSinglePCTo(strComputer, strParentOU, strNamingConvention)
		End If
	Next
End Sub

Open in new window


Regards,

Rob.
0
 
Gabriel CliftonNet AdminAuthor Commented:
Spent all day working on this. Added what you posted, made adjustments in other areas for the new subRenameFrom and I keep getting "rename failed with error: 5".
0
 
Gabriel CliftonNet AdminAuthor Commented:
I do not know how, but somehow it started working reliably. So how can I get this to make sure the computer is on before it attempts the rename. If I select all computers and one of them happens to be off, when the script gets to that computer it fails and crashes. Also, I desperately would like for it to wait for the computers to come back up and if the computer is in the correct OU (which I have a script that automatically moves the computers on the 0s and 5s of every hour), force a gpupdate and reboot similar to what I am already doing in my batch file. This would be the final piece to ensure my techs can run this without any intervention from me and allow the techs to run this before they leave for the day prior to the day of testing and they would not have to touch the computers.
0
 
RobSampsonCommented:
Ok sounds like it's coming together. Post your current code again so we're working off the same version again.

One thing about not logging anymore is that we are not capturing the original OU the computer came from. Does that matter, or will your OU moving task put it in the right place with the naming conventions anyway (both to and from)?

In terms of not crashing when a computer is off, that's easy enough, I can add that.

As far as making sure gpupdate is run, we need to think about how we will determine when the computer gets moved to the correct OU. I guess your OU Move script has all that logic, but I don't think we would want to duplicate all that.  After a rename, what do you think would be the easiest way to determine when the computer is in the right OU before we run gpupdate?

Rob.
0
 
Gabriel CliftonNet AdminAuthor Commented:
As far as posing the new code, I have already left work for the day. I will get that up tomorrow. As far as the OU and gpupdate, we could wait for the last computer to be renamed to come back up, call the vbs that moves the computers, gpupdate /force on all computers that had their name changed, reboot. Here is something I was thinking about on my way home today that would be a nice addition, but not necessary. On naming computers for testing, at the end shut down all computers in ou that were not renamed. That way when the testing proctor would know which computers are to be used and not used.
0
 
RobSampsonCommented:
Yeah, that's not a bad idea, but maybe rather than call the VBS that moves computers (in case the running of each causes a conflict), knowing that the script runs every five minutes, we could have the HTA wait five minutes and then run gpupdate and reboot.  I know initially that five minutes will seem like an eternity, but in the long run, the "lite-touch" approach will save time.

Shutting down the other PCs in the OU that were not selected for rename won't be difficult either.

If you think that would work, we can work on that.

Rob.
0
 
Gabriel CliftonNet AdminAuthor Commented:
Here is what I have, I did add the Sub RenameSinglePCFrom section when I was testing it and could not get it to work, I just left it there. I am also having an issue with rename back if there is only one computer that has been changed to testing naming scheme. I will get:
Line: 353
Column: 2
Error: Object doesn't support this property or method: 'checknum2.length'
Code: 800A01B6

Now, most of the time I will not have only one computer renamed for testing in any lab simply because I like to have backup systems, but occasionally I will.

<html> 
<head> 
<title>Rename Computer Labs for state testing</title> 

<HTA:Application 
ID = "HTA" 
ApplicationName = "RenLab" 
Border = "dialog" 
BorderStyle = "normal" 
Caption = "yes" 
ContextMenu="yes" 
ICON="\\Server\Share\panther.ICO"
InnerBorder="no" 
MaximizeButton = "no" 
MinimizeButton = "no" 
Navigable="yes" 
Scroll="yes" 
SrollFlat="no" 
Selection="yes" 
ShowInTaskBar = "yes" 
SingleInstance = "yes" 
SysMenu = "yes" 
Version = "1.0" 
> 
<style>
.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; 
} 
.tabsNotSelected { 
background-color: wheat; 
border: solid 1px black; 
} 
.tabsSelected { 
background-color: white; 
border-color: black black white black; 
border-style: solid solid solid solid; 
border-width: 1px 1px 1px 1px; 
} 
</style>
<script language="VBscript"> 
Dim sItem 
Dim aPanels 
Dim el 
Dim iPanelCount 
iPanelCount = 2
Dim intColCount
intColCount = 4

Sub Window_OnLoad

	ElevatedCheck
	width = "750"
	height = "750"
	' 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 
	
	'Original OU
	AddRenameToOption selRenameTo, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,dc=local|TESTNAVAL1-YYYY"
	AddRenameToOption selRenameTo, "Alamo D01 2-3 Lab", "OU=Alamo Room D01 Student,OU=RM D01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,dc=local|TESTNAVAL2-YYYY"
	
	AddRenameToOption selRenameTo, "Apache Room 006 Lab", "OU=Apache Lab Room 006 Student,OU=RM 06 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,dc=local|TESTNAVAP1-YYYY"
	AddRenameToOption selRenameTo, "Apache Room 017 Lab", "OU=Apache Lab Room 017 Student,OU=Apache Lab Room 017,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,dc=local|TESTNAVAP2-YYYY"
	AddRenameToOption selRenameTo, "Apache Room 326 Lab", "OU=Apache Lab Room 326 Student,OU=RM 326 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,dc=local|TESTNAVAP3-YYYY"
	
	AddRenameToOption selRenameTo, "Intermediate Room 001 Lab", "OU=Intermediate Lab Room 001 Student,OU=RM 01 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN1-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Room 012 Lab", "OU=Intermediate Lab Room 012 Student,OU=RM 12 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN2-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Room 027 Lab", "OU=Intermediate Lab Room 027 Student,OU=RM 27 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN3-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Room 028 Lab", "OU=Intermediate Lab Room 028 Student,OU=RM 28 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN4-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Mobile Lab", "OU=Mobile Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN5-YYYY"
	
	AddRenameToOption selRenameTo, "Middle School Room 110 Lab", "OU=Middle School 110 Lab Student,OU=RM 110 Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS1-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 111 Lab", "OU=Middle School 111 Lab Student,OU=RM 111 Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS2-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 118 Lab", "OU=Middle School Math Lab Student,OU=RM 118 Math Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS3-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 125 Lab", "OU=Middle School Science Lab Student,OU=RM 125 Science Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS4-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 126 Lab", "OU=Middle School Robotics Lab Student,OU=RM 126 Robotics Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS5-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 127 Lab", "OU=Middle School Spec-Ed Lab Student,OU=RM 127 Spec-Ed Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS6-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 130 Lab", "OU=Middle School Reading Lab Teacher,OU=RM 130 Reading Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS7-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 141 Lab", "OU=Student,OU=RM 141 Mobile Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS8-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room GCS Lab", "OU=Middle School GCS Lab Student,OU=RM GCS Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS9-YYYY"
	
	AddRenameToOption selRenameTo, "High School Room 11 Lab", "OU=HS Lab Room 11 Student,OU=RM 11 Panther Den Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS1-YYYY"
	AddRenameToOption selRenameTo, "High School Room 12 Lab", "OU=HS Lab Room 12 Student,OU=RM 12 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS2-YYYY"
	AddRenameToOption selRenameTo, "High School Room 13 Lab", "OU=High School Room 013 Student,OU=Rm 013 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS3-YYYY"
	AddRenameToOption selRenameTo, "High School Room 47 Lab", "OU=HS Lab Room 47 Student,OU=RM 47 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS6-YYYY"
	AddRenameToOption selRenameTo, "High School Room 48 Lab", "OU=HS Lab Room 48 Student,OU=RM 48 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS4-YYYY"
	AddRenameToOption selRenameTo, "High School Room 148 Lab", "OU=HS GCS Lab Student,OU=RM GCS Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS5-YYYY"
	AddRenameToOption selRenameTo, "High School Room 149 Lab", "OU=HS GCS Lab Student,OU=RM GCS Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS7-YYYY"
	
	AddRenameToOption selRenameTo, "Technology East Lab", "OU=East Computers,OU=East Lab,OU=Training Lab,OU=Technology Center,OU=Locations,DC=domain,dc=local|TESTNAVTC1-YYYY"
	AddRenameToOption selRenameTo, "Technology West Lab", "OU=West Computers,OU=West Lab,OU=Training Lab,OU=Technology Center,OU=Locations,DC=domain,dc=local|TESTNAVTC2-YYYY"
	
	'Testing OU
	AddRenameToOption selRenameFrom, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameFrom, "Alamo C01 K-1 Lab", "OU=Alamo,OU=TESTNAV,DC=domain,dc=local|ALRMC01YYYY"
	AddRenameToOption selRenameFrom, "Alamo D01 2-3 Lab", "OU=Alamo,OU=TESTNAV,DC=domain,dc=local|ALRMD01YYYY"
	
	AddRenameToOption selRenameFrom, "Apache Room 006 Lab", "OU=Apache,OU=TESTNAV,DC=domain,dc=local|APRM006YYYY"
	AddRenameToOption selRenameFrom, "Apache Room 017 Lab", "OU=Apache,OU=TESTNAV,DC=domain,dc=local|APRM017YYYY"
	AddRenameToOption selRenameFrom, "Apache Room 326 Lab", "OU=Apache,OU=TESTNAV,DC=domain,dc=local|APRM326YYYY"
	
	AddRenameToOption selRenameFrom, "Intermediate Room 001 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM001YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Room 012 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM012YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Room 027 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM027YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Room 028 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM028YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Mobile Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INML001YYYY"
	
	AddRenameToOption selRenameFrom, "Middle School Room 110 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM110YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 111 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM111YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 118 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM118YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 125 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM125YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 126 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM126YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 127 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM127YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 130 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM130YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 141 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM141YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 148 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM148YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 149 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM149YYYY"
	
	AddRenameToOption selRenameFrom, "High School Room 11 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM011YYYY"
	AddRenameToOption selRenameFrom, "High School Room 12 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM012YYYY"
	AddRenameToOption selRenameFrom, "High School Room 13 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM013YYYY"
	AddRenameToOption selRenameFrom, "High School Room 47 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM047YYYY"
	AddRenameToOption selRenameFrom, "High School Room 48 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM048YYYY"
	AddRenameToOption selRenameFrom, "High School GCS Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRMGCSYYYY"
	
	AddRenameToOption selRenameFrom, "Technology East Lab", "OU=Technology,OU=TESTNAV,DC=domain,dc=local|TCLATLEYYYY"
	AddRenameToOption selRenameFrom, "Technology West Lab", "OU=Technology,OU=TESTNAV,DC=domain,dc=local|TCLATLWYYYY"
End Sub

Sub ElevatedCheck
	'Source: http://www.thegbach.com/elevatedHta.html
	Set objShell = CreateObject("WScript.Shell")
	Set objShellApp = CreateObject("Shell.Application")
	strElevated = False
	strHTADir = document.location.pathname
	Set objWhoami = objShell.Exec("whoami /groups")
	strWhoami = objWhoami.StdOut.ReadAll
	If InStr(1, strWhoami,"S-1-16-12288",vbTextCompare) Then
	strElevated = True
	Else
		objShellApp.ShellExecute"mshta.exe",Chr(34) & strHTADir & Chr(34) & " runasadministrator","","runas",1
		window.close()
	End If 
End Sub

SUB Check_M_All(checkNum) 
   ON ERROR RESUME NEXT 
       checkNum.Checked = TRUE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.length - 1 
               checkNum(i).checked = TRUE 
           Next 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
 SUB Uncheck_M_All(checkNum)
   ON ERROR RESUME NEXT 
       checkNum.Checked = FALSE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.Length - 1 
               checkNum(i).Checked = FALSE 
           NEXT 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
Private Sub Panel(tab) 
	For i = 1 To iPanelCount 
		If i = tab Then 
			document.getElementById("tab" & i).className = "tabs tabsSelected" 
			document.getElementById("panel" & i).style.display = "block" 
		Else 
			document.getElementById("tab" & i).className = "tabs tabsNotSelected" 
			document.getElementById("panel" & i).style.display = "none" 
		End If 
	Next 
End Sub 

Sub AddRenameToOption(objObject, strText, strValue)
	Set objOption = Document.CreateElement("OPTION")
	objOption.Text = strText
	objOption.Value = strValue
	objObject.Add(objOption)
End Sub

'Tab 1
Sub TestSub
	strText = selRenameTo.Item(selRenameTo.SelectedIndex).Text
	strValue = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Value, "|")(0)
	strNaming = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Value, "|")(1)
	'MsgBox strText & vbCrLf & strValue
	Set objOU = GetObject("LDAP://" & strValue)
	strNames = ""
	intCol = 0
	strNames = "<table cellspacing=10 cellpadding=0 border=0>"
	For Each objObject In objOU
		If objObject.class = "computer" Then
			strCheckBoxCode = ""
			If intCol = 0 Then
				strCheckBoxCode = "<tr>"
			End If
			strCheckBoxCode = strCheckBoxCode & "<td><font color=""white""><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum"" value=""" & objObject.distinguishedName & "|" & strNaming & """>" & Mid(objObject.Name, 4) & "</font></td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode = strCheckBoxCode & "</tr>"
				intCol = 0
			End If
			If strNames = "" Then
				strNames = strCheckBoxCode
			Else
				strNames = strNames & vbCrLf & strCheckBoxCode
			End If
		End If
	Next
	strNames = strNames & vbCrLf & "</table>"
    instPath.InnerHTML = strNames
End Sub

'Tab 2
Sub TestSub2
	strText2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Text
	strValue2 = Split(selRenameFrom.Item(selRenameFrom.SelectedIndex).Value, "|")(0)
	strNaming2 = Split(selRenameFrom.Item(selRenameFrom.SelectedIndex).Value, "|")(1)
'	MsgBox strText2 & vbCrLf & strValue2
	Set objOU2 = GetObject("LDAP://" & strValue2)
	strNames2 = ""
	intCol = 0
	strNames2 = "<table cellspacing=10 cellpadding=0 border=0>"
	For Each objObject In objOU2
		If objObject.class = "computer" Then
			strCheckBoxCode2 = ""
			If intCol = 0 Then
				strCheckBoxCode2 = "<tr>"
			End If
			strCheckBoxCode2 = strCheckBoxCode2 & "<td><font color=""white""><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum2"" value=""" & objObject.distinguishedName & "|" & strNaming2 & """>" & Mid(objObject.Name, 4) & "</font></td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode2 = strCheckBoxCode2 & "</tr>"
				intCol = 0
			End If
			If strNames2 = "" Then
				strNames2 = strCheckBoxCode2
			Else
				strNames2 = strNames2 & vbCrLf & strCheckBoxCode2
			End If
		End If
	Next
	strNames2 = strNames2 & vbCrLf & "</table>"
    instPath2.InnerHTML = strNames2
End Sub

Sub RenameTo(checknum)
	FOR i = 0 TO checkNum.length - 1 
		If checknum(i).checked = True Then
			'MsgBox "Renaming " & checknum(i).id & vbCrLf& checknum(i).value & vbCrLf & " to " & strNewComputer
			strComputer = checknum(i).id
			strDN = Split(checknum(i).value, "|")(0)
			strParentOU = Split(Mid(checknum(i).value,INSTR(checknum(i).value,",")+1,LEN(checknum(i).value)-INSTR(checknum(i).value,",")), "|")(0)
			strNamingConvention = Split(Mid(checknum(i).value,INSTR(checknum(i).value,",")+1,LEN(checknum(i).value)-INSTR(checknum(i).value,",")), "|")(1)
'			MsgBox "1. " & strComputer & vbCrLf & "2. " & strDN & vbCrLf & "3. " & strParentOU & vbCrLf & "3. " & strNamingConvention
			Call RenameSinglePCTo(strComputer, strParentOU, strNamingConvention)
		End If
	Next
End Sub

Sub RenameSinglePCTo(strComputer, strOU, strConvention)
	strDomainUser = document.getElementById("uName").value & "@domain.local"
	strDomainPasswd = document.getElementById("uPassword").value
	strLocalUser = strComputer & "\administrator"
	strLocalPasswd = "password" 
	arrLabParts = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Text, " ")
       'strNewComputer = "TESTNAV" & Left(selRenameTo.Item(selRenameTo.SelectedIndex).Text, 2) & arrLabParts(UBound(arrLabParts) - 1) & "-" & Right(strComputer, 4)
    strNewComputer = Replace(strConvention, "YYYY", Right(strComputer, 4))
'	MsgBox strNewComputer
	'Exit Sub
	'########################### 
	' Connect to Computer 
	'###########################
	Dim objWMILocator, objWMIComputer, objWMIComputerSystem, rc, objWMIService, colOperatingSystems, objOperatingSystem, objNetwork, objComputer
	Set objNetwork = CreateObject("WScript.Network")
	'Set objWMIComputer = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd) 
	'Set objWMIComputerSystem = objWMIComputer.Get( "Win32_ComputerSystem.Name='" & strComputer & "'") 
	If LCase(strComputer) = LCase(objNetwork.ComputerName) Then
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, authenticationLevel=pktPrivacy, (Shutdown)}!\\" & strComputer & "\root\cimv2") 
	Else
		Set objWMILocator = CreateObject("WbemScripting.SWbemLocator") 
		objWMILocator.Security_.AuthenticationLevel = 6 
		Set objWMIService = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd)
	End If
	'########################### 
	' Rename Computer 
	'########################### 
	Set objWMIComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem Where Name='" & strComputer & "'")
	For Each objWMIComputerSystem In objWMIComputer
		' There will only ever be one element in this collection
		rc = objWMIComputerSystem.Rename(strNewComputer, strDomainPasswd, strDomainUser) 
		if rc <> 0 then 
			Msgbox "Rename failed with error: " & rc 
		else 
			Msgbox "Successfully renamed " & strComputer & " to " & strNewComputer
			'########################### 
			' Place text files on the CURRENT computer that you are running this management from
			'###########################
			Set objFSO = CreateObject("Scripting.FileSystemObject")
			strLogFolder = "C:\PCs_Renamed\"
			If objFSO.FolderExists(strLogFolder) = False Then objFSO.CreateTextFile strLogFolder
			Set objFile = objFSO.CreateTextFile(strLogFolder & strNewComputer & ".txt", True)
			objFile.Write strComputer & ";" & strOU
			objFile.Close
			'########################### 
			' Reboot computer
			'###########################
			'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("RenameFrom").disabled = True
  document.GetElementByID("RenameTo").disabled = true
end Sub

Sub RenameFrom(checknum2)
	For i = 0 TO checkNum2.Length - 1 
		If checknum2(i).checked = True Then
'			MsgBox "Renaming " & checknum2(i).id & vbCrLf& checknum2(i).value & vbCrLf & " to " & strNewComputer
			strComputer2 = checknum2(i).id
			strDN2 = Split(checknum2(i).value, "|")(0)
			strParentOU2 = Split(Mid(checknum2(i).value,INSTR(checknum2(i).value,",")+1,LEN(checknum2(i).value)-INSTR(checknum2(i).value,",")), "|")(0)
			strNamingConvention2 = Split(Mid(checknum2(i).value,INSTR(checknum2(i).value,",")+1,LEN(checknum2(i).value)-INSTR(checknum2(i).value,",")), "|")(1)
'			MsgBox "1. " & strComputer2 & vbCrLf & "2. " & strDN2 & vbCrLf & "3. " & strParentOU2 & vbCrLf & "4. " & strNamingConvention2
			Call RenameSinglePCFrom(strComputer2, strParentOU2, strNamingConvention2)
		End If
	Next
End Sub

Sub RenameSinglePCFrom(strComputer2, strOU2, strConvention2)
	strDomainUser2 = document.getElementById("uName").value & "@domain.local"
	strDomainPasswd2 = document.getElementById("uPassword").value
	strLocalUser2 = strComputer2 & "\administrator"
	strLocalPasswd2 = "password" 
	arrLabParts2 = Split(selRenameFrom.Item(selRenameFrom.SelectedIndex).Text, " ")
       'strNewComputer = "TESTNAV" & Left(selRenameTo.Item(selRenameTo.SelectedIndex).Text, 2) & arrLabParts(UBound(arrLabParts) - 1) & "-" & Right(strComputer, 4)
    strNewComputer2 = Replace(strConvention2, "YYYY", Right(strComputer2, 4))
    strNewComputer3 = Chr(34) & strNewComputer2 & Chr(34)
'	MsgBox strNewComputer2
	'Exit Sub
	'########################### 
	' Connect to Computer 
	'###########################
	Dim objWMILocator, objWMIComputer, objWMIComputerSystem, rc, objWMIService, colOperatingSystems, objOperatingSystem, objNetwork, objComputer
	Set objNetwork = CreateObject("WScript.Network")
	'Set objWMIComputer = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd) 
	'Set objWMIComputerSystem = objWMIComputer.Get( "Win32_ComputerSystem.Name='" & strComputer & "'") 
	If LCase(strComputer2) = LCase(objNetwork.ComputerName) Then
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, authenticationLevel=pktPrivacy, (Shutdown)}!\\" & strComputer2 & "\root\cimv2") 
	Else
		Set objWMILocator = CreateObject("WbemScripting.SWbemLocator") 
		objWMILocator.Security_.AuthenticationLevel = 6 
		Set objWMIService = objWMILocator.ConnectServer(strComputer2, "root\cimv2", strLocalUser2, strLocalPasswd2)
	End If
	'########################### 
	' Rename Computer 
	'########################### 
	Set objWMIComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem Where Name='" & strComputer2 & "'")
	For Each objWMIComputerSystem In objWMIComputer
		' There will only ever be one element in this collection
		rc = objWMIComputerSystem.Rename(strNewComputer2, strDomainPasswd2, strDomainUser2) 
		if rc <> 0 then 
			Msgbox "Rename failed with error: " & rc 
		else 
			Msgbox "Successfully renamed " & strComputer2 & " to " & strNewComputer2
			'########################### 
			' Place text files on the CURRENT computer that you are running this management from
			'###########################
			Set objFSO = CreateObject("Scripting.FileSystemObject")
			strLogFolder = "C:\PCs_Renamed\"
			If objFSO.FolderExists(strLogFolder) = False Then objFSO.CreateTextFile strLogFolder
			Set objFile = objFSO.CreateTextFile(strLogFolder & strNewComputer2 & ".txt", True)
			objFile.Write strComputer2 & ";" & strOU2
			objFile.Close
			'########################### 
			' Reboot computer
			'###########################
			'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("RenameFrom").disabled = True
  document.GetElementByID("RenameTo").disabled = true
end Sub

</script> 

</head> 


<body bgcolor="blue"> 
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650"> 
<tr valign="top"> 
<td colspan="2"> 
<span class="tabs tabsSelected" id="tab1" onclick="panel(1)">Rename Computers for Testing</span> 
<span class="tabs tabsNotSelected" id="tab2" onclick="panel(2)">Rename Computers back from Testing</span>
<!-- Tab 1 -->
<div class="panel" id="panel1" style="display:block"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<td style="text-align:right;font-size:0.9em;font-weight:bold;font-style:oblique;color:#888888;">
				Created by Gabriel Clifton
			</td>
		</tr>
	</table>
<!--Add your controls here-->
<select size="1" onChange="TestSub" name="selRenameTo" id="selRenameTo"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll" value="Check All" onclick="Check_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="uchckAll" value="Un-Check All" onclick="UNCheck_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="RenameTo" value="Rename To" onclick="RenameTo(document.myform.checkNum)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform" method="post">
            <span  id="instPath"></span>
        </font></form>
    </TH>
    </tr>
 </table>
  <table>
 	<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>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

<!-- Tab 2 -->
<div class="panel" id="panel2" style="display:none"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<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>

<!--Add your controls here-->
<select size="1" onChange="TestSub2" name="selRenameFrom" id="selRenameFrom"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename back</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll2" value="Check All" onclick="Check_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="uchckAll2" value="Un-Check All" onclick="Uncheck_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="RenameFrom" value="Rename From" onclick="RenameFrom(document.myform2.checkNum2)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform2" method="post">
            <span  id="instPath2"></span>
        </font></form>
    </TH>
    </tr>
 </table>
 <table>
 	<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>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

</body> 
</html> 

Open in new window

0
 
RobSampsonCommented:
Hi again,

Sorry for the late response.  Things are hectic at work again!

So, at this point I must stress that I have not tested this fully because I do not have a test lab structure that allows me to check the functionality fully.

I strongly suggest that you run this against an OU that has only a few machines that you can test with.

Right now I have only completed the RenameTo side of things, and here's what it *should* be doing:

When you click RenameTo, you will be asked if you want to shut down non-selected computers that are displayed.

If you click Yes, any computer on that page that is not selected will have
     cmd /c shutdown /s /t 00 /m <ComputerName>
run against it. If you click No, no computers will be shut down.

For any computers that were selected, they will be renamed according to the naming convention specified.  After each PC has had the rename command issued, the program will wait for five minutes before continuing.

After that time, each PC that was originally selected will have the following command run against them:
     PSExec -accepteula \\<ComputerName> gpupdate /force
Note: This requires that PSExec.exe is placed in the same folder as the HTA
And then they will have the following command run against them:
     shutdown /r /t 00 /m <ComputerName>

After all of that, computers should be renamed, and during the five minutes, moved to the correct OU by your externally scheduled script, have GPUpdate run on them, and rebooted.

If that all works, I can transfer that over to the RenameFrom procedures.

Regards,

Rob.


<html> 
<head> 
<title>Rename Computer Labs for state testing</title> 

<HTA:Application 
ID = "HTA" 
ApplicationName = "RenLab" 
Border = "dialog" 
BorderStyle = "normal" 
Caption = "yes" 
ContextMenu="yes" 
ICON="\\Server\Share\panther.ICO"
InnerBorder="no" 
MaximizeButton = "no" 
MinimizeButton = "no" 
Navigable="yes" 
Scroll="yes" 
SrollFlat="no" 
Selection="yes" 
ShowInTaskBar = "yes" 
SingleInstance = "yes" 
SysMenu = "yes" 
Version = "1.0" 
> 
<style>
.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; 
} 
.tabsNotSelected { 
background-color: wheat; 
border: solid 1px black; 
} 
.tabsSelected { 
background-color: white; 
border-color: black black white black; 
border-style: solid solid solid solid; 
border-width: 1px 1px 1px 1px; 
} 
</style>
<script language="VBscript"> 
Dim sItem 
Dim aPanels 
Dim el 
Dim iPanelCount 
iPanelCount = 2
Dim intColCount
intColCount = 4
Dim strHTAPath

Sub Window_OnLoad

	ElevatedCheck
	width = "750"
	height = "750"
	' 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 
	
    If Mid(document.location, 6, 3) = "///" Then
    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)
    Else
    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)
    End If
		    
	'Original OU
	AddRenameToOption selRenameTo, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,dc=local|TESTNAVAL1-YYYY"
	AddRenameToOption selRenameTo, "Alamo D01 2-3 Lab", "OU=Alamo Room D01 Student,OU=RM D01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,dc=local|TESTNAVAL2-YYYY"
	
	AddRenameToOption selRenameTo, "Apache Room 006 Lab", "OU=Apache Lab Room 006 Student,OU=RM 06 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,dc=local|TESTNAVAP1-YYYY"
	AddRenameToOption selRenameTo, "Apache Room 017 Lab", "OU=Apache Lab Room 017 Student,OU=Apache Lab Room 017,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,dc=local|TESTNAVAP2-YYYY"
	AddRenameToOption selRenameTo, "Apache Room 326 Lab", "OU=Apache Lab Room 326 Student,OU=RM 326 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,dc=local|TESTNAVAP3-YYYY"
	
	AddRenameToOption selRenameTo, "Intermediate Room 001 Lab", "OU=Intermediate Lab Room 001 Student,OU=RM 01 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN1-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Room 012 Lab", "OU=Intermediate Lab Room 012 Student,OU=RM 12 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN2-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Room 027 Lab", "OU=Intermediate Lab Room 027 Student,OU=RM 27 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN3-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Room 028 Lab", "OU=Intermediate Lab Room 028 Student,OU=RM 28 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN4-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Mobile Lab", "OU=Mobile Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN5-YYYY"
	
	AddRenameToOption selRenameTo, "Middle School Room 110 Lab", "OU=Middle School 110 Lab Student,OU=RM 110 Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS1-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 111 Lab", "OU=Middle School 111 Lab Student,OU=RM 111 Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS2-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 118 Lab", "OU=Middle School Math Lab Student,OU=RM 118 Math Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS3-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 125 Lab", "OU=Middle School Science Lab Student,OU=RM 125 Science Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS4-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 126 Lab", "OU=Middle School Robotics Lab Student,OU=RM 126 Robotics Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS5-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 127 Lab", "OU=Middle School Spec-Ed Lab Student,OU=RM 127 Spec-Ed Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS6-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 130 Lab", "OU=Middle School Reading Lab Teacher,OU=RM 130 Reading Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS7-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 141 Lab", "OU=Student,OU=RM 141 Mobile Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS8-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room GCS Lab", "OU=Middle School GCS Lab Student,OU=RM GCS Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS9-YYYY"
	
	AddRenameToOption selRenameTo, "High School Room 11 Lab", "OU=HS Lab Room 11 Student,OU=RM 11 Panther Den Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS1-YYYY"
	AddRenameToOption selRenameTo, "High School Room 12 Lab", "OU=HS Lab Room 12 Student,OU=RM 12 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS2-YYYY"
	AddRenameToOption selRenameTo, "High School Room 13 Lab", "OU=High School Room 013 Student,OU=Rm 013 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS3-YYYY"
	AddRenameToOption selRenameTo, "High School Room 47 Lab", "OU=HS Lab Room 47 Student,OU=RM 47 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS6-YYYY"
	AddRenameToOption selRenameTo, "High School Room 48 Lab", "OU=HS Lab Room 48 Student,OU=RM 48 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS4-YYYY"
	AddRenameToOption selRenameTo, "High School Room 148 Lab", "OU=HS GCS Lab Student,OU=RM GCS Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS5-YYYY"
	AddRenameToOption selRenameTo, "High School Room 149 Lab", "OU=HS GCS Lab Student,OU=RM GCS Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS7-YYYY"
	
	AddRenameToOption selRenameTo, "Technology East Lab", "OU=East Computers,OU=East Lab,OU=Training Lab,OU=Technology Center,OU=Locations,DC=domain,dc=local|TESTNAVTC1-YYYY"
	AddRenameToOption selRenameTo, "Technology West Lab", "OU=West Computers,OU=West Lab,OU=Training Lab,OU=Technology Center,OU=Locations,DC=domain,dc=local|TESTNAVTC2-YYYY"
	
	'Testing OU
	AddRenameToOption selRenameFrom, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameFrom, "Alamo C01 K-1 Lab", "OU=Alamo,OU=TESTNAV,DC=domain,dc=local|ALRMC01YYYY"
	AddRenameToOption selRenameFrom, "Alamo D01 2-3 Lab", "OU=Alamo,OU=TESTNAV,DC=domain,dc=local|ALRMD01YYYY"
	
	AddRenameToOption selRenameFrom, "Apache Room 006 Lab", "OU=Apache,OU=TESTNAV,DC=domain,dc=local|APRM006YYYY"
	AddRenameToOption selRenameFrom, "Apache Room 017 Lab", "OU=Apache,OU=TESTNAV,DC=domain,dc=local|APRM017YYYY"
	AddRenameToOption selRenameFrom, "Apache Room 326 Lab", "OU=Apache,OU=TESTNAV,DC=domain,dc=local|APRM326YYYY"
	
	AddRenameToOption selRenameFrom, "Intermediate Room 001 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM001YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Room 012 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM012YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Room 027 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM027YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Room 028 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM028YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Mobile Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INML001YYYY"
	
	AddRenameToOption selRenameFrom, "Middle School Room 110 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM110YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 111 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM111YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 118 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM118YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 125 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM125YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 126 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM126YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 127 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM127YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 130 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM130YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 141 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM141YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 148 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM148YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 149 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM149YYYY"
	
	AddRenameToOption selRenameFrom, "High School Room 11 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM011YYYY"
	AddRenameToOption selRenameFrom, "High School Room 12 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM012YYYY"
	AddRenameToOption selRenameFrom, "High School Room 13 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM013YYYY"
	AddRenameToOption selRenameFrom, "High School Room 47 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM047YYYY"
	AddRenameToOption selRenameFrom, "High School Room 48 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM048YYYY"
	AddRenameToOption selRenameFrom, "High School GCS Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRMGCSYYYY"
	
	AddRenameToOption selRenameFrom, "Technology East Lab", "OU=Technology,OU=TESTNAV,DC=domain,dc=local|TCLATLEYYYY"
	AddRenameToOption selRenameFrom, "Technology West Lab", "OU=Technology,OU=TESTNAV,DC=domain,dc=local|TCLATLWYYYY"
End Sub

Sub ElevatedCheck
	'Source: http://www.thegbach.com/elevatedHta.html
	Set objShell = CreateObject("WScript.Shell")
	Set objShellApp = CreateObject("Shell.Application")
	strElevated = False
	strHTADir = document.location.pathname
	Set objWhoami = objShell.Exec("whoami /groups")
	strWhoami = objWhoami.StdOut.ReadAll
	If InStr(1, strWhoami,"S-1-16-12288",vbTextCompare) Then
	strElevated = True
	Else
		objShellApp.ShellExecute"mshta.exe",Chr(34) & strHTADir & Chr(34) & " runasadministrator","","runas",1
		window.close()
	End If 
End Sub

SUB Check_M_All(checkNum) 
   ON ERROR RESUME NEXT 
       checkNum.Checked = TRUE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.length - 1 
               checkNum(i).checked = TRUE 
           Next 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
 SUB Uncheck_M_All(checkNum)
   ON ERROR RESUME NEXT 
       checkNum.Checked = FALSE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.Length - 1 
               checkNum(i).Checked = FALSE 
           NEXT 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
Private Sub Panel(tab) 
	For i = 1 To iPanelCount 
		If i = tab Then 
			document.getElementById("tab" & i).className = "tabs tabsSelected" 
			document.getElementById("panel" & i).style.display = "block" 
		Else 
			document.getElementById("tab" & i).className = "tabs tabsNotSelected" 
			document.getElementById("panel" & i).style.display = "none" 
		End If 
	Next 
End Sub 

Sub AddRenameToOption(objObject, strText, strValue)
	Set objOption = Document.CreateElement("OPTION")
	objOption.Text = strText
	objOption.Value = strValue
	objObject.Add(objOption)
End Sub

'Tab 1
Sub TestSub
	strText = selRenameTo.Item(selRenameTo.SelectedIndex).Text
	strValue = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Value, "|")(0)
	strNaming = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Value, "|")(1)
	'MsgBox strText & vbCrLf & strValue
	Set objOU = GetObject("LDAP://" & strValue)
	strNames = ""
	intCol = 0
	strNames = "<table cellspacing=10 cellpadding=0 border=0>"
	For Each objObject In objOU
		If objObject.class = "computer" Then
			strCheckBoxCode = ""
			If intCol = 0 Then
				strCheckBoxCode = "<tr>"
			End If
			strCheckBoxCode = strCheckBoxCode & "<td><font color=""white""><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum"" value=""" & objObject.distinguishedName & "|" & strNaming & """>" & Mid(objObject.Name, 4) & "</font></td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode = strCheckBoxCode & "</tr>"
				intCol = 0
			End If
			If strNames = "" Then
				strNames = strCheckBoxCode
			Else
				strNames = strNames & vbCrLf & strCheckBoxCode
			End If
		End If
	Next
	strNames = strNames & vbCrLf & "</table>"
    instPath.InnerHTML = strNames
End Sub

'Tab 2
Sub TestSub2
	strText2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Text
	strValue2 = Split(selRenameFrom.Item(selRenameFrom.SelectedIndex).Value, "|")(0)
	strNaming2 = Split(selRenameFrom.Item(selRenameFrom.SelectedIndex).Value, "|")(1)
'	MsgBox strText2 & vbCrLf & strValue2
	Set objOU2 = GetObject("LDAP://" & strValue2)
	strNames2 = ""
	intCol = 0
	strNames2 = "<table cellspacing=10 cellpadding=0 border=0>"
	For Each objObject In objOU2
		If objObject.class = "computer" Then
			strCheckBoxCode2 = ""
			If intCol = 0 Then
				strCheckBoxCode2 = "<tr>"
			End If
			strCheckBoxCode2 = strCheckBoxCode2 & "<td><font color=""white""><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum2"" value=""" & objObject.distinguishedName & "|" & strNaming2 & """>" & Mid(objObject.Name, 4) & "</font></td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode2 = strCheckBoxCode2 & "</tr>"
				intCol = 0
			End If
			If strNames2 = "" Then
				strNames2 = strCheckBoxCode2
			Else
				strNames2 = strNames2 & vbCrLf & strCheckBoxCode2
			End If
		End If
	Next
	strNames2 = strNames2 & vbCrLf & "</table>"
    instPath2.InnerHTML = strNames2
End Sub

Sub RenameTo(checknum)
	Set objShell = CreateObject("WScript.Shell")
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	blnComputerRenamed = False
	Set dctToRename = CreateObject("Scripting.Dictionary")
	dctToRename.CompareMode = vbTextCompare
	blnShutdown = MsgBox("Do you want to shut down non-selected computers in this OU?", vbYesNo, "Shutdown computers?")
	FOR i = 0 TO checkNum.length - 1 
		If checknum(i).checked = True Then
			'MsgBox "Renaming " & checknum(i).id & vbCrLf& checknum(i).value & vbCrLf & " to " & strNewComputer
			strComputer = checknum(i).id
			strDN = Split(checknum(i).value, "|")(0)
			strParentOU = Split(Mid(checknum(i).value,INSTR(checknum(i).value,",")+1,LEN(checknum(i).value)-INSTR(checknum(i).value,",")), "|")(0)
			strNamingConvention = Split(Mid(checknum(i).value,INSTR(checknum(i).value,",")+1,LEN(checknum(i).value)-INSTR(checknum(i).value,",")), "|")(1)
			If Ping(strComputer) = True Then
				MsgBox "1. " & strComputer & vbCrLf & "2. " & strDN & vbCrLf & "3. " & strParentOU & vbCrLf & "3. " & strNamingConvention
				Call RenameSinglePC(strComputer, strParentOU, strNamingConvention)
				blnComputerRenamed = True
				dctToRename.Add strComputer, 0
			Else
				objShell.Popup strComputer & " is not online.  Cannot rename computer.", 2, strComputer & " not online"
				checknum(i).checked = False
			End If
		Else
			If blnShutdown = vbYes Then
				objShell.Popup "Shutting down " & checknum(i).id, 1, checknum(i).id
				objShell.Run "cmd /c shutdown /s /t 00 /m " & checknum(i).id
			End If
		End If
	Next
	If blnComputerRenamed = True Then
		dteEndTime = DateAdd("s", 300, Now)
		While DateDiff("s", Now, dteEndTime) > 0
			intWait = DateDiff("s", Now, dteEndTime)
			If DateDiff("s", Now, dteEndTime) > 30 Then intWait = 30
			objShell.Popup "Waiting " & DateDiff("s", Now, dteEndTime) & " seconds.", intWait, "Waiting for computers to be placed in the correct OU..."
		Wend
		strPSExec = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "PSExec.exe"
		If objFSO.FileExists(strPSExec) = True Then
			For Each strPC In dctToRename
				objShell.Popup "Running gpupdate on " & strPC, 1, "GPUpdate on " & strPC
				objShell.Run "cmd /c " & objFSO.GetFile(strPSExec).ShortPath & " -accepteula \\" & checknum(i).id & " gpupdate /force", 0, True
				objShell.Run "cmd /c shutdown /r /t 00 /m " & checknum(i).id
			Next
		Else
			MsgBox "Unable to find " & strPSExec & " to run GPUpdate"
		End If
	End If
End Sub

Sub RenameSinglePC(strComputer, strOU, strConvention)
	strDomainUser = document.getElementById("uName").value & "@domain.local"
	strDomainPasswd = document.getElementById("uPassword").value
	strLocalUser = strComputer & "\administrator"
	strLocalPasswd = "password" 
	arrLabParts = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Text, " ")
       'strNewComputer = "TESTNAV" & Left(selRenameTo.Item(selRenameTo.SelectedIndex).Text, 2) & arrLabParts(UBound(arrLabParts) - 1) & "-" & Right(strComputer, 4)
    strNewComputer = Replace(strConvention, "YYYY", Right(strComputer, 4))
	'MsgBox strNewComputer
	'Exit Sub
	'########################### 
	' Connect to Computer 
	'###########################
	Dim objWMILocator, objWMIComputer, objWMIComputerSystem, rc, objWMIService, colOperatingSystems, objOperatingSystem, objNetwork, objComputer
	Set objNetwork = CreateObject("WScript.Network")
	'Set objWMIComputer = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd) 
	'Set objWMIComputerSystem = objWMIComputer.Get( "Win32_ComputerSystem.Name='" & strComputer & "'") 
	If LCase(strComputer) = LCase(objNetwork.ComputerName) Then
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, authenticationLevel=pktPrivacy, (Shutdown)}!\\" & strComputer & "\root\cimv2") 
	Else
		Set objWMILocator = CreateObject("WbemScripting.SWbemLocator") 
		objWMILocator.Security_.AuthenticationLevel = 6 
		Set objWMIService = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd)
	End If
	'########################### 
	' Rename Computer 
	'########################### 
	Set objWMIComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem Where Name='" & strComputer & "'")
	For Each objWMIComputerSystem In objWMIComputer
		' There will only ever be one element in this collection
		rc = objWMIComputerSystem.Rename(strNewComputer, strDomainPasswd, strDomainUser) 
		if rc <> 0 then 
			Msgbox "Failed to rename " & strComputer & " to " & strNewComputer & " with error: " & rc 
		else 
			Msgbox "Successfully renamed " & strComputer & " to " & strNewComputer
			'########################### 
			' Place text files on the CURRENT computer that you are running this management from
			'###########################
			'Set objFSO = CreateObject("Scripting.FileSystemObject")
			'strLogFolder = "C:\PCs_Renamed\"
			'If objFSO.FolderExists(strLogFolder) = False Then objFSO.CreateTextFile strLogFolder
			'Set objFile = objFSO.CreateTextFile(strLogFolder & strNewComputer & ".txt", True)
			'objFile.Write strComputer & ";" & strOU
			'objFile.Close
			'########################### 
			' Reboot computer
			'###########################
			'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("RenameFrom").disabled = True
  document.GetElementByID("RenameTo").disabled = true
end Sub

Sub RenameFrom(checknum2)
	For i = 0 TO checkNum2.Length - 1 
		If checknum2(i).checked = True Then
'			MsgBox "Renaming " & checknum2(i).id & vbCrLf& checknum2(i).value & vbCrLf & " to " & strNewComputer
			strComputer2 = checknum2(i).id
			strDN2 = Split(checknum2(i).value, "|")(0)
			strParentOU2 = Split(Mid(checknum2(i).value,INSTR(checknum2(i).value,",")+1,LEN(checknum2(i).value)-INSTR(checknum2(i).value,",")), "|")(0)
			strNamingConvention2 = Split(Mid(checknum2(i).value,INSTR(checknum2(i).value,",")+1,LEN(checknum2(i).value)-INSTR(checknum2(i).value,",")), "|")(1)
			If Ping(strComputer2) = True Then
				MsgBox "1. " & strComputer2 & vbCrLf & "2. " & strDN2 & vbCrLf & "3. " & strParentOU2 & vbCrLf & "4. " & strNamingConvention2
				Call RenameSinglePC(strComputer2, strParentOU2, strNamingConvention2)
			Else
				objShell.Popup strComputer2 & " is not online.  Cannot rename computer.", 1, strComputer2 & " not online"
				checknum2(i).checked = False
			End If
		End If
	Next
End Sub

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

</script> 

</head> 


<body bgcolor="blue"> 
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650"> 
<tr valign="top"> 
<td colspan="2"> 
<span class="tabs tabsSelected" id="tab1" onclick="panel(1)">Rename Computers for Testing</span> 
<span class="tabs tabsNotSelected" id="tab2" onclick="panel(2)">Rename Computers back from Testing</span>
<!-- Tab 1 -->
<div class="panel" id="panel1" style="display:block"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<td style="text-align:right;font-size:0.9em;font-weight:bold;font-style:oblique;color:#888888;">
				Created by Gabriel Clifton
			</td>
		</tr>
	</table>
<!--Add your controls here-->
<select size="1" onChange="TestSub" name="selRenameTo" id="selRenameTo"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll" value="Check All" onclick="Check_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="uchckAll" value="Un-Check All" onclick="UNCheck_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="RenameTo" value="Rename To" onclick="RenameTo(document.myform.checkNum)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform" method="post">
            <span  id="instPath"></span>
        </font></form>
    </TH>
    </tr>
 </table>
  <table>
 	<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>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

<!-- Tab 2 -->
<div class="panel" id="panel2" style="display:none"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<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>

<!--Add your controls here-->
<select size="1" onChange="TestSub2" name="selRenameFrom" id="selRenameFrom"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename back</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll2" value="Check All" onclick="Check_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="uchckAll2" value="Un-Check All" onclick="Uncheck_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="RenameFrom" value="Rename From" onclick="RenameFrom(document.myform2.checkNum2)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform2" method="post">
            <span  id="instPath2"></span>
        </font></form>
    </TH>
    </tr>
 </table>
 <table>
 	<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>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

</body> 
</html>

Open in new window

0
 
Gabriel CliftonNet AdminAuthor Commented:
Sorry it took so long to get back, getting ready for school to start. The new version is working great with the exception of the gpupdate which I am assuming is because the computer is now renamed and checknum(i).id on line 321 is probably no longer valid.
0
 
RobSampsonCommented:
Oh you're right......that's embarrassing!   ;-)

I have now made RenameSinglePC a function that returns the new computer name back to the RenameTo sub, so that the commands can be ran against the new computer name.

See how this goes.

Rob.

<html> 
<head> 
<title>Rename Computer Labs for state testing</title> 

<HTA:Application 
ID = "HTA" 
ApplicationName = "RenLab" 
Border = "dialog" 
BorderStyle = "normal" 
Caption = "yes" 
ContextMenu="yes" 
ICON="\\Server\Share\panther.ICO"
InnerBorder="no" 
MaximizeButton = "no" 
MinimizeButton = "no" 
Navigable="yes" 
Scroll="yes" 
SrollFlat="no" 
Selection="yes" 
ShowInTaskBar = "yes" 
SingleInstance = "yes" 
SysMenu = "yes" 
Version = "1.0" 
> 
<style>
.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; 
} 
.tabsNotSelected { 
background-color: wheat; 
border: solid 1px black; 
} 
.tabsSelected { 
background-color: white; 
border-color: black black white black; 
border-style: solid solid solid solid; 
border-width: 1px 1px 1px 1px; 
} 
</style>
<script language="VBscript"> 
Dim sItem 
Dim aPanels 
Dim el 
Dim iPanelCount 
iPanelCount = 2
Dim intColCount
intColCount = 4
Dim strHTAPath

Sub Window_OnLoad

	ElevatedCheck
	width = "750"
	height = "750"
	' 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 
	
    If Mid(document.location, 6, 3) = "///" Then
    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)
    Else
    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)
    End If
		    
	'Original OU
	AddRenameToOption selRenameTo, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,dc=local|TESTNAVAL1-YYYY"
	AddRenameToOption selRenameTo, "Alamo D01 2-3 Lab", "OU=Alamo Room D01 Student,OU=RM D01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,dc=local|TESTNAVAL2-YYYY"
	
	AddRenameToOption selRenameTo, "Apache Room 006 Lab", "OU=Apache Lab Room 006 Student,OU=RM 06 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,dc=local|TESTNAVAP1-YYYY"
	AddRenameToOption selRenameTo, "Apache Room 017 Lab", "OU=Apache Lab Room 017 Student,OU=Apache Lab Room 017,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,dc=local|TESTNAVAP2-YYYY"
	AddRenameToOption selRenameTo, "Apache Room 326 Lab", "OU=Apache Lab Room 326 Student,OU=RM 326 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,dc=local|TESTNAVAP3-YYYY"
	
	AddRenameToOption selRenameTo, "Intermediate Room 001 Lab", "OU=Intermediate Lab Room 001 Student,OU=RM 01 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN1-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Room 012 Lab", "OU=Intermediate Lab Room 012 Student,OU=RM 12 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN2-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Room 027 Lab", "OU=Intermediate Lab Room 027 Student,OU=RM 27 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN3-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Room 028 Lab", "OU=Intermediate Lab Room 028 Student,OU=RM 28 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN4-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Mobile Lab", "OU=Mobile Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN5-YYYY"
	
	AddRenameToOption selRenameTo, "Middle School Room 110 Lab", "OU=Middle School 110 Lab Student,OU=RM 110 Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS1-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 111 Lab", "OU=Middle School 111 Lab Student,OU=RM 111 Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS2-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 118 Lab", "OU=Middle School Math Lab Student,OU=RM 118 Math Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS3-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 125 Lab", "OU=Middle School Science Lab Student,OU=RM 125 Science Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS4-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 126 Lab", "OU=Middle School Robotics Lab Student,OU=RM 126 Robotics Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS5-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 127 Lab", "OU=Middle School Spec-Ed Lab Student,OU=RM 127 Spec-Ed Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS6-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 130 Lab", "OU=Middle School Reading Lab Teacher,OU=RM 130 Reading Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS7-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 141 Lab", "OU=Student,OU=RM 141 Mobile Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS8-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room GCS Lab", "OU=Middle School GCS Lab Student,OU=RM GCS Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS9-YYYY"
	
	AddRenameToOption selRenameTo, "High School Room 11 Lab", "OU=HS Lab Room 11 Student,OU=RM 11 Panther Den Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS1-YYYY"
	AddRenameToOption selRenameTo, "High School Room 12 Lab", "OU=HS Lab Room 12 Student,OU=RM 12 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS2-YYYY"
	AddRenameToOption selRenameTo, "High School Room 13 Lab", "OU=High School Room 013 Student,OU=Rm 013 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS3-YYYY"
	AddRenameToOption selRenameTo, "High School Room 47 Lab", "OU=HS Lab Room 47 Student,OU=RM 47 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS6-YYYY"
	AddRenameToOption selRenameTo, "High School Room 48 Lab", "OU=HS Lab Room 48 Student,OU=RM 48 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS4-YYYY"
	AddRenameToOption selRenameTo, "High School Room 148 Lab", "OU=HS GCS Lab Student,OU=RM GCS Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS5-YYYY"
	AddRenameToOption selRenameTo, "High School Room 149 Lab", "OU=HS GCS Lab Student,OU=RM GCS Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS7-YYYY"
	
	AddRenameToOption selRenameTo, "Technology East Lab", "OU=East Computers,OU=East Lab,OU=Training Lab,OU=Technology Center,OU=Locations,DC=domain,dc=local|TESTNAVTC1-YYYY"
	AddRenameToOption selRenameTo, "Technology West Lab", "OU=West Computers,OU=West Lab,OU=Training Lab,OU=Technology Center,OU=Locations,DC=domain,dc=local|TESTNAVTC2-YYYY"
	
	'Testing OU
	AddRenameToOption selRenameFrom, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameFrom, "Alamo C01 K-1 Lab", "OU=Alamo,OU=TESTNAV,DC=domain,dc=local|ALRMC01YYYY"
	AddRenameToOption selRenameFrom, "Alamo D01 2-3 Lab", "OU=Alamo,OU=TESTNAV,DC=domain,dc=local|ALRMD01YYYY"
	
	AddRenameToOption selRenameFrom, "Apache Room 006 Lab", "OU=Apache,OU=TESTNAV,DC=domain,dc=local|APRM006YYYY"
	AddRenameToOption selRenameFrom, "Apache Room 017 Lab", "OU=Apache,OU=TESTNAV,DC=domain,dc=local|APRM017YYYY"
	AddRenameToOption selRenameFrom, "Apache Room 326 Lab", "OU=Apache,OU=TESTNAV,DC=domain,dc=local|APRM326YYYY"
	
	AddRenameToOption selRenameFrom, "Intermediate Room 001 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM001YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Room 012 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM012YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Room 027 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM027YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Room 028 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM028YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Mobile Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INML001YYYY"
	
	AddRenameToOption selRenameFrom, "Middle School Room 110 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM110YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 111 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM111YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 118 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM118YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 125 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM125YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 126 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM126YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 127 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM127YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 130 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM130YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 141 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM141YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 148 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM148YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 149 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM149YYYY"
	
	AddRenameToOption selRenameFrom, "High School Room 11 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM011YYYY"
	AddRenameToOption selRenameFrom, "High School Room 12 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM012YYYY"
	AddRenameToOption selRenameFrom, "High School Room 13 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM013YYYY"
	AddRenameToOption selRenameFrom, "High School Room 47 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM047YYYY"
	AddRenameToOption selRenameFrom, "High School Room 48 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM048YYYY"
	AddRenameToOption selRenameFrom, "High School GCS Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRMGCSYYYY"
	
	AddRenameToOption selRenameFrom, "Technology East Lab", "OU=Technology,OU=TESTNAV,DC=domain,dc=local|TCLATLEYYYY"
	AddRenameToOption selRenameFrom, "Technology West Lab", "OU=Technology,OU=TESTNAV,DC=domain,dc=local|TCLATLWYYYY"
End Sub

Sub ElevatedCheck
	'Source: http://www.thegbach.com/elevatedHta.html
	Set objShell = CreateObject("WScript.Shell")
	Set objShellApp = CreateObject("Shell.Application")
	strElevated = False
	strHTADir = document.location.pathname
	Set objWhoami = objShell.Exec("whoami /groups")
	strWhoami = objWhoami.StdOut.ReadAll
	If InStr(1, strWhoami,"S-1-16-12288",vbTextCompare) Then
	strElevated = True
	Else
		objShellApp.ShellExecute"mshta.exe",Chr(34) & strHTADir & Chr(34) & " runasadministrator","","runas",1
		window.close()
	End If 
End Sub

SUB Check_M_All(checkNum) 
   ON ERROR RESUME NEXT 
       checkNum.Checked = TRUE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.length - 1 
               checkNum(i).checked = TRUE 
           Next 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
 SUB Uncheck_M_All(checkNum)
   ON ERROR RESUME NEXT 
       checkNum.Checked = FALSE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.Length - 1 
               checkNum(i).Checked = FALSE 
           NEXT 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
Private Sub Panel(tab) 
	For i = 1 To iPanelCount 
		If i = tab Then 
			document.getElementById("tab" & i).className = "tabs tabsSelected" 
			document.getElementById("panel" & i).style.display = "block" 
		Else 
			document.getElementById("tab" & i).className = "tabs tabsNotSelected" 
			document.getElementById("panel" & i).style.display = "none" 
		End If 
	Next 
End Sub 

Sub AddRenameToOption(objObject, strText, strValue)
	Set objOption = Document.CreateElement("OPTION")
	objOption.Text = strText
	objOption.Value = strValue
	objObject.Add(objOption)
End Sub

'Tab 1
Sub TestSub
	strText = selRenameTo.Item(selRenameTo.SelectedIndex).Text
	strValue = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Value, "|")(0)
	strNaming = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Value, "|")(1)
	'MsgBox strText & vbCrLf & strValue
	Set objOU = GetObject("LDAP://" & strValue)
	strNames = ""
	intCol = 0
	strNames = "<table cellspacing=10 cellpadding=0 border=0>"
	For Each objObject In objOU
		If objObject.class = "computer" Then
			strCheckBoxCode = ""
			If intCol = 0 Then
				strCheckBoxCode = "<tr>"
			End If
			strCheckBoxCode = strCheckBoxCode & "<td><font color=""white""><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum"" value=""" & objObject.distinguishedName & "|" & strNaming & """>" & Mid(objObject.Name, 4) & "</font></td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode = strCheckBoxCode & "</tr>"
				intCol = 0
			End If
			If strNames = "" Then
				strNames = strCheckBoxCode
			Else
				strNames = strNames & vbCrLf & strCheckBoxCode
			End If
		End If
	Next
	strNames = strNames & vbCrLf & "</table>"
    instPath.InnerHTML = strNames
End Sub

'Tab 2
Sub TestSub2
	strText2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Text
	strValue2 = Split(selRenameFrom.Item(selRenameFrom.SelectedIndex).Value, "|")(0)
	strNaming2 = Split(selRenameFrom.Item(selRenameFrom.SelectedIndex).Value, "|")(1)
'	MsgBox strText2 & vbCrLf & strValue2
	Set objOU2 = GetObject("LDAP://" & strValue2)
	strNames2 = ""
	intCol = 0
	strNames2 = "<table cellspacing=10 cellpadding=0 border=0>"
	For Each objObject In objOU2
		If objObject.class = "computer" Then
			strCheckBoxCode2 = ""
			If intCol = 0 Then
				strCheckBoxCode2 = "<tr>"
			End If
			strCheckBoxCode2 = strCheckBoxCode2 & "<td><font color=""white""><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum2"" value=""" & objObject.distinguishedName & "|" & strNaming2 & """>" & Mid(objObject.Name, 4) & "</font></td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode2 = strCheckBoxCode2 & "</tr>"
				intCol = 0
			End If
			If strNames2 = "" Then
				strNames2 = strCheckBoxCode2
			Else
				strNames2 = strNames2 & vbCrLf & strCheckBoxCode2
			End If
		End If
	Next
	strNames2 = strNames2 & vbCrLf & "</table>"
    instPath2.InnerHTML = strNames2
End Sub

Sub RenameTo(checknum)
	Set objShell = CreateObject("WScript.Shell")
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	blnComputerRenamed = False
	Set dctToRename = CreateObject("Scripting.Dictionary")
	dctToRename.CompareMode = vbTextCompare
	blnShutdown = MsgBox("Do you want to shut down non-selected computers in this OU?", vbYesNo, "Shutdown computers?")
	FOR i = 0 TO checkNum.length - 1 
		If checknum(i).checked = True Then
			'MsgBox "Renaming " & checknum(i).id & vbCrLf& checknum(i).value & vbCrLf & " to " & strNewComputer
			strComputer = checknum(i).id
			strDN = Split(checknum(i).value, "|")(0)
			strParentOU = Split(Mid(checknum(i).value,INSTR(checknum(i).value,",")+1,LEN(checknum(i).value)-INSTR(checknum(i).value,",")), "|")(0)
			strNamingConvention = Split(Mid(checknum(i).value,INSTR(checknum(i).value,",")+1,LEN(checknum(i).value)-INSTR(checknum(i).value,",")), "|")(1)
			If Ping(strComputer) = True Then
				MsgBox "1. " & strComputer & vbCrLf & "2. " & strDN & vbCrLf & "3. " & strParentOU & vbCrLf & "3. " & strNamingConvention
				strNewPCName = RenameSinglePC(strComputer, strParentOU, strNamingConvention)
				blnComputerRenamed = True
				dctToRename.Add strComputer, strNewPCName
			Else
				objShell.Popup strComputer & " is not online.  Cannot rename computer.", 2, strComputer & " not online"
				checknum(i).checked = False
			End If
		Else
			If blnShutdown = vbYes Then
				objShell.Popup "Shutting down " & checknum(i).id, 1, checknum(i).id
				objShell.Run "cmd /c shutdown /s /t 00 /m " & checknum(i).id
			End If
		End If
	Next
	If blnComputerRenamed = True Then
		dteEndTime = DateAdd("s", 300, Now)
		While DateDiff("s", Now, dteEndTime) > 0
			intWait = DateDiff("s", Now, dteEndTime)
			If DateDiff("s", Now, dteEndTime) > 30 Then intWait = 30
			objShell.Popup "Waiting " & DateDiff("s", Now, dteEndTime) & " seconds.", intWait, "Waiting for computers to be placed in the correct OU..."
		Wend
		strPSExec = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "PSExec.exe"
		If objFSO.FileExists(strPSExec) = True Then
			For Each strPC In dctToRename
				objShell.Popup "Running gpupdate on " & dctToRename(strPC), 1, "GPUpdate on " & dctToRename(strPC)
				objShell.Run "cmd /c " & objFSO.GetFile(strPSExec).ShortPath & " -accepteula \\" & dctToRename(strPC) & " gpupdate /force", 0, True
				objShell.Run "cmd /c shutdown /r /t 00 /m " & dctToRename(strPC)
			Next
		Else
			MsgBox "Unable to find " & strPSExec & " to run GPUpdate"
		End If
	End If
End Sub

Function RenameSinglePC(strComputer, strOU, strConvention)
	strDomainUser = document.getElementById("uName").value & "@domain.local"
	strDomainPasswd = document.getElementById("uPassword").value
	strLocalUser = strComputer & "\administrator"
	strLocalPasswd = "password"
	arrLabParts = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Text, " ")
       'strNewComputer = "TESTNAV" & Left(selRenameTo.Item(selRenameTo.SelectedIndex).Text, 2) & arrLabParts(UBound(arrLabParts) - 1) & "-" & Right(strComputer, 4)
    strNewComputer = Replace(strConvention, "YYYY", Right(strComputer, 4))
	'MsgBox strNewComputer
	'Exit Sub
	'########################### 
	' Connect to Computer 
	'###########################
	Dim objWMILocator, objWMIComputer, objWMIComputerSystem, rc, objWMIService, colOperatingSystems, objOperatingSystem, objNetwork, objComputer
	Set objNetwork = CreateObject("WScript.Network")
	'Set objWMIComputer = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd) 
	'Set objWMIComputerSystem = objWMIComputer.Get( "Win32_ComputerSystem.Name='" & strComputer & "'") 
	If LCase(strComputer) = LCase(objNetwork.ComputerName) Then
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, authenticationLevel=pktPrivacy, (Shutdown)}!\\" & strComputer & "\root\cimv2") 
	Else
		Set objWMILocator = CreateObject("WbemScripting.SWbemLocator") 
		objWMILocator.Security_.AuthenticationLevel = 6 
		Set objWMIService = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd)
	End If
	'########################### 
	' Rename Computer 
	'########################### 
	Set objWMIComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem Where Name='" & strComputer & "'")
	For Each objWMIComputerSystem In objWMIComputer
		' There will only ever be one element in this collection
		rc = objWMIComputerSystem.Rename(strNewComputer, strDomainPasswd, strDomainUser) 
		if rc <> 0 then 
			Msgbox "Failed to rename " & strComputer & " to " & strNewComputer & " with error: " & rc 
		else 
			Msgbox "Successfully renamed " & strComputer & " to " & strNewComputer
			'########################### 
			' Place text files on the CURRENT computer that you are running this management from
			'###########################
			'Set objFSO = CreateObject("Scripting.FileSystemObject")
			'strLogFolder = "C:\PCs_Renamed\"
			'If objFSO.FolderExists(strLogFolder) = False Then objFSO.CreateTextFile strLogFolder
			'Set objFile = objFSO.CreateTextFile(strLogFolder & strNewComputer & ".txt", True)
			'objFile.Write strComputer & ";" & strOU
			'objFile.Close
			'########################### 
			' Reboot computer
			'###########################
			'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
	If rc <> 0 Then
		RenameSinglePC = "FAILED"
	Else
		RenameSinglePC = strNewComputer
	End If
End Function

sub disableButton()
  document.GetElementByID("RenameFrom").disabled = True
  document.GetElementByID("RenameTo").disabled = true
end Sub

Sub RenameFrom(checknum2)
	For i = 0 TO checkNum2.Length - 1 
		If checknum2(i).checked = True Then
'			MsgBox "Renaming " & checknum2(i).id & vbCrLf& checknum2(i).value & vbCrLf & " to " & strNewComputer
			strComputer2 = checknum2(i).id
			strDN2 = Split(checknum2(i).value, "|")(0)
			strParentOU2 = Split(Mid(checknum2(i).value,INSTR(checknum2(i).value,",")+1,LEN(checknum2(i).value)-INSTR(checknum2(i).value,",")), "|")(0)
			strNamingConvention2 = Split(Mid(checknum2(i).value,INSTR(checknum2(i).value,",")+1,LEN(checknum2(i).value)-INSTR(checknum2(i).value,",")), "|")(1)
			If Ping(strComputer2) = True Then
				MsgBox "1. " & strComputer2 & vbCrLf & "2. " & strDN2 & vbCrLf & "3. " & strParentOU2 & vbCrLf & "4. " & strNamingConvention2
				Call RenameSinglePC(strComputer2, strParentOU2, strNamingConvention2)
			Else
				objShell.Popup strComputer2 & " is not online.  Cannot rename computer.", 1, strComputer2 & " not online"
				checknum2(i).checked = False
			End If
		End If
	Next
End Sub

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

</script> 

</head> 


<body bgcolor="blue"> 
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650"> 
<tr valign="top"> 
<td colspan="2"> 
<span class="tabs tabsSelected" id="tab1" onclick="panel(1)">Rename Computers for Testing</span> 
<span class="tabs tabsNotSelected" id="tab2" onclick="panel(2)">Rename Computers back from Testing</span>
<!-- Tab 1 -->
<div class="panel" id="panel1" style="display:block"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<td style="text-align:right;font-size:0.9em;font-weight:bold;font-style:oblique;color:#888888;">
				Created by Gabriel Clifton
			</td>
		</tr>
	</table>
<!--Add your controls here-->
<select size="1" onChange="TestSub" name="selRenameTo" id="selRenameTo"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll" value="Check All" onclick="Check_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="uchckAll" value="Un-Check All" onclick="UNCheck_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="RenameTo" value="Rename To" onclick="RenameTo(document.myform.checkNum)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform" method="post">
            <span  id="instPath"></span>
        </font></form>
    </TH>
    </tr>
 </table>
  <table>
 	<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>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

<!-- Tab 2 -->
<div class="panel" id="panel2" style="display:none"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<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>

<!--Add your controls here-->
<select size="1" onChange="TestSub2" name="selRenameFrom" id="selRenameFrom"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename back</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll2" value="Check All" onclick="Check_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="uchckAll2" value="Un-Check All" onclick="Uncheck_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="RenameFrom" value="Rename From" onclick="RenameFrom(document.myform2.checkNum2)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform2" method="post">
            <span  id="instPath2"></span>
        </font></form>
    </TH>
    </tr>
 </table>
 <table>
 	<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>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

</body> 
</html>

Open in new window

0
 
Gabriel CliftonNet AdminAuthor Commented:
I have not forgotten about this, have not taken a look yet. I have shattered a bone in my foot and have had several pre-surgery doctor visits.
0
 
RobSampsonCommented:
Oh man, that doesn't sound good! Rest up, I can wait until you are ready to give it a shot.

Rob.
0
 
Gabriel CliftonNet AdminAuthor Commented:
Moderator, this is not abandoned, unable to get to it right now.
0
 
RobSampsonCommented:
I didn't see any "abandoned" notice, so we should be OK to continue. I'm snowed under as well, so take your time ;-)
0
 
Gabriel CliftonNet AdminAuthor Commented:
All right, I got a little bit of a chance to look at it. The rename to is looking perfect. Off to rename from.
0
 
RobSampsonCommented:
Hi, wow, where does three weeks go!!??!  Sorry for the delay, try this for the ability to rename computers back according to your naming convention.

Regards,

Rob.

<html> 
<head> 
<title>Rename Computer Labs for state testing</title> 

<HTA:Application 
ID = "HTA" 
ApplicationName = "RenLab" 
Border = "dialog" 
BorderStyle = "normal" 
Caption = "yes" 
ContextMenu="yes" 
ICON="\\Server\Share\panther.ICO"
InnerBorder="no" 
MaximizeButton = "no" 
MinimizeButton = "no" 
Navigable="yes" 
Scroll="yes" 
SrollFlat="no" 
Selection="yes" 
ShowInTaskBar = "yes" 
SingleInstance = "yes" 
SysMenu = "yes" 
Version = "1.0" 
> 
<style>
.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; 
} 
.tabsNotSelected { 
background-color: wheat; 
border: solid 1px black; 
} 
.tabsSelected { 
background-color: white; 
border-color: black black white black; 
border-style: solid solid solid solid; 
border-width: 1px 1px 1px 1px; 
} 
</style>
<script language="VBscript"> 
Dim sItem 
Dim aPanels 
Dim el 
Dim iPanelCount 
iPanelCount = 2
Dim intColCount
intColCount = 4
Dim strHTAPath

Sub Window_OnLoad

	ElevatedCheck
	width = "750"
	height = "750"
	' 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 
	
    If Mid(document.location, 6, 3) = "///" Then
    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 9)
    Else
    	strHTAPath = Mid(Replace(Replace(document.location, "%20", " "), "/", "\"), 6)
    End If
		    
	'Original OU
	AddRenameToOption selRenameTo, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameTo, "Alamo C01 K-1 Lab", "OU=Alamo Room C01 Student,OU=RM C01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,dc=local|TESTNAVAL1-YYYY"
	AddRenameToOption selRenameTo, "Alamo D01 2-3 Lab", "OU=Alamo Room D01 Student,OU=RM D01 Lab,OU=Alamo Lab,OU=Alamo,OU=Locations,DC=domain,dc=local|TESTNAVAL2-YYYY"
	
	AddRenameToOption selRenameTo, "Apache Room 006 Lab", "OU=Apache Lab Room 006 Student,OU=RM 06 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,dc=local|TESTNAVAP1-YYYY"
	AddRenameToOption selRenameTo, "Apache Room 017 Lab", "OU=Apache Lab Room 017 Student,OU=Apache Lab Room 017,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,dc=local|TESTNAVAP2-YYYY"
	AddRenameToOption selRenameTo, "Apache Room 326 Lab", "OU=Apache Lab Room 326 Student,OU=RM 326 Lab,OU=Apache Lab,OU=Apache,OU=Locations,DC=domain,dc=local|TESTNAVAP3-YYYY"
	
	AddRenameToOption selRenameTo, "Intermediate Room 001 Lab", "OU=Intermediate Lab Room 001 Student,OU=RM 01 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN1-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Room 012 Lab", "OU=Intermediate Lab Room 012 Student,OU=RM 12 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN2-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Room 027 Lab", "OU=Intermediate Lab Room 027 Student,OU=RM 27 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN3-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Room 028 Lab", "OU=Intermediate Lab Room 028 Student,OU=RM 28 Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN4-YYYY"
	AddRenameToOption selRenameTo, "Intermediate Mobile Lab", "OU=Mobile Lab,OU=intermediate Lab,OU=Intermediate,OU=Locations,DC=domain,dc=local|TESTNAVIN5-YYYY"
	
	AddRenameToOption selRenameTo, "Middle School Room 110 Lab", "OU=Middle School 110 Lab Student,OU=RM 110 Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS1-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 111 Lab", "OU=Middle School 111 Lab Student,OU=RM 111 Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS2-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 118 Lab", "OU=Middle School Math Lab Student,OU=RM 118 Math Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS3-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 125 Lab", "OU=Middle School Science Lab Student,OU=RM 125 Science Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS4-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 126 Lab", "OU=Middle School Robotics Lab Student,OU=RM 126 Robotics Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS5-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 127 Lab", "OU=Middle School Spec-Ed Lab Student,OU=RM 127 Spec-Ed Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS6-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 130 Lab", "OU=Middle School Reading Lab Teacher,OU=RM 130 Reading Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS7-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room 141 Lab", "OU=Student,OU=RM 141 Mobile Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS8-YYYY"
	AddRenameToOption selRenameTo, "Middle School Room GCS Lab", "OU=Middle School GCS Lab Student,OU=RM GCS Lab,OU=Middle School Lab,OU=Middle School,OU=Locations,DC=domain,dc=local|TESTNAVMS9-YYYY"
	
	AddRenameToOption selRenameTo, "High School Room 11 Lab", "OU=HS Lab Room 11 Student,OU=RM 11 Panther Den Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS1-YYYY"
	AddRenameToOption selRenameTo, "High School Room 12 Lab", "OU=HS Lab Room 12 Student,OU=RM 12 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS2-YYYY"
	AddRenameToOption selRenameTo, "High School Room 13 Lab", "OU=High School Room 013 Student,OU=Rm 013 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS3-YYYY"
	AddRenameToOption selRenameTo, "High School Room 47 Lab", "OU=HS Lab Room 47 Student,OU=RM 47 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS6-YYYY"
	AddRenameToOption selRenameTo, "High School Room 48 Lab", "OU=HS Lab Room 48 Student,OU=RM 48 Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS4-YYYY"
	AddRenameToOption selRenameTo, "High School Room 148 Lab", "OU=HS GCS Lab Student,OU=RM GCS Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS5-YYYY"
	AddRenameToOption selRenameTo, "High School Room 149 Lab", "OU=HS GCS Lab Student,OU=RM GCS Lab,OU=High School Lab,OU=High School,OU=Locations,DC=domain,dc=local|TESTNAVHS7-YYYY"
	
	AddRenameToOption selRenameTo, "Technology East Lab", "OU=East Computers,OU=East Lab,OU=Training Lab,OU=Technology Center,OU=Locations,DC=domain,dc=local|TESTNAVTC1-YYYY"
	AddRenameToOption selRenameTo, "Technology West Lab", "OU=West Computers,OU=West Lab,OU=Training Lab,OU=Technology Center,OU=Locations,DC=domain,dc=local|TESTNAVTC2-YYYY"
	
	'Testing OU
	AddRenameToOption selRenameFrom, " --- Select --- ", " --- Select --- "
	AddRenameToOption selRenameFrom, "Alamo C01 K-1 Lab", "OU=Alamo,OU=TESTNAV,DC=domain,dc=local|ALRMC01YYYY"
	AddRenameToOption selRenameFrom, "Alamo D01 2-3 Lab", "OU=Alamo,OU=TESTNAV,DC=domain,dc=local|ALRMD01YYYY"
	
	AddRenameToOption selRenameFrom, "Apache Room 006 Lab", "OU=Apache,OU=TESTNAV,DC=domain,dc=local|APRM006YYYY"
	AddRenameToOption selRenameFrom, "Apache Room 017 Lab", "OU=Apache,OU=TESTNAV,DC=domain,dc=local|APRM017YYYY"
	AddRenameToOption selRenameFrom, "Apache Room 326 Lab", "OU=Apache,OU=TESTNAV,DC=domain,dc=local|APRM326YYYY"
	
	AddRenameToOption selRenameFrom, "Intermediate Room 001 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM001YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Room 012 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM012YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Room 027 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM027YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Room 028 Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INRM028YYYY"
	AddRenameToOption selRenameFrom, "Intermediate Mobile Lab", "OU=Intermediate,OU=TESTNAV,DC=domain,dc=local|INML001YYYY"
	
	AddRenameToOption selRenameFrom, "Middle School Room 110 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM110YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 111 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM111YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 118 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM118YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 125 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM125YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 126 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM126YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 127 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM127YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 130 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM130YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 141 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM141YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 148 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM148YYYY"
	AddRenameToOption selRenameFrom, "Middle School Room 149 Lab", "OU=Middle School,OU=TESTNAV,DC=domain,dc=local|MSRM149YYYY"
	
	AddRenameToOption selRenameFrom, "High School Room 11 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM011YYYY"
	AddRenameToOption selRenameFrom, "High School Room 12 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM012YYYY"
	AddRenameToOption selRenameFrom, "High School Room 13 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM013YYYY"
	AddRenameToOption selRenameFrom, "High School Room 47 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM047YYYY"
	AddRenameToOption selRenameFrom, "High School Room 48 Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRM048YYYY"
	AddRenameToOption selRenameFrom, "High School GCS Lab", "OU=High School,OU=TESTNAV,DC=domain,dc=local|HSRMGCSYYYY"
	
	AddRenameToOption selRenameFrom, "Technology East Lab", "OU=Technology,OU=TESTNAV,DC=domain,dc=local|TCLATLEYYYY"
	AddRenameToOption selRenameFrom, "Technology West Lab", "OU=Technology,OU=TESTNAV,DC=domain,dc=local|TCLATLWYYYY"
End Sub

Sub ElevatedCheck
	'Source: http://www.thegbach.com/elevatedHta.html
	Set objShell = CreateObject("WScript.Shell")
	Set objShellApp = CreateObject("Shell.Application")
	strElevated = False
	strHTADir = document.location.pathname
	Set objWhoami = objShell.Exec("whoami /groups")
	strWhoami = objWhoami.StdOut.ReadAll
	If InStr(1, strWhoami,"S-1-16-12288",vbTextCompare) Then
	strElevated = True
	Else
		objShellApp.ShellExecute"mshta.exe",Chr(34) & strHTADir & Chr(34) & " runasadministrator","","runas",1
		window.close()
	End If 
End Sub

SUB Check_M_All(checkNum) 
   ON ERROR RESUME NEXT 
       checkNum.Checked = TRUE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.length - 1 
               checkNum(i).checked = TRUE 
           Next 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
 SUB Uncheck_M_All(checkNum)
   ON ERROR RESUME NEXT 
       checkNum.Checked = FALSE 
       IF ERR.Number <> 0 THEN 
           FOR i = 0 TO checkNum.Length - 1 
               checkNum(i).Checked = FALSE 
           NEXT 
       END IF 
   ON ERROR GOTO 0 
 END SUB 
 
Private Sub Panel(tab) 
	For i = 1 To iPanelCount 
		If i = tab Then 
			document.getElementById("tab" & i).className = "tabs tabsSelected" 
			document.getElementById("panel" & i).style.display = "block" 
		Else 
			document.getElementById("tab" & i).className = "tabs tabsNotSelected" 
			document.getElementById("panel" & i).style.display = "none" 
		End If 
	Next 
End Sub 

Sub AddRenameToOption(objObject, strText, strValue)
	Set objOption = Document.CreateElement("OPTION")
	objOption.Text = strText
	objOption.Value = strValue
	objObject.Add(objOption)
End Sub

'Tab 1
Sub TestSub
	strText = selRenameTo.Item(selRenameTo.SelectedIndex).Text
	strValue = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Value, "|")(0)
	strNaming = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Value, "|")(1)
	'MsgBox strText & vbCrLf & strValue
	Set objOU = GetObject("LDAP://" & strValue)
	strNames = ""
	intCol = 0
	strNames = "<table cellspacing=10 cellpadding=0 border=0>"
	For Each objObject In objOU
		If objObject.class = "computer" Then
			strCheckBoxCode = ""
			If intCol = 0 Then
				strCheckBoxCode = "<tr>"
			End If
			strCheckBoxCode = strCheckBoxCode & "<td><font color=""white""><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum"" value=""" & objObject.distinguishedName & "|" & strNaming & """>" & Mid(objObject.Name, 4) & "</font></td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode = strCheckBoxCode & "</tr>"
				intCol = 0
			End If
			If strNames = "" Then
				strNames = strCheckBoxCode
			Else
				strNames = strNames & vbCrLf & strCheckBoxCode
			End If
		End If
	Next
	strNames = strNames & vbCrLf & "</table>"
    instPath.InnerHTML = strNames
End Sub

'Tab 2
Sub TestSub2
	strText2 = selRenameFrom.Item(selRenameFrom.SelectedIndex).Text
	strValue2 = Split(selRenameFrom.Item(selRenameFrom.SelectedIndex).Value, "|")(0)
	strNaming2 = Split(selRenameFrom.Item(selRenameFrom.SelectedIndex).Value, "|")(1)
'	MsgBox strText2 & vbCrLf & strValue2
	Set objOU2 = GetObject("LDAP://" & strValue2)
	strNames2 = ""
	intCol = 0
	strNames2 = "<table cellspacing=10 cellpadding=0 border=0>"
	For Each objObject In objOU2
		If objObject.class = "computer" Then
			strCheckBoxCode2 = ""
			If intCol = 0 Then
				strCheckBoxCode2 = "<tr>"
			End If
			strCheckBoxCode2 = strCheckBoxCode2 & "<td><font color=""white""><input type=""checkbox"" id=""" & Mid(objObject.Name, 4) & """ name=""checkNum2"" value=""" & objObject.distinguishedName & "|" & strNaming2 & """>" & Mid(objObject.Name, 4) & "</font></td>"
			intCol = intCol + 1
			If intCol = intColCount Then
				strCheckBoxCode2 = strCheckBoxCode2 & "</tr>"
				intCol = 0
			End If
			If strNames2 = "" Then
				strNames2 = strCheckBoxCode2
			Else
				strNames2 = strNames2 & vbCrLf & strCheckBoxCode2
			End If
		End If
	Next
	strNames2 = strNames2 & vbCrLf & "</table>"
    instPath2.InnerHTML = strNames2
End Sub

Sub RenameTo(checknum)
	Set objShell = CreateObject("WScript.Shell")
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	blnComputerRenamed = False
	Set dctToRename = CreateObject("Scripting.Dictionary")
	dctToRename.CompareMode = vbTextCompare
	blnShutdown = MsgBox("Do you want to shut down non-selected computers in this OU?", vbYesNo, "Shutdown computers?")
	FOR i = 0 TO checkNum.length - 1 
		If checknum(i).checked = True Then
			'MsgBox "Renaming " & checknum(i).id & vbCrLf& checknum(i).value & vbCrLf & " to " & strNewComputer
			strComputer = checknum(i).id
			strDN = Split(checknum(i).value, "|")(0)
			strParentOU = Split(Mid(checknum(i).value,INSTR(checknum(i).value,",")+1,LEN(checknum(i).value)-INSTR(checknum(i).value,",")), "|")(0)
			strNamingConvention = Split(Mid(checknum(i).value,INSTR(checknum(i).value,",")+1,LEN(checknum(i).value)-INSTR(checknum(i).value,",")), "|")(1)
			If Ping(strComputer) = True Then
				MsgBox "1. " & strComputer & vbCrLf & "2. " & strDN & vbCrLf & "3. " & strParentOU & vbCrLf & "3. " & strNamingConvention
				strNewPCName = RenameSinglePC(strComputer, strParentOU, strNamingConvention)
				blnComputerRenamed = True
				dctToRename.Add strComputer, strNewPCName
			Else
				objShell.Popup strComputer & " is not online.  Cannot rename computer.", 2, strComputer & " not online"
				checknum(i).checked = False
			End If
		Else
			If blnShutdown = vbYes Then
				objShell.Popup "Shutting down " & checknum(i).id, 1, checknum(i).id
				objShell.Run "cmd /c shutdown /s /t 00 /m " & checknum(i).id
			End If
		End If
	Next
	If blnComputerRenamed = True Then
		dteEndTime = DateAdd("s", 300, Now)
		While DateDiff("s", Now, dteEndTime) > 0
			intWait = DateDiff("s", Now, dteEndTime)
			If DateDiff("s", Now, dteEndTime) > 30 Then intWait = 30
			objShell.Popup "Waiting " & DateDiff("s", Now, dteEndTime) & " seconds.", intWait, "Waiting for computers to be placed in the correct OU..."
		Wend
		strPSExec = Left(strHTAPath, InStrRev(strHTAPath, "\")) & "PSExec.exe"
		If objFSO.FileExists(strPSExec) = True Then
			For Each strPC In dctToRename
				objShell.Popup "Running gpupdate on " & dctToRename(strPC), 1, "GPUpdate on " & dctToRename(strPC)
				objShell.Run "cmd /c " & objFSO.GetFile(strPSExec).ShortPath & " -accepteula \\" & dctToRename(strPC) & " gpupdate /force", 0, True
				objShell.Run "cmd /c shutdown /r /t 00 /m " & dctToRename(strPC)
			Next
		Else
			MsgBox "Unable to find " & strPSExec & " to run GPUpdate"
		End If
	End If
End Sub

Function RenameSinglePC(strComputer, strOU, strConvention)
	strDomainUser = document.getElementById("uName").value & "@domain.local"
	strDomainPasswd = document.getElementById("uPassword").value
	strLocalUser = strComputer & "\administrator"
	strLocalPasswd = "password"
	arrLabParts = Split(selRenameTo.Item(selRenameTo.SelectedIndex).Text, " ")
       'strNewComputer = "TESTNAV" & Left(selRenameTo.Item(selRenameTo.SelectedIndex).Text, 2) & arrLabParts(UBound(arrLabParts) - 1) & "-" & Right(strComputer, 4)
    strNewComputer = Replace(strConvention, "YYYY", Right(strComputer, 4))
	'MsgBox strNewComputer
	'Exit Sub
	'########################### 
	' Connect to Computer 
	'###########################
	Dim objWMILocator, objWMIComputer, objWMIComputerSystem, rc, objWMIService, colOperatingSystems, objOperatingSystem, objNetwork, objComputer
	Set objNetwork = CreateObject("WScript.Network")
	'Set objWMIComputer = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd) 
	'Set objWMIComputerSystem = objWMIComputer.Get( "Win32_ComputerSystem.Name='" & strComputer & "'") 
	If LCase(strComputer) = LCase(objNetwork.ComputerName) Then
		Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate, authenticationLevel=pktPrivacy, (Shutdown)}!\\" & strComputer & "\root\cimv2") 
	Else
		Set objWMILocator = CreateObject("WbemScripting.SWbemLocator") 
		objWMILocator.Security_.AuthenticationLevel = 6 
		Set objWMIService = objWMILocator.ConnectServer(strComputer, "root\cimv2", strLocalUser, strLocalPasswd)
	End If
	'########################### 
	' Rename Computer 
	'########################### 
	Set objWMIComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem Where Name='" & strComputer & "'")
	For Each objWMIComputerSystem In objWMIComputer
		' There will only ever be one element in this collection
		rc = objWMIComputerSystem.Rename(strNewComputer, strDomainPasswd, strDomainUser) 
		if rc <> 0 then 
			Msgbox "Failed to rename " & strComputer & " to " & strNewComputer & " with error: " & rc 
		else 
			Msgbox "Successfully renamed " & strComputer & " to " & strNewComputer
			'########################### 
			' Place text files on the CURRENT computer that you are running this management from
			'###########################
			'Set objFSO = CreateObject("Scripting.FileSystemObject")
			'strLogFolder = "C:\PCs_Renamed\"
			'If objFSO.FolderExists(strLogFolder) = False Then objFSO.CreateTextFile strLogFolder
			'Set objFile = objFSO.CreateTextFile(strLogFolder & strNewComputer & ".txt", True)
			'objFile.Write strComputer & ";" & strOU
			'objFile.Close
			'########################### 
			' Reboot computer
			'###########################
			'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
	If rc <> 0 Then
		RenameSinglePC = "FAILED"
	Else
		RenameSinglePC = strNewComputer
	End If
End Function

sub disableButton()
  document.GetElementByID("RenameFrom").disabled = True
  document.GetElementByID("RenameTo").disabled = true
end Sub

Sub RenameFrom(checknum2)
	Set objShell = CreateObject("WScript.Shell")
	Set objFSO = CreateObject("Scripting.FileSystemObject")
	blnComputerRenamed2 = False
	Set dctToRename = CreateObject("Scripting.Dictionary")
	dctToRename.CompareMode = vbTextCompare
	blnShutdown = MsgBox("Do you want to shut down non-selected computers in this OU?", vbYesNo, "Shutdown computers?")
	For i = 0 TO checkNum2.Length - 1 
		If checknum2(i).checked = True Then
'			MsgBox "Renaming " & checknum2(i).id & vbCrLf& checknum2(i).value & vbCrLf & " to " & strNewComputer
			strComputer2 = checknum2(i).id
			strDN2 = Split(checknum2(i).value, "|")(0)
			strParentOU2 = Split(Mid(checknum2(i).value,INSTR(checknum2(i).value,",")+1,LEN(checknum2(i).value)-INSTR(checknum2(i).value,",")), "|")(0)
			strNamingConvention2 = Split(Mid(checknum2(i).value,INSTR(checknum2(i).value,",")+1,LEN(checknum2(i).value)-INSTR(checknum2(i).value,",")), "|")(1)
			If Ping(strComputer2) = True Then
				MsgBox "1. " & strComputer2 & vbCrLf & "2. " & strDN2 & vbCrLf & "3. " & strParentOU2 & vbCrLf & "4. " & strNamingConvention2
				strNewPCName2 = RenameSinglePC(strComputer2, strParentOU2, strNamingConvention2)
				blnComputerRenamed2 = True
				dctToRename.Add strComputer2, strNewPCName2
			Else
				objShell.Popup strComputer2 & " is not online.  Cannot rename computer.", 2, strComputer2 & " not online"
				checknum2(i).checked = False
			End If
		Else
			If blnShutdown = vbYes Then
				objShell.Popup "Shutting down " & checknum2(i).id, 1, checknum2(i).id
				objShell.Run "cmd /c shutdown /s /t 00 /m " & checknum2(i).id
			End If
		End If
	Next
End Sub

Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
	Else
		Ping = False
	End If
End Function

</script> 

</head> 


<body bgcolor="blue"> 
<table align="center" border="0" cellpadding="0" cellspacing="0" width="650"> 
<tr valign="top"> 
<td colspan="2"> 
<span class="tabs tabsSelected" id="tab1" onclick="panel(1)">Rename Computers for Testing</span> 
<span class="tabs tabsNotSelected" id="tab2" onclick="panel(2)">Rename Computers back from Testing</span>
<!-- Tab 1 -->
<div class="panel" id="panel1" style="display:block"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<td style="text-align:right;font-size:0.9em;font-weight:bold;font-style:oblique;color:#888888;">
				Created by Gabriel Clifton
			</td>
		</tr>
	</table>
<!--Add your controls here-->
<select size="1" onChange="TestSub" name="selRenameTo" id="selRenameTo"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll" value="Check All" onclick="Check_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="uchckAll" value="Un-Check All" onclick="UNCheck_M_All(document.myform.checkNum)">
        </td>
        <td>
        	<input type="button" name="RenameTo" value="Rename To" onclick="RenameTo(document.myform.checkNum)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform" method="post">
            <span  id="instPath"></span>
        </font></form>
    </TH>
    </tr>
 </table>
  <table>
 	<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>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

<!-- Tab 2 -->
<div class="panel" id="panel2" style="display:none"> 
<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="6" 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>
</table>

	<table style="width:100%;">
		<tr>
			<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>

<!--Add your controls here-->
<select size="1" onChange="TestSub2" name="selRenameFrom" id="selRenameFrom"> 
</select>

 <br><br>
 <table border="0" width="100%">
    <tr width="100%">
        <TH colspan="3" width="100%" height="3" align="center"><font color="white" size="5"><B>Computers to rename back</font></B></TH>
    </tr>

    <tr>
        <td>
        	<input type="button" name="chckAll2" value="Check All" onclick="Check_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="uchckAll2" value="Un-Check All" onclick="Uncheck_M_All(document.myform2.checkNum2)">
        </td>
        <td>
        	<input type="button" name="RenameFrom" value="Rename From" onclick="RenameFrom(document.myform2.checkNum2)">
        </td>
    </tr>
 </table>
 <table border="1" width="100%">
    <tr border=1>
    <TH width="50%" height="35" align="left"><font color="white">
        <form name="myform2" method="post">
            <span  id="instPath2"></span>
        </font></form>
    </TH>
    </tr>
 </table>
 <table>
 	<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>
 <!--{{InsertControlsHere}}-Do not remove this line-->

</div> 

</body> 
</html>

Open in new window

0
 
Gabriel CliftonNet AdminAuthor Commented:
I am having an issue at line 408 "For i = 0 TO checkNum2.Length - 1" Error: Object doesn't support this property or method: 'checkNum2.length'

Every time I go through it I think I see the problem and adjust, but that makes it worse, undo and try again.

The timing on this happens to be great. We are starting the state testing on Monday and I will be using the Rename to Testing Scheme today. Hopefully the rename from next week.
0
 
Gabriel CliftonNet AdminAuthor Commented:
I have tried the last modified version and still had issues, so I rewrote the second tab to mirror the first tab and so far having good success. I have been out at a conference so I have not tested it as thoroughly as I want yet.
0
 
RobSampsonCommented:
I'm not sure why you had to rewrite the second tab, or what was different from your new code to the old one, but I'm glad it is working.  Let me know if you have any more issues.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.