Hello,
I have 2 VBscript that I have combined into a HTA that has over 2,500 lines. The HTA works perfectly from joining to domain, install printers and software, etc. The issue I am having is that both are calling to have window_onload, so with both having a subroutine for windows_onload one is canceling out. Below is the script that I have copied out of the HTA. The first script pulls user logged on information and the OU for which the computer belongs to.The second script loads the software to be installed. How can I combine both script that require to run on load to make both of them work at the sametime or load and work at the sametime?
''''''''''''''''''''''''''''''''''''''''''''''''Loads OU info''''''''''''''''''''''''''''''''''''<script language="VBScript">
Dim FSO, oShell, oNetwork, objSysInfo, sUserDN, objUser
Dim sDepartment, sUserName, sComputerName, sDomain, sDisplayName, sGroups, sDN
Dim sStatus, intSeconds, sDesktop, sScriptDir, iTimerID
sDN = "ms.com"
Sub Window_onLoad
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
Set oNetwork = CreateObject("WScript.Network")
UserInfo
sDesktop = oShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Desktop\"
document.title = sDomain & " & Techs " & sDepartment & " OU"
DisplayName.InnerHTML = sDisplayName
UserName.InnerHTML = sUserName
ComputerName.InnerHTML = sComputerName
HTA = location.pathname
HTA_Path = Left(HTA,InStrRev(HTA,"\"))
If FSO.FileExists(HTA_Path & "logo-" & sDepartment & ".gif") Then
Logo.src = "logo-" & sDepartment & ".gif"
Else
Logo.src = "logo-default.gif"
End If
Me.MoveTo 10,10
MainScript
'Countdown timer before closing. Set time in seconds.
'intSeconds = 5
'iTimerID = window.setInterval("Count", 8000)
End Sub
Sub Default_Buttons
If Window.Event.KeyCode = 13 Then
End If
End Sub
Sub UserInfo
On Error Resume Next
Dim arrDept
Set objSysInfo = CreateObject("ADSystemInfo")
sUserDN = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & sDN & "/" & sUserDN)
sUserName = oNetwork.UserName
sComputerName = UCase((oNetwork.ComputerName))
sDomain = UCase((oNetwork.UserDomain))
sDisplayName = trim(objUser.DisplayName)
sGroups = GetGroups(sUserDN)
arrDept = split(sUserDN, ",")
sDepartment = mid(arrDept(2), 4) 'Set number in array where department OU name is found.
'ie: CN=UserName,OU=Users,OU=Department,DC=your,DC=domain,DC=com; arrDept(2) = OU=Department
If sDisplayName = "" Then
sDisplayName = sUserName
End If
Err.Clear
Set objSysInfo = Nothing
Set objUser = Nothing
End Sub</script>
'''''''''''''''''''''''''''''''''''''Loads software to be installed.''''''''''''''''''''''''''''''''''''''''''''''''''''''
<script language="VBScript">
Dim arrSoftware
Sub window_onload
'intWidth = 800
'intHeight = 600
'Me.ResizeTo intWidth, intHeight
'Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
arrSoftware = Array(_"china;Office Products;Office 2010 With Access;\\server01/office.exe", _"china;Office Products;Office 2010 No Access;\\server01/office.exe")
Populate_Office
End Sub
Sub Populate_Office
strHTML = "<select size='1' name='cbo_office' onchange='vbs:Populate_SoftwareType'>" & VbCrLf
strHTML = strHTML & "<option selected value='cbo_office'> --- Select Office --- </option>" & vbCrLf
strOffices = ";"
For Each strProduct In arrSoftware
strOffice = Split(strProduct, ";")(0)
If InStr(LCase(strOffices), LCase(";" & strOffice & ";")) = 0 Then
strOffices = strOffices & strOffice & ";"
strHTML = strHTML & "<option value='" & strOffice & "'>" & strOffice & "</option>" & VbCrLf
End If
Next
strHTML = strHTML & "</select>"
span_office.InnerHTML = strHTML
End Sub
Sub Populate_SoftwareType
strHTML = "<select size='1' name='cbo_softwaretype' onchange='vbs:Populate_Application'>" & VbCrLf
strHTML = strHTML & "<option selected value='cbo_softwaretype'> --- Select Software Type --- </option>" & VbCrLf
strTypes = ";"
For Each strProduct In arrSoftware
If LCase(Split(strProduct, ";")(0)) = LCase(cbo_office.Value) Then
strType = Split(strProduct, ";")(1)
If InStr(LCase(strTypes), LCase(";" & strType & ";")) = 0 Then
strTypes = strTypes & strType & ";"
strHTML = strHTML & "<option value='" & strType & "'>" & strType & "</option>" & VbCrLf
End If
End If
Next
strHTML = strHTML & "</select>"
span_softwaretype.InnerHTML = strHTML
End Sub
Sub Populate_Application
strHTML = "<select size='1' name='cbo_application'>" & VbCrLf
strHTML = strHTML & "<option selected value='cbo_application'> --- Select Application --- </option>" & VbCrLf
For Each strProduct In arrSoftware
If LCase(Split(strProduct, ";")(0)) = LCase(cbo_office.Value) And LCase(Split(strProduct, ";")(1)) = LCase(cbo_softwaretype.Value) Then
strApplication = Split(strProduct, ";")(2)
strFilePath = Split(strProduct, ";")(3)
strHTML = strHTML & "<option value='" & strApplication & ";" & strFilePath & "'>" & strApplication & "</option>" & VbCrLf
End If
Next
strHTML = strHTML & "</select>"
span_application.InnerHTML = strHTML
End Sub
Sub Default_Buttons
If Window.Event.KeyCode = 13 Then
btn_install.Click
End If
End Sub
Sub Install_Software
strLogFile = "\\server01\software logs\HTA_Install_Log.csv"
Const intForAppending = 8
If cbo_office.Value = "cbo_office" Then
MsgBox "Please select an office."
cbo_office.Focus
ElseIf cbo_softwaretype.Value = "cbo_softwaretype" Then
MsgBox "Please select a software type."
cbo_softwaretype.Focus
ElseIf cbo_application.Value = "cbo_application" Then
MsgBox "Please select an application."
cbo_application.Focus
Else
strProduct = Split(cbo_application.Value, ";")(0)
strExecutable = Split(cbo_application.Value, ";")(1)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objNetwork = CreateObject("WScript.Network")
'Software file,Machinename,Username,Date and time
strDetails = strExecutable & "," & objNetwork.ComputerName & "," & objNetwork.UserName & "," & Now
If objFSO.FileExists(strExecutable) = True Then
'objShell.Run strExecutable
If LCase(Right(strExecutable, 4)) = LCase(".msi") Then
strCommand = "msiexec /i " & objFSO.GetFile(strExecutable).ShortPath & " /qf /norestart"
Else
strCommand = "cmd /c """ & objFSO.GetFile(strExecutable).ShortPath & """"
End If
'MsgBox "Installing: " & strProduct & VbCrLf & "From:" & VbCrLf & strExecutable & VbCrLf & "With: " & strCommand
strExitCode = objShell.Run(strCommand, 1, True)
If Left(strCommand, 7) = "msiexec" And strExitCode = 1619 Then
MsgBox "You do not have permission to install this application." & VbCrLf & "Please contact the Help Desk."
ElseIf Left(strCommand, 6) = "cmd /c" And strExitCode = 1 Then
MsgBox "You do not have permission to install this application." & VbCrLf & "Please contact the Help Desk."
End If
Set objOutputFile = objFSO.OpenTextFile(strLogFile, intForAppending, True)
objOutputFile.WriteLine strDetails
objOutputFile.Close
Set objOutputFile = Nothing
Else
MsgBox "The file does not exist, or you do not have permission to access it." & VbCrLf & "Please contact the Help Desk."
End If
Set objShell = Nothing
Set objFSO = Nothing
Set objNetwork = Nothing
End If
End Sub</script>here is a picture of the HTA. At the top it should populate the info and as you can see it is blank.