Jump to content


Damien

Frontend HTA issue

Recommended Posts

I have the below HTA, This HTA was used in a different domain and now I want to impliment that in my test lab. which collect information like PC name, computer description, OU...etc at the PXE stage. the issue is i am getting an error when the HTA loads up at the beging of the task sequence

Line 71

Char:1

error: invalid syntax

code:0

 

if I say continue I get another error

 

Line :110

Char:5

error: Object required: objCommand

code:0

 

if I click continue the HTA loads up but computer sites, floor within sites and laptop model fields won't populate. I have pasted the saurce. can someone please help me with this?

 

< html>

< head>

< title>Workstation Deployment</title>

< HTA:APPLICATION

ID="objDEPLOYMENT"

APPLICATIONNAME="DEPLOYMENT"

SCROLL="no"

SINGLEINSTANCE="yes"

WINDOWSTATE="MAXIMIZED"

MaximizeButton = "no"

MinimizeButton = "no"

CloseButton = "no"

SysMenu = "no"

>

<style type="text/css">

.style2

{

font-size: medium;

font-weight: bold;

}

.style3

{

height: 54px;

}

.style4

{

}

.style5

{

height: 52px;

}

.style7

{

}

.style9

{

width: 235px;

}

.style10

{

}

.style11

{

width: 200px;

}

.style12

{

width: 250px;

}

</style>

< /head>

< SCRIPT LANGUAGE="VBScript">

'**Start Encode**

strDomainName = "DJ"

strDomainMaster = strDomainName & "\administrator"

strDomainMasterPwd = "password"

strDomainController = "DJDC"

strMainCompOU = "OU=" & strDomainName & " Computers,DC=" & strDomainName & ",DC=DJ,DC=LOCAL"

strLapUtilOU = "OU=Laptop Utils,OU=Application Groups,OU=" & strDomainName & " Groups,DC=" & strDomainName & ",DC=DJ,DC=LOCAL"

Const ADS_SCOPE_SUBTREE = 2

Const ADS_SECURE_AUTHENTICATION = 1

Const ADS_SERVER_BIND = 200

Set objShell = CreateObject("Wscript.Shell")

objShell.regWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1\1406", 0, "REG_DWORD"

objShell.regWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\3\1406", 0, "REG_DWORD"

 

Set objDomain = GetObject("LDAP:").OpenDSObject("LDAP://" & strDomainController & "/DC=" & strDomainName & ",DC=DJ,DC=LOCAL" , strDomainMaster , strDomainMasterPwd ,ADS_SECURE_AUTHENTICATION + ADS_SERVER_BIND)

Set objConnection = CreateObject("ADODB.Connection")

Set objCommand = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"

objConnection.Properties("User ID") = strDomainMaster

objConnection.Properties("Password") = strDomainMasterPwd

objConnection.Properties("Encrypt Password") = TRUE

objConnection.Properties("ADSI Flag") = ADS_SERVER_BIND Or ADS_SECURE_AUTHENTICATION

objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000

objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

 

Sub CheckKeys

If window.event.altKey And window.event.keyCode = 115 then

Call alert("please do not close this window")

document.parentwindow.event.keyCode = 0

document.parentwindow.event.cancelBubble = true

document.parentwindow.event.returnvalue = false

End If

End Sub

Sub Window_onload

'On Error Resume Next

Dim objProgressUI

Dim arrSitesName()

Dim arrSitesDesc()

 

Set objProgressUI = CreateObject("Microsoft.SMS.TsProgressUI")

objProgressUI.CloseProgressDialog

window.resizeTo 800,600

Set dropdownNode = document.createElement("OPTION")

dropdownNode.Text = "Select a computer site"

dropdownNode.Value = ""

ctrlComputerSite.Add(dropdownNode)

 

objCommand.CommandText = "SELECT name FROM 'LDAP://" & strDomainController & "/" & strMainCompOU & "' WHERE objectCategory='organizationalUnit'"

Set objRecordSet = objCommand.Execute

i = 0

 

If objRecordSet.EOF then

Set dropdownNode = document.createElement("OPTION")

dropdownNode.Text = "No sites have been found"

ctrlComputerSite.Add(dropdownNode)

Else

objRecordSet.MoveFirst

Do Until objRecordSet.EOF

strOUName = objRecordSet.Fields("name").Value

If Len(strOUName) > 3 then

objRecordSet.MoveNext

Else

i = i + 1

objRecordSet.MoveNext

End If

Loop

 

ReDim arrSitesName(i)

ReDim arrSitesDesc(i)

 

i = 0

 

objCommand.CommandText = "SELECT name, description FROM 'LDAP://" & strDomainController & "/" & strMainCompOU & "' WHERE objectCategory='organizationalUnit'"

