i haven't posted before, largely because i haven't had a real need for much VBScripting. Now i'm in a quandry and would like some assistance. Windows 7 install has grown to 2 DVDs. DVD 1 contains Win7 + Office 2010, DVD 2 contains drivers for various models of computers. All of this will fit on 1 16GB thumb drive. i've copied all files to 1 16GB thumb drive and it works, up to a point. i think i've narrowed it down to 1 .HTA file that uses WMI to find the DVD drive letter and status. i've modified a copy of the file to look for a USB drive (DriveType 2) but can't seem to get any farther than that. When i run it i either get code errors or the test system tells me to load DVD 2 and just sits there and looks at me, never getting beyond that point.
As i said, i'm not very good at VBScripting, and would like some assistance sorting this thing out and getting everything to run from 1 16GB thumb driver rather than mess around with swapping DVDs and such.
If someone would be kind enough to at least point me in the right direction i would be grateful.
Thanks,
Dave
As i said, i'm not very good at VBScripting, and would like some assistance sorting this thing out and getting everything to run from 1 16GB thumb driver rather than mess around with swapping DVDs and such.
Code:
<html>
<head>
<script>
window.resizeTo(396,158);
window.moveTo( Math.floor(screen.width-396)/2, Math.floor(screen.height-158)/2 );
</script>
<title>Windows 7 Wipe & Load</title>
<meta http-equiv="MSThemeCompatible"content="yes">
<HTA:APPLICATION ID="oHTA2"
APPLICATIONNAME="DVDExchange"
BORDER="thin"
BORDERSTYLE="normal"
CAPTION="yes"
ICON=""
INNERBORDER="no"
SELECTION="no"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="yes"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="no"
VERSION="1.0"/>
<style>
body {
margin: 0px;
overflow: hidden;
}
.bodyHeader {
font-family: Segoe UI,Verdana,Arial,Sans;
font-size: 24px;
color: #333333
}
.bodyText {
font-family: Segoe UI, MS Sans Serif, Sans-Serif;
font-size: 14px;
padding: 0 0 7 4;
color: #1370AB
}
#background {
background-color: gray;
}
.style1 {
border: 1px solid #000000;
background-color: #FFFFCC;
}
.style2 {
font-size: x-large;
}
.style3 {
font-size: large;
}
.style4 {
font-size: medium;
color: #333333
}
</style>
<script language="vbscript">
'<--START OF GLOBALS-->
Dim DrvLet
Dim Media
Dim Stmp1x86, Stmp1x64, Stmp2x86, Stmp2x64
Dim strArch
Dim strLogInfo
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Set oShell = CreateObject("WScript.Shell")
Set oFS = CreateObject("Scripting.FileSystemObject")
'<--END OF GLOBALS-->
'<--START OF SUBS-->
Sub Window_onload
On Error Resume Next
'Hide the TS progress bar
Set oTSProgressUI = CreateObject("Microsoft.SMS.TSProgressUI")
oTSProgressUI.CloseProgressDialog
'Create an MDT based log File
If oFS.FolderExists("C:\MININT\SMSOSD\OSDLOGS") Then
oFS.CreateTextFile("C:\MININT\SMSOSD\OSDLOGS\DVDExchange.log")
Else
oFS.CreateFolder "C:\MININT"
oFS.CreateFolder "C:\MININT\SMSOSD"
oFS.CreateFolder "C:\MININT\SMSOSD\OSDLOGS"
oFS.CreateTextFile("C:\MININT\SMSOSD\OSDLOGS\DVDExchange.log")
End If
strLogInfo = "DVD Exchange Wizard Started"
LogInfo()
GetDVDDrive()
GetDVDStatus()
'Set the ID File Locations
Stmp1x86 = DrvLet & "DVD1x86.ID"
Stmp2x86 = DrvLet & "DVD2x86.ID"
Stmp1x64 = DrvLet & "DVD1x64.ID"
Stmp2x64 = DrvLet & "DVD2x64.ID"
If (oFS.FileExists(Stmp1x86)) Then
strArch = "x86"
statusarea.innerhtml = "Please insert the x86 Drivers Disk into drive "& DrvLet
ElseIf (oFS.FileExists(Stmp1x64)) Then
strArch = "x64"
statusarea.innerhtml = "Please insert the x64 Drivers Disk into drive "& DrvLet
End If
NextButton.Disabled = False
EjectDVD(DrvLet)
End Sub
'<--END OF SUBS-->
'<--START OF MAIN PROCESSING-->
Function StartProcess1()
'Disable the Next button
NextButton.Disabled = True
'Get the drive status (True or False)
GetDVDStatus()
If strArch = "x86"Then
'Check for Disk ID 2 (x86) and run CACHE.vbs from it
If oFS.FileExists(Stmp2x86) Then
strLogInfo = "Windows 7 v3.x Wipe & Load x86 Drivers Disk was inserted in drive "& DrvLet
LogInfo()
statusarea.innerhtml = "Copying drivers. This may take up to 15 minutes..."
oShell.Run DrvLet & "CACHE.vbs", 1, True
statusarea.innerhtml = "Drivers successfully copied from x86 Drivers Disk"
strLogInfo = "CACHE.vbs completed copying files and returned control"
LogInfo()
StartProcess2()
If StartProcess2 = 0 Then
Set oShell = Nothing
Set oFS = Nothing
strLogInfo = "DVDExchange.hta exited - process completed"
LogInfo()
Window.close()
Exit Function
End If
'Check for any other disk and eject if present
Else
EjectDVD(DrvLet)
MsgBox "Please insert the x86 Drivers Disk into drive "& DrvLet,0,"Windows 7 Wipe & Load"
StartProcess1()
End If
ElseIf strArch = "x64"Then
'Check for Disk ID 2 (x64) and run CACHE.vbs from it
If oFS.FileExists(Stmp2x64) Then
strLogInfo = "Windows 7 Wipe & Load x64 Drivers Disk was inserted in drive "& DrvLet
LogInfo()
statusarea.innerhtml = "Copying drivers. This may take up to 15 minutes..."
oShell.Run DrvLet & "CACHE.vbs", 1, True
statusarea.innerhtml = "Drivers successfully copied from x64 Drivers Disk"
strLogInfo = "CACHE.vbs completed copying files and returned control"
LogInfo()
StartProcess2()
If StartProcess2 = 0 Then
Set oShell = Nothing
Set oFS = Nothing
strLogInfo = "DVDExchange.hta exited - process completed"
LogInfo()
Window.close()
Exit Function
End If
'Check for any other disk and eject if present
Else
EjectDVD(DrvLet)
MsgBox "Please insert the x64 Drivers Disk into drive "& DrvLet,0,"Windows 7 Wipe & Load"
StartProcess1()
End If
End If
End Function
Function StartProcess2()
On Error Resume Next
'Get the drive status (True or False)
GetDVDStatus()
If strArch = "x86"Then
'Check for Disk ID 1 (x86) and close the HTA to continue with the task sequence
If oFS.FileExists(Stmp1x86) Then
strLogInfo = "Disk 1 (x86) was re-inserted into drive "& DrvLet
LogInfo()
statusarea.innerhtml = "Task completed - deployment will now continue"
StartProcess2 = 0
Exit Function
'Check for any other disk and eject if present
Else
EjectDVD(DrvLet)
MsgBox "Please re-insert Disk 1 (x86) into drive "& DrvLet,0,"Windows 7 Wipe & Load"
StartProcess2 = 1
StartProcess2()
End If
ElseIf strArch = "x64"Then
'Check for Disk ID 1 (x64) and close the HTA to continue with the task sequence
If oFS.FileExists(Stmp1x64) Then
strLogInfo = "Disk 1 (x64) was re-inserted into drive "& DrvLet
LogInfo()
statusarea.innerhtml = "Task completed - deployment will now continue"
StartProcess2 = 0
Exit Function
'Check for any other disk and eject if present
Else
EjectDVD(DrvLet)
MsgBox "Please re-insert Disk 1 (x64) into drive "& DrvLet,0,"Windows 7 Wipe & Load"
StartProcess2 = 1
StartProcess2()
End If
End If
End Function
'<--END OF MAIN PROCESSING-->
'<--START OF SUPPORT FUNCTIONS-->
Function GetDVDDrive()
statusarea.innerhtml = "Checking the status of the DVD drive - please wait..."
' Find the DVD Drive using WMI
arrComputers = Array("localhost")
For Each strComputer In arrComputers
Set objWMIService = GetObject("winmgmts:\\"& strComputer & "\root\CIMV2")
' Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_CDROMDrive", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
Set colItems = objWMIservice.ExecQuery("SELECT * FROM Win32_LogicalDrive WHERE DriveType = 2", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
Next
For Each objItem In colItems
DrvLet = objItem.Drive & "\"
statusarea.innerhtml = "Working drive has been identified as "& DrvLet
'Log the drive letter
strLogInfo = "GetDVDDrive function ran and identified the DVD drive as "& DrvLet
LogInfo()
Next
End Function
Function GetDVDState()
statusarea.innerhtml = "Checking the status of the currently loaded disk..."
' Find the DVD Drive using WMI
arrComputers = Array("localhost")
For Each strComputer In arrComputers
Set objWMIService = GetObject("winmgmts:\\"& strComputer & "\root\CIMV2")
' Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_CDROMDrive", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_LogicalDrive WHERE DriveType = 2", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
Next
For Each objItem In colItems
Media = objItem.MediaLoaded
strLogInfo = "GetDVDState function ran and identified media loaded in "& objItem.Drive & "\ as being "& Media
LogInfo()
If Media Then
DrvLet = objItem.Drive & "\"
Exit For
End If
Next
End Function
Function GetDVDStatus()
GetDVDState()
Do While Media = False
EjectDVD(DrvLet)
MsgBox "Drive "& DrvLet & "does not have a disk inserted!"& Chr(13) & "Please insert the requested disk into drive "& DrvLet,0,"Windows 7 Wipe & Load"
GetDVDState()
If Media Then Exit Do
Loop
End Function
Function EjectDVD(drive)
On Error Resume Next
' Dim ts
' Dim strDriveLetter
' Dim intDriveLetter
' Const CDROM = 4
' strDriveLetter = ""
' For intDriveLetter = Asc("A") To Asc("Z")
' Err.Clear
' If oFSO.GetDrive(Chr(intDriveLetter)).DriveType = CDROM Then
' If Err.Number = 0 Then
' strDriveLetter = Chr(intDriveLetter)
' Exit For
' End If
' End If
' Next
'
' Set oWMP = CreateObject("WMPlayer.OCX.7")
' Set colCDROMs = oWMP.cdromCollection
' For d = 0 To colCDROMs.Count - 1
' colCDROMs.Item(d).Eject
' Next
' set oWMP = Nothing
' set colCDROMs = Nothing
Dim oShell
Set oShell = CreateObject("Shell.Application")
oShell.Namespace(17).ParseName(drive).InvokeVerb("Eject")
End Function
Function LogInfo()
Dim ObjFile, ObjFSO, strTime, strDate, strTempMsg
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\MININT\SMSOSD\OSDLOGS\DVDExchange.log", 8)
strTime = Right("0"& Hour(Now), 2) & ":"& Right("0"& Minute(Now), 2) & ":"& Right("0"& Second(Now), 2) & ".000+000"
strDate = Right("0"& Month(Now), 2) & "-"& Right("0"& Day(Now), 2) & "-"& Year(Now)
strTempMsg = "<![LOG["& strLogInfo & "]LOG]!><time="""& strTime & """date="""& strDate & """component=""DVDExch""context=""""type="""& strLogInfoType &"""thread=""""file=""DVDExchange.hta"">"
objFile.WriteLine strTempMsg
objFile.Close
'LogInfo Cleanup
Set objFSO = Nothing
Set objFile = Nothing
End Function
'<--END OF SUPPORT FUNCTIONS-->
</script>
</head>
<body scroll="no">
<table border="0"width="386"height="128">
<tr>
<td class="bodyText"style="width: 100%; padding: 10 10 10 10">
<font size="3">
<span id="StatusArea"></span>
</font>
<br />
<hr size="1"style="margin-top: 5px; color: #CCCCCC"/>
</td>
</tr>
<tr>
<td align="right"style="padding: 0 10 0 0">
<INPUT tabindex=1 onclick=StartProcess1() name="NextButton"value="Next"type=button style="height: 30px; width: 120px"disabled>
</td>
</tr>
</table>
</body>
</html>
If someone would be kind enough to at least point me in the right direction i would be grateful.
Thanks,
Dave