← Archive
article· jaw

Creating the ultimate SCCM 2007 Frontend HTA for OSD Part III

htaosdsccm

Now for the guts of the HTA the VBscript that makes all the magic happen.  Check comments for more info. Ok here's the whole thing with the functions. You will want to modify several parts to meet your configuration. The go() function is what does most of the work. You will want to update the part that builds the LDAP string to match your AD setup. You will also need to setup the first dropdown box with the right values to load the site names from text files. You can create the text files by right clicking on the container in AD users and computers and selecting export to list. Check that you are building the LDAP string properly by selecting the ou you want in the config manager console - join domain panel. I left some of my workstation name validation intact but you will have to change it to work with your naming standard or just take it out. You can copy and modify the script all you want, sorry if it's a little confusing I kept adding features.
If you need some help modifying the code leave  a comment, I'd be happy to help.
----------------------------
<HTML>
<HEAD>
<TITLE>Ultimate HTA / Outil de configuration Supreme</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<!--
 **********************************************************************
                     Ultimate HTA
 ----------------------------------------------------------------------
 By: Jaw
 www.jawtech.com
You can take all the credit if you think you can pull it off, or leave my link in.
 **********************************************************************

----not going to use this but leaving it as example of how to use css and js files
<link rel="stylesheet" type="text/css" href="english.css" title="eng" />
<link rel="alternate stylesheet" type="text/css" href="francais.css" title="fra" />
<script type="text/javascript" src="styleswitcher.js"></script>
------------------------------------------------------------------------
-->
<HTA:APPLICATION
     ID="HTA"
     APPLICATIONNAME="Ultimate HTA"
     SCROLL = "NO"
     SINGLEINSTANCE = "YES"
     WINDOWSTATE = "NORMAL"
     BORDER = "THIN"
     SHOWINTASKBAR = "YES"
     MAXIMIZEBUTTON = "NO"
     MINIMIZEBUTTON = "NO"
     SHOWINTASKBAR = "YES"
>

</HEAD>

<SCRIPT Language="VBScript"  >
 dim province, site, timezone, daylight, updates, lang, LDAP,KB,errmsg,err,lasterr
 on error resume next
 
Sub Window_Onload
'read command line and check to see if "fra" was passed if yes launch hta in French.
'This can be set in the task sequence to control default behavior
'Set the hidden var for the javascipt styleswitcher
lang2 = right(HTA.commandline,4)
lang2 = left(lang2,3)
if lang2 = "fra" then
 langvar.value = "fra"
 fra.click()
else
langvar.value = "eng"
end if
'resize the window
 window.resizeTo 720,530
 window.moveTo 5,5
'suppress ts error debuging close the progress window
on error resume next
 Set ProgressUI = CreateObject("Microsoft.SMS.TsProgressUI")  
ProgressUI.CloseProgressDialog
'populate the description field
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objWMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 
' get service tag and computer manufacturer
 For Each objSMBIOS in objWMI.ExecQuery("Select * from Win32_SystemEnclosure")
 serviceTag = replace(objSMBIOS.SerialNumber, ",", ".")
 manufacturer = replace(objSMBIOS.Manufacturer, ",", ".")
 Next
 
' get computer model
 For Each objComputer in objWMI.ExecQuery("Select * from Win32_ComputerSystem")
 model = trim(replace(objComputer.Model, ",", "."))
 Next
 
description.value =  manufacturer & " " & model & " - " & serviceTag 

end sub

function cmd()
 Set objShell = CreateObject("Wscript.Shell")
 objShell.Run "cmd.exe /k"
 
end function
function ps()
msgbox "This will be enabled when SCCM 2007 can support winPE 4.0"
' Set objShell = CreateObject("Wscript.Shell")
' objShell.Run "powershell.exe"
end function
function tzchg()
 
 if  tz(2).checked = true then
  timezone = "Eastern Standard Time"
 elseif tz(0).checked = true then
  timezone = "Atlantic Standard Time"  
 elseif tz(3).checked = true then
  timezone = "Central Standard Time"
  elseif tz(5).checked = true then
  timezone = "Pacific Standard Time"
  elseif tz(4).checked = true then
   timezone = "Mountain Standard Time"
 elseif tz(4).checked = true   then
   timezone = "Mountain Standard Time"
 elseif tz(1).checked = true  then
   timezone = "Atlantic Standard Time"
 end if
 end function
 
function tzSel(divi)
 province = divi
 select case divi
 case "ON", "QC"
  tz(2).checked = true
  timezone = "Eastern Standard Time"
 case "BC"
  tz(6).checked = true
  timezone = "Pacific Standard Time"  
 
 end select
end function
 
function divsel(divi)
 LoadListBox(divi)
 tzSel(divi)