Set objRecordSet = objCommand.Execute

objRecordSet.MoveFirst

Do Until objRecordSet.EOF

strOUName = objRecordSet.Fields("name").Value

If Len(strOUName) > 3 then

objRecordSet.MoveNext

Else

arrSitesName(i) = strOUName

If IsNull(objRecordSet.Fields("description").Value) Then

strDesc = ""

Else

For Each strDesc in objRecordSet.Fields("description").Value

If strDesc = "" then

Exit For

Else

arrSitesDesc(i) = strDesc

End If

Next

End If

i = i + 1

objRecordSet.MoveNext

End If

Loop

End If

d = 0

Do While d < i

Set dropdownNode = document.createElement("OPTION")

dropdownNode.Text = arrSitesName(d) & " - " & arrSitesDesc(d)

dropdownNode.Value = arrSitesName(d)

ctrlComputerSite.Add(dropdownNode)

d = d + 1

 

Loop

End Sub

Sub Update_ctrlSiteFloor

On Error Resume Next

For Each dropdownNode in ctrlSiteFloor.Options

dropdownNode.RemoveNode

Next

 

strComputerSite = ctrlComputerSite.value

 

If strComputerSite = "" Then

Set dropdownNode = document.createElement("OPTION")

dropdownNode.Text = "Loading....."

dropdownNode.Value = ""

ctrlSiteFloor.Add(dropdownNode)

intErrResult = MsgBox("You have not selected a computer site. Please select a computer site before proceeding",48,"Computer Site not Defined")

Exit Sub

End If

strSiteOU = "LDAP://" & strDomainController & "/OU=" & strComputerSite & "," & strMainCompOU

i = 0

 

Set dropdownNode = document.createElement("OPTION")

dropdownNode.Text = "Select a Site Floor"

dropdownNode.Value = ""

ctrlSiteFloor.Add(dropdownNode)

 

objCommand.CommandText = "SELECT name FROM '" & strSiteOU & "' WHERE objectCategory='organizationalUnit'"

Set objRecordSet = objCommand.Execute

 

If objRecordSet.EOF then

Set dropdownNode = document.createElement("OPTION")

dropdownNode.Text = "No sites have been found"

ctrlComputerSite.Add(dropdownNode)

Else

objRecordSet.MoveFirst

i = 0

Do Until objRecordSet.EOF

strOUName = objRecordSet.Fields("name").Value

If InStr("Desktop", strOUName) <> 0 or InStr("Laptop", strOUName) <> 0 or strOUName = strComputerSite then

objRecordSet.MoveNext

Else

Set dropdownNode = document.createElement("OPTION")

dropdownNode.Text = strOUName

dropdownNode.Value = strOUName

ctrlSiteFloor.Add(dropdownNode)

i = 1

objRecordSet.MoveNext

End If

Loop

 

If i <> 1 then

For Each dropdownNode in ctrlSiteFloor.Options

dropdownNode.RemoveNode

Next

Set dropdownNode = document.createElement("OPTION")

dropdownNode.Text = "Site has no floors"

dropdownNode.Value = "N/A"

ctrlSiteFloor.Add(dropdownNode)

End If

End If

End Sub

Sub Update_LaptopModel

On Error Resume Next

For Each dropdownNode in ctrlLaptopMod.Options

dropdownNode.RemoveNode

Next

 

strComputerType = ctrlComputerType.value

 

If strComputerType = "" then

Set dropdownNode = document.createElement("OPTION")

dropdownNode.Text = "Loading....."

dropdownNode.Value = ""

ctrlLaptopMod.Add(dropdownNode)

intErrResult = MsgBox("You have not selected a computer type. Please select a computer type before proceeding",48,"Computer Type not Defined")

Exit Sub

End If

 

If strComputerType = "Desktop" then

Set dropdownNode = document.createElement("OPTION")

dropdownNode.Text = "Desktop has been selected"

dropdownNode.Value = "NA"

ctrlLaptopMod.Add(dropdownNode)

Else

objCommand.CommandText = "SELECT Name FROM 'LDAP://" & strDomainController & "/" & strLapUtilOU & "' WHERE objectCategory='group'"

Set objRecordSet = objCommand.Execute

 

If objRecordSet.EOF Then

Set dropdownNode = document.createElement("OPTION")

dropdownNode.Text = "No Laptop Models have been identified"

ctrlLaptopMod.Add(dropdownNode)

Else

objRecordSet.MoveFirst

Do Until objRecordSet.EOF

strGroupName = objRecordSet.Fields("Name").Value

strGroupDesc = Mid(strGroupName, 5)

intTempLen = Len(strGroupDesc)

strGroupDesc = Left(strGroupDesc, intTempLen - 13)

Set dropdownNode = document.createElement("OPTION")