end function
function LoadListBox(divi)
 Set objShell = CreateObject("WScript.Shell") 
 myCur = objShell.CurrentDirectory
 strFileName =  myCur &"\" & divi & ".txt"
 For Each objOption in Items.Options
  objOption.RemoveNode
 Next
 if divi <> "NA" then
  ForReading = 1
   Set objFSO = CreateObject("Scripting.FileSystemObject")
   Set objFile = objFSO.OpenTextFile(strFileName, 1)
   strItems = objFile.ReadAll
   objFile.Close
   arrItems = Split(strItems,vbNewLine)
    For Each strItem in arrItems   
     Set objOption = Document.createElement("OPTION")
     objOption.Text = strItem
     objOption.Value = strItem
     Items.Add(objOption)
    Next
end if 
end function
function clearform()
 workstationname.value = ""
 For Each objOption in Items.Options
  objOption.RemoveNode
 Next
 divi.selectedindex = 0
for count = 0 to 4
tz(count).checked = false
next
if langvar.value  = "eng" then
keyboard.checked = false
os.checked = false
end if
 
if langvar.value = "fra" then
keyboard.checked = true
os.checked = true
end if
patches.checked = false
end function
function go()
on error resume next
 SET env = CreateObject("Microsoft.SMS.TSEnvironment")
 'set computer name
 env("OSDComputerName") = workstationname.Value
 '*************************************************
 
 env("SMSRebootMessage") = "Hang on for a reboot"
 env("SMSRebootTimeout") = 3
 
 '***************************************************
 
 'Set updates now yes or no
 if patches.checked = true then
  Updates = "true"
 else
  Updates = "false"
 end if
 env("DoUpdates") = Updates
'***************************************************

'Set description variable
env("Desc") = description.value 
 
 'Set timezone
 env("OSDTimeZone") = timezone
'***************************************************
 'Set province Set OU
 province = divi.value
 select case province
 case "ON" ,"BC","QC"
  LDAP= "LDAP://OU=Workstations,OU=" & Items.value & ",OU=" & province & ",DC=mydomain,DC=com"
 case "NA"
 msgbox "Computer will be placed in the unknow computers container"
 LDAP = ""
 end select
 env("OSDDomainOUName") = LDAP
 env("LDAP") = LDAP
'***************************************************
 'Set language
 if os.checked = false   then
  langf = "eng.xml"
  end if
 
 
 if os.checked = true   then
  langf = "fra.xml"
  end if
  
 
if os.checked = false   then
  lang = "eng"
else
lang = "fra" 
  end if
 
if keyboard.checked = false   then
  kb = "eng"
else
kb = "fra" 
  end if
   env("lang-file") = langf
  env("kb") = kb
  env("lang") = lang
 '***************************************************
 
 
 'validate name
 workstationname.value = Ucase(ltrim(rtrim(workstationname.value)))
 
 if validateName(workstationname.value) then
  'show summary
  ret = msgbox( "Workstation Name:" & VBCRLF & workstationname.value & VBCRLF & "Description:" & description.value & VBCRLF & "language:" & lang & VBCRLF & "keyboard:" _
& kb & vbcrlf  &  "join location:" & VBCRLF & LDAP & VBCRLF & "timezone:" & timezone & VBCRLF & "Do updates now:" _
& updates & VBCRLF & "Validation errors:" & lasterr & VBCRLF &"Deployment start:" & now & VBCRLF & VBCRLF & VBCRLF & "Proceed with deployment?",4,"Summary")
  'clicked yes close windows and proceed if no...do nothing.
 if ret = 6 then
  window.close()
 env("OSDComputerName") =workstationname.value
  end if
 end if ' valid name
 
''''''''''proceeding with the deployment try and write a log this doesn't seem to work on the target os...still working on it
Set objFSO=CreateObject("Scripting.FileSystemObject")
outFile="c:\Deployment HTA.log"
 Set objFileToWrite = objFSO.CreateTextFile(outFile,True)
 
data = "Workstation Name:" & workstationname.value
objFileToWrite.WriteLine(data)
data ="language:" & lang
objFileToWrite.WriteLine(data)
data ="keyboard:" & kb
objFileToWrite.WriteLine(data)
data ="join location:" & LDAP
objFileToWrite.WriteLine(data)
data = "timezone:" & timezone
objFileToWrite.WriteLine(data)
data ="Do updates now:" & updates
objFileToWrite.WriteLine(data)

data ="Validation errors:" & lasterr
objFileToWrite.WriteLine(data)
 
data ="Deployment start:" & now
objFileToWrite.WriteLine(data)
 
objFileToWrite.Close
Set objFileToWrite = Nothing
end function
 
function validateName(name)
lasterr =""     
if name = "" then
err = true
errmsg = errmsg & vbcrlf &  "Computername cannot be blank - Random name generated"
workstationname.value = province & (int(rnd() * 10)) & (int(rnd() * 10)) & (int(rnd() * 10)) & (int(rnd() * 10)) & (int(rnd() * 10)) & (int(rnd() * 10)) & (int(rnd() * 10)) &"D"
name = workstationname.value
end if
 if len(province) = 1 then
 if (left(name,1) <> province ) then
  err=true
 errmsg = errmsg & vbcrlf &  "First letter failed validation"
 end if
 end if 
 
 if right(name,1) = "L" OR right(name,1) = "D" OR right(name,1) = "T" OR instr(strreverse(name),"V") = 2 or instr(strreverse(name),"V") = 3 then
  else
  err = true
errmsg = errmsg & vbcrlf &  "Trailing device type incorrect."
 end if
if instr(name, " ") > 0 then
errmsg = errmsg & vbcrlf & "You cannot have spaces in the computer name. - Spaces removed"
 workstationname.value = replace(name," ","")
name = workstationname.value
err=true
end if
if len(name) > 15 then
errmsg = errmsg & vbcrlf &  "Computer name cannot be longer than 15 characters. - Name truncated"
 workstationname.value = mid(name,1,14)
name = workstationname.value
end if
 
if right(name,1) = "L" OR right(name,1) = "D" OR right(name,1) = "T" then
fin = len(name)
fin = fin - 2
 end if

if  instr(strreverse(name),"V") = 2  then
 fin = len(name)
fin = fin - 3
end if

if  instr(strreverse(name),"V") = 3  then
 fin = len(name)
fin = fin - 4
end if
 
if isnumeric(mid(name,2,fin)) then
else
 errmsg = errmsg & vbcrlf &  "Asset tags are generally numeric."
err=true
end if
 
if err = true then
  ret = msgbox( "Please verify workstation name. / SVP Vérifier convention d'énumération:" & vbcrlf & errmsg & vbcrlf & vbcrlf & vbcrlf & "Do you wish to proceed with the deployment?" , 1)
errmsg =   "IGNORED" & errmsg
 else
  ret = 1
 end if
 
if err = false then
errmsg = "No errors detected."
end if
 
 
 
 if ret = 1 then
  validateName = true
 else
  validateName = false
 end if
lasterr = errmsg
errmsg = ""
end function
</SCRIPT>
</HEAD>
<BODY>
<input type="hidden" id="langvar" name="langvar" value="eng">
 <hr>
 
<hr>
<p>

Location
 <select name="divi" onchange="divsel(divi.value)">
   <option value="NA">Unknown / inconnu</option>
   <option value="ON">Ontario</option>
   <option value="QC">Quebec</option>
   <option value="BC">British Columbia</option>
  </select> 
site  <SELECT name="Items"></SELECT>
<br /><br />
 Workstation Name: <INPUT class="form" type="text" size="65" name="workstationname">
 
<br />
 Description:
  <INPUT class="form" type="text" size="65" name="description">
 
 
<br /><br />
 <INPUT type="checkbox" id="os" name="os"> French Operating System<BR />
 <INPUT type="checkbox" id="keyboard" name="keyboard"> French Keyboard <BR />
   
  <INPUT type="checkbox" id="patches" name="patches">  Apply patches Immediately  <br>

<br />
  <INPUT type="radio" id="tz" name="tz" value="Newfoundland and Labrador Standard time" onchange="tzchg()" />Newfoundland and Labrador Standard time<BR />
  <INPUT type="radio" id="tz" name="tz" value="Atlantic Standard Time" onchange="tzchg()"  />Atlantic Standard Time<BR />
  <INPUT type="radio" id="tz" name="tz" value="Eastern Standard Time" onchange="tzchg()"  />Eastern Standard Time<BR />
  <INPUT type="radio" id="tz" name="tz" value="Central Standard Time" onchange="tzchg()"  />Central Standard Time<BR />
  <INPUT type="radio" id="tz" name="tz" value="Canada Central Standard Time" onchange="tzchg()"  />Canada Central Standard Time<BR />
  <INPUT type="radio" id="tz" name="tz" value="Mountain Standard Time" onchange="tzchg()"  />Mountain Standard Time<BR />
  <INPUT type="radio" id="tz" name="tz" value="Pacific Standard Time"  onchange="tzchg()" />Pacific Standard Time<BR />
<br />
 
 <input class="button" type="button" value="Clear Form Data" onclick="clearform()"> &nbsp;
 <input class="button" type="button" value="PowerShell Prompt" onclick="ps()"> &nbsp;
 <input class="button" type="button" value="Command Prompt" onclick="cmd()"> &nbsp;
 <input class="button" type="button" value="Save and Continue" onclick="go()">
 
 
</BODY>
</HTML>
 

Tags:

Restored from the original jawtech.com (archived copy). Links and downloads from that era may no longer work.