dropdownNode.Text = strGroupDesc

dropdownNode.Value = strGroupName

ctrlLaptopMod.Add(dropdownNode)

objRecordSet.MoveNext

Loop

End If

End If

End Sub

Sub RunScript

On Error Resume Next

Set objTS = CreateObject("Microsoft.SMS.TSEnvironment")

Set objFSO = CreateObject("Scripting.FileSystemObject")

strComputerType = ctrlComputerType.value

strComputerName = ctrlComputerName.value

strComputerSite = ctrlComputerSite.value

strSiteFloor = ctrlSiteFloor.value

strDomainAccount = strDomainName & "\" & ctrlAccountUserName.value

strDomainPassword = ctrlAccountPassword.value

 

Set objDomain = GetObject("LDAP:").OpenDSObject("LDAP://" & strDomainController & "/DC=" & strDomainName & ",DC=WA,DC=GOV,DC=AU" , strDomainAccount , strDomainPassword ,ADS_SECURE_AUTHENTICATION + ADS_SERVER_BIND)

Set objConnection = CreateObject("ADODB.Connection")

Set objCommand = CreateObject("ADODB.Command")

objConnection.Provider = "ADsDSOObject"

objConnection.Properties("User ID") = strDomainAccount

objConnection.Properties("Password") = strDomainPassword

objConnection.Properties("Encrypt Password") = TRUE

objConnection.Properties("ADSI Flag") = ADS_SERVER_BIND Or ADS_SECURE_AUTHENTICATION

objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000

objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

 

If err.number <> 0 then

intErrResult = MsgBox("You have supplied an invalid Username or Password. Please check your Username & Password and try again.",16,"Supplied credentials invalid")

Exit Sub

End If

 

If strSiteFloor = "N/A" Then

strDomainOU = "LDAP://OU=" & strComputerType & ",OU=" & strComputerSite & ",OU=" & strDomainName & " COMPUTERS,DC=" & strDomainName & ",DC=DJ,DC=LOCAL"

Else

strDomainOU = "LDAP://OU=" & strComputerType & ",OU=" & strSiteFloor & ",OU=" & strComputerSite & ",OU=" & strDomainName & " COMPUTERS,DC=" & strDomainName & ",DC=WA,DC=GOV,DC=AU"

End If

 

strLaptopMod = ctrlLaptopMod.value

strComputerDesc = ctrlComputerDesc.value

strServiceDeskJob = ctrlServiceDeskJob.value

strFQDN = strDomainName & ".wa.gov.au"

strPreviousCompName = ctrlPreviousComputerName.value

 

i = 1

 

Do While i < 8

Select Case i

 

Case 1

If strComputerName = "" Then

intErrResult = MsgBox("You have not entered a computer name. Please enter a computer name before proceeding",48,"Computer name not Defined")

Exit Sub

Else

'If strComputerType = "Desktop" then

' If InStr(strComputerName, "PCD") = 0 Or InStr(strComputerName, "SV") = 0 then

' intErrResult = MsgBox("You have not entered a valid computer name. Please enter a valid computer name before proceeding",48,"Computer name not valid")

' Exit Sub

' End If

'End If

End If

i = i + 1

 

Case 2

If strComputerType = "" Then

intErrResult = MsgBox("You have not selected a computer type. Please select a computer type before proceeding",48,"Computer Type not Defined")

Exit Sub

End If

i = i + 1

 

Case 3

If strComputerSite = "" Then

intErrResult = MsgBox("You have not selected a computer site. Please select a computer site before proceeding",48,"Computer Site not Defined")

Exit Sub

End If

i = i + 1

 

Case 4

If strDomainName = "" Then

intErrResult = MsgBox("You have not selected a PTA Domain. Please select a PTA Domain before proceeding",48,"Domain not Defined")

Exit Sub

End If

i = i + 1

 

Case 5

If strDomainAccount = strDomainName & "\" Then

intErrResult = MsgBox("You have not entered your username. Please enter your username before proceeding",48,"Username not Defined")

Exit Sub

End If

i = i + 1

 

Case 6

If strDomainPassword = "" Then

intErrResult = MsgBox("You have not entered your password. Please enter your password before proceeding",48,"Password not Defined")

Exit Sub

End If

i = i + 1

 

Case 7

If strComputerDesc = "" Then

intErrResult = MsgBox("You have not entered a computer description. Please enter a computer description before proceeding",48,"Computer Description not Defined")

Exit Sub

End If

i = i + 1

 

End Select

Loop

 

objTS("OSDDomainName") = strFQDN

objTS("OSDDomainOUName") = strDomainOU

objTS("OSDJoinAccount") = strDomainAccount

objTS("OSDJoinPassword") = strDomainPassword

objTS("OSDNetworkJoinType") = "0"

objTS("OSDJoinSkipReboot") = "false"

objTS("OSDComputerName") = strComputerName

Set objTxtWrite = objFSO.CreateTextFile("Y:\temp\" & strComputerName & ".txt")

objTxtWrite.WriteLine(strDomainOU)

objTxtWrite.WriteLine(strLaptopMod)

objTxtWrite.WriteLine(strDomainAccount)

objTxtWrite.WriteLine(strComputerDesc)

objTxtWrite.WriteLine(strServiceDeskJob)

objTxtWrite.WriteLine(strPreviousCompName)

objTxtWrite.WriteLine(strSiteFloor)

objTxtWrite.Close

 

window.close

End Sub

< /SCRIPT>

< body onkeydown="CheckKeys()">

<font face="Tahoma"><center>

<table width=100%>

<tr bgcolor="#2C7993" height=50>

<td>

<font color="#FFFFFF" face="Tahoma"><center class="style2">

Public Transport Authority System Centre Configuration Manager 2007 Image Deployment (CMR)</center></font>

</td>

</tr>

<tr height=50>

<td>

Please enter the details for this new computer</td>

</tr>

</table>

<table width=100%>

<tr>

<td class="style9">

Computer Name:

</td>

<td class="style12">

<input type="text" id="ctrlComputerName" name="ctrlComputerName" size="30" title="Enter the computer name. Example: PC100001">

</td>

<td class="style11">

Service<font face="Tahoma"> Desk Job #:</font></td>

<td>

<font face="Tahoma">

<input id="ctrlServiceDeskJob" name="ctrlServiceDeskJob" type="text" size="30"/></font></td>

</tr>

<tr>

<td class="style9">

<font face="Tahoma">Previous PC Name:</font></td>

<td class="style12">

<font face="Tahoma">

<input id="ctrlPreviousComputerName" name="ctrlPreviousComputerName" size="30"

type="text" value="N/A" /></font></tr>

<td class="style10">

 </tr>

<td class="style10">

 </tr>

<tr>

<td class="style9">

<font face="Tahoma">Computer Site:</font></td>

<td class="style12">

<font face="Tahoma">

<select id="ctrlComputerSite" name="ctrlComputerSite" onchange="Update_ctrlSiteFloor">

</select></font></tr>

<td>

<font face="Tahoma">Computer Type:</font></tr>

<td>

<font face="Tahoma">

<select id="ctrlComputerType" name="ctrlComputerType" onchange="Update_LaptopModel">

<option selected>Select a computer type</option>

<option value="Desktop">Desktop</option>

<option value="Laptop">Laptop</option>

</select></font></tr>

<tr>

<td class="style9">

<font face="Tahoma">Floor within Site:</font></td>

<td class="style12">

<font face="Tahoma">

<select id="ctrlSiteFloor" name="ctrlSiteFloor" title="Only to be used for PTC, CIT and CLA Sites">

<option>Loading.....</option>

</select></font></td>

<td>

<font face="Tahoma">Laptop Model:</font></td>

<td>

<font face="Tahoma">

<select id="ctrlLaptopMod" name="ctrlLaptopMod" title="Only to be used if machine is a laptop">

<option>Loading.....</option>

</select></font></td>

</tr>

<tr>

<td class="style4" colspan="4">

<hr />

</td>

</tr>

<tr>

<td class="style5" colspan="4">

Please enter a description of this computer:</td>

</tr>

<tr>

<td class="style9">

Computer Description:</td>

<td colspan="3">

<input id="ctrlComputerDesc" name="ctrlComputerDesc" type="text" size="60" /></td>

</tr>

<tr>

<td class="style7" colspan="4">

<font face="Tahoma">

<hr />

</font>

</td>

</tr>

<tr>

<td class="style3" colspan="4">

Please enter your admin account details to join this machine to the domain.</td>

</tr>

<tr>

<td class="style9">

User Name: </td>

<td colspan="3">

<input id="ctrlAccountUserName" name="ctrlAccountUserName" type="text" size="30" title="Enter your User Name. Example: wex103761a"/></td>

</tr>

<tr>

<td class="style9">

Password:</td>

<td colspan="3">

<input id="ctrlAccountPassword" name="ctrlAccountpassword" type="password" size="30" title="Enter your Password."/></td>

</tr>

</table>

<table width=100%>

<tr>

<td height=80>

<font face="Tahoma">

<center><input id=runbutton class="button" type="button" value="OK" name="run_button" onclick="RunScript"></center>

</font>

</td>

</tr>

</table>

</center></font>

< /body>

Share this post


Link to post
Share on other sites

you need to point it to whatever OU's are applicable in your environment so either create those OU's or adapt (change) the string to match your environment

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.