VBscript HTA
Dear Exprt,
How to display value when start hta file.
<html>
<head>
<title>HTA Test</title>
<HTA:APPLICATION
ID="objTest"
APPLICATIONNAME="HTA Test"
SCROLL="yes"
SINGLEINSTANCE="yes"
>
</head>
<SCRIPT LANGUAGE="VBScript">
Sub Computername
Dim objPC
Set objPC = WScript.CreateObject( "WScript.Network" )
objPC = objPC.ComputerName
BasicTextbox.value
End Sub
</SCRIPT>
<body>
<input type="text" name="BasicTextbox" size="30"><P>
</body>
[email protected]
Thanks its work!
But when i add another textbox its load only last one not first
<html>
<head>
<title>HTA Test</title>
<HTA:APPLICATION
ID="objTest"
APPLICATIONNAME="HTA Test"
SCROLL="yes"
SINGLEINSTANCE="yes"
>
</head>
<SCRIPT LANGUAGE="VBScript">
Sub window_onload
Computernm.Focus
Dim objPC
Set objPC = CreateObject( "WScript.Network" )
Computernm.value = objPC.ComputerName
End Sub
Sub window_onload
Dim objPC
Set objPC = CreateObject( "WScript.Network" )
Username.value = objPC.UserName
End Sub
</SCRIPT>
<body>
<label for="Computer Name">Computer Name:</label> <input type="text" name="Computernm" size="20"><P>
<label for="Usernm Name">User Name:</label> <input type="text" name="Username" size="20"><P>
</body>
[email protected]
Similar Messages
-
Installing printers from a VBScript HTA
Hi,
I have just started with VBScript, and I'm trying to make a simple portal for printer installation. The problem is that we have a setup with different printservers, with printers with some standard names. So the HTA lets you choose where you sit, and
then installs the correct printers, from the server near you.
What am i doing wrong?
<html>
<head>
<title>Printer Installation</title>
<script language="VBScript">
Window.ReSizeTo 350, 125
Function InstPrt(strPrtSrv)
strPrtSrvName = "Print-Server-" & strPrtSrv
strPrtShrNmAA = "\\" & strPrtSrvName & "\PrinterAA"
strPrtShrNmBB = "\\" & strPrtSrvName & "\PrinterBB"
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer Where ShareName = 'PrinterAA' or ShareName = 'PrinterBB' and not ServerName = strPrtSrvName")
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
Set WshNetwork = CreateObject("Wscript.Network")
PrinterPath = strPrtShrNmAA
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
PrinterPath = strPrtShrNmBB
WshNetwork.AddWindowsPrinterConnection PrinterPath, PrinterDriver
WshNetwork.SetDefaultPrinter strPrtShrNmBB
Self.Close
End Function
</script>
</head>
<center>
<a href="#" onClick="InstPrt(a01)">Install PrinterAA & BB from Server A01</a><br>
<a href="#" onClick="InstPrt(b01)">Install PrinterAA & BB from Server B01</a><br>
<a href="#" onClick="InstPrt(c02)">Install PrinterAA & BB from Server C01</a><br>
</center>
</script>
</html>strPrtSrvName given ealier in the function? I cant call that in the Query?
You cannot use a variable inside of a query and you cannot use a variable that is not in the file. Your file has no variable with that name.
You need to spend sometime learning VBScript first. Run the code as VBScript then try to use it in an HTA.
Here is a partial example:
"Select * from Win32_Printer Where ShareName='PrinterAA' or ShareName='PrinterBB' and not ServerName='MyPrintServer'"
¯\_(ツ)_/¯ -
Auto-Centering VBScript based HTA
Hi ScriptingGuys/All,
I am using the command below to call a custom HTA from within VBScript, and am having real difficulties getting it to launch in centre screen, rather than tucked up in one corner as it currently is!
sCommand = "mshta.exe ""javascript:{new ActiveXObject(""InternetExplorer.Application"")" _
& ".putProperty('" & iRandom & "',window); window.resizeTo(" & WidthX & "," & HeightY & ");" _
& "window.moveTo(" & ("screen.Width" & - WidthX) & "/2" & "," & ("screen.Height" & - HeightY) & "/2" & ")}"""
As you can see, I have the code which I THINK should be there and should work in the 'window.moveTo' statement, but this seems to be ignored completely!
('WidthX' and 'HeightY' are the two parameters passed in when calling the function, that determine the desired size of the window)
If anyone has any suggestions or can point me in the right direction, I'd be very grateful!
Many thanks,
JamesHi jrv, thank you for your reply.
I'm afraid I don't quite follow your first suggestion. The code I have isn't a 'native' HTA as such, it's an HTA generated from within a VBScript thus I'm not sure where/how your example would fit in with what I've got. If it helps here is the code I have;
Function HTA(WidthX, HeightY)
Dim iRandom, sCommand, oIE
randomize : iRandom = Int(1000000 * rnd)
sCommand = "mshta.exe ""javascript:{new ActiveXObject(""InternetExplorer.Application"")" _
& ".putProperty('" & iRandom & "',window); self.resizeTo(" & WidthX & "," & HeightY & ");" _
& "self.moveTo(" & ("screen.Width" & - WidthX) & "/2" & "," & ("screen.Height" & - HeightY) & "/2" & ")}"""
With CreateObject("WScript.Shell")
.Run sCommand, 1, False
Do Until .AppActivate("javascript:{new ") : Wsh.Sleep 10 : Loop
End With
For Each oIE In CreateObject("Shell.Application").Windows
If IsObject(oIE.GetProperty(iRandom)) Then
Set HTA = oIE.GetProperty(iRandom)
oIE.Quit
HTA.document.write "<HTA:Application border=thin sysmenu=no contextMenu=no minimizebutton=no maximizebutton=no/>" _
& "<body scroll=no style='font:normal 12pt Arial; background-color:whitesmoke; border-Style:inset; border-Width:2px'" _
& "onunload='VBScript:If Not Done.Value Then window.event.cancelBubble=true : window.event.returnValue=false : Done.Value=true : End If'>" _
& "<input type=hidden id=Done value=false><center><span id=Message></span>" _
& "<input type=button id=buttonLock style='font:italic' onclick=Done.Value=""Lock""> " _
& "<input type=button id=buttonLogOff style='font:italic' onclick=Done.Value=""LogOff""><center></body>"
HTA.buttonLogOff.Focus
Exit Function
End If
Next
End Function
I saw this example used in a
previous post and have adapted it slightly for my needs.
Why is it you say that performing the resize/move actions at the point of building the command won't work? The resize seems to work fine having it there, and the move code doesn't error as such it just doesn't do anything! -
How can I stop a task sequence if a custom HTA preflight check fails?
In our currently deployment method, we launch an HTA program before initiating the OSD process. This is only when run from the RAP menu, not via PXE. When a user initiates OSD through that menu, they get a message prompting them to close Outlook, and
a countdown of 5 mins, then OSD starts. They also have the ability to click on an 'OK' button to proceed on their own.
I've created a new script which checks WMI if Outlook and/or OCS are open, and if the machine is running on battery, spit out a "Failed" response and stop the HTA. I've also added a "recheck" button to re-do the check, and an 'OK
button if people jsut want to continue.
I'm curious if there is a way to prevent the task sequence from continuing if any of those conditions arent met. Currently it just pops up and says "Failed, Cannot conitue", but if they close the window, the task sequence thinks the program
has run, and the OSD migration starts. I'd like to be able and get the script to cancel the OSD process if a check fails.
Has anyone had success with this, using WINXP? I'd use the MS pre-flight check but it's only for WIN7.Interesting. Thanks for the response. Is there anybody out there that can assist with VBS part of the solution?
Here's the code I'm working with. Currently the battery piece isnt working as it should but I can figure that our, eventually. I'd like to get Jason's proposed solution in the code. If this isn't the right place, I'll take this somewhere
else.
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>OSD Preflight checks</title>
<HTA:APPLICATION
APPLICATIONNAME="OSD Preflight checks"
ID="objOSDPreReqChecks"
SCROLL="no"
CONTEXTMENU="no"
SINGLEINSTANCE="no"
MAXIMIZEBUTTON="no"
MINIMIZEBUTTON="no"
WINDOWSTATE="normal"/>
<!-- #region STYLEs-->
<style type="text/css">
H1{color:Black;text-align:center;font-family: Arial, Helvetica, sans-serif;font-size: 26px;}
p{font-family:"Arial";font-size:10px;}
fail{color:Red;text-align:center;}
.Version {float:left; font-size:1.0em;font-style:italic;color:#888888;font-weight:bold;}
.Header1 {width: 180px; text-align: right;font-weight:bold;}<!-- '1st column heading -->
H2 {font-family: Arial, Helvetica, sans-serif; text-align: center;}
H3 {font-style: italic;}
.style2 {width: 180px; text-align: left;}
.Header2 {width: 150px; text-align: right;font-weight:bold;}<!-- '2nd column heading -->
.style4 {width: 410px; text-align: left;}
.StatusBar
font-family: Arial, Helvetica, sans-serif;
text-align: center;
.hidden {display: none; visibility: hidden;}
</style><!-- #endregion -->
</head>
<script language="VBScript" type="text/vbscript">
'======================================================================================
' Script
' Version
' Purpose To check a machine is suitable for taking an OS deployment
'======================================================================================
'Features
' Modular design
' Verbose "Debug Mode"
' In-built data validation
' Custom error handling
' Custom error codes - 90x0
' Generic WMI handler
'BUGfix: Change CLng to CDbl to avoid overflow (in GetRAM)
'fixed - moved head section to top to become head > script > body
'fixed - fCheckModel display with leading ,
'fixed - fgetmodels dictionary list
Option Explicit
' #region GLOBAL DECLARATIONS: Persistent fold region
'======================================================================================
'GLOBAL Vars
'Things to just display (in GUI)
Dim strRAM
Dim strCPUInfo
Dim strCPUName
Dim strCPUDesc
Dim iCPUCount
Dim iCPUCoreCount
Dim iRAM
Dim strBIOSver, strBIOSDate, strBIOSInfo
'Time related
Dim TimerInterval 'timer to refresh HTA at start
Dim iTimer 'abort timer
Const iAbortTimeout=300000 'delay before window closes (in milliseconds)
Dim pbTimerID
Dim pbHTML
Dim pbWaitTime
Dim pbHeight
Dim pbWidth
Dim pbBorder
Dim pbUnloadedColor
Dim pbLoadedColor
Dim pbStartTime
'Dictionary
Dim objModelsDict,colKeys,strKey 'models
Dim objApprovedMakesDict
'Misc GLOBAL vars
Dim blnDebug 'set TRUE to trigger debug mode
Dim bAbortBuild 'Boolean flag to abort or not abort
Dim strTemp 'throwaway/scratch
Dim strNamespace 'wmi default namespace for ANY machine
Dim strComputer 'wmi reference to current machine, just .
Dim strService 'WMI service
Dim strQuery 'custom WQL
Dim ErrMsg 'custom error messages
Dim iErrMode 'State machine for error mode
Dim lFlags 'WMI flag
Dim strDisks
'Pre-requisites - things that will cause build to abort if values do not meet spec
Dim strHTAVendor 'Make of hardware
Dim strHTAVendorState
Dim strHTAModel 'Model of hardware
Dim strHTAModelState 'Model state
Dim strHTARAM 'RAM
Dim strHTARAMState 'RAM state
Dim strHTACPUSpeed 'Processor speed
Dim strHTACPUCores 'Number of cores
Dim strHTACPUFullInfo 'CPU + cores
Dim strHTAHDD 'Disk info
Dim strHTAHDDState 'Disk state
Dim strHTACheckRAW 'NTFS check
Dim strHTAArchitecture 'Processor support
Dim strHTAProduct 'Product ID
Dim strHTAOutlook 'Outlook running
Dim strHTAOutlookState 'Outlook state
Dim strHTABattery 'Battery check
Dim strHTABatteryState 'Battery state
'for WQL filters
Dim strWQLPCInfo 'Pre-req - (1) for various inc. domain role (servers)
Dim strWQLRAM 'Pre-req - (2) RAM
Dim strWQLCPU 'Pre-req - CPU speed string (not int)
Dim strWQLBootOrder 'Pre-req - Boot order string
Dim strWQLSATAMode 'Pre-req - HDD mode
Dim strWQLGenericBIOS
Dim strWQLCPUCount 'Pre-req - how many CPUs
Dim strWQLCPUInfo
Dim strWQLFSType 'Pre-req - Check HDD not RAW (i.e. is NTFS)
Dim strWQLDisks 'Disks
Dim strWQLChassis 'Machine type
Dim strWQLID 'Unique code from OEM
Dim strWQLProc 'is Outlook running = False
Dim strWQLBattery 'is on Battery = False
'State
Const cProblem = " Problem!"
Const cRunAgain =" RunCheck: Run System Check Again"
Const cSuccess = " Success!"
Const cPassed=" Pass"
Const cFail=" Fail"
'Pre-requisite to check: SET VALUES HERE vvvvvvvvvvvvvvvv
Const cApprovedOEM="Hewlett-Packard"
Const LegacyOEM1="Dell Inc."
Const LegacyOEM2="IBM"
Const cMinimumMemoryMB = 1000 'RAM in MB
'Const cMinimumMemoryMB = 1000000 'force fail test data RAM in MB
Const cMinFS="NTFS"
' Const cMinFS="HPFS" 'force fail test data
Const iMinCores=1
'Const iMinCores=10099 'force fail cores test data
Const iMinCPUSpeed=2 '20 'in GHz
'Const iMinCPUSpeed=90000 'in GHz
Const iMinCPUArch=32
'Const iMinCPUArch=64
' #endregion
' To hide anything use ID.className = "hidden", to show set to "", e.g. NotFoundArea.className = "hidden"
Sub Window_Onload
Err.Clear
VersionSpan.InnerText = objOSDPreReqChecks.Version 'Get version
self.focus
self.moveTo 100,100 'Move window top left
StatusBar.InnerText="Validating machine..."
document.body.style.cursor = "wait" 'hourglass cursor
'Call PreflightChecks 'use for testing as a VBS only, otherwise HTA timer will call below
TimerInterval = window.setInterval("PreflightChecks",10)
End Sub
Function PreflightChecks
' #region HEADER NOTES: Persistent fold region
'Version history
'ver 5 OCTOBER 2011 - added error handler
'ver 3rd Nov - removed HPonly queries
'// Solution: Custom Script for use with MDT - Adapted from hardwareinfo.vbs Mikael Nystrom – http://deploymentbunny.com
'Typical BIOS content
'Processor Speed = 2133/1066 MHz
'Boot Order = Network Controller,ATAPI CD-ROM Drive,USB device,Hard Drive,Diskette Drive,PnP Device #2,PnP Device #3,PnP Device #4,PnP Device #5,PnP Device #6,PnP Device #7,PnPe #8,PnP Device #9,PnP Device #10,PnP Device #11
'SATA (disk) mode: *IDE,--,RAID,-- or IDE,*AHCI,RAID
'On Error Resume Next
' #endregion
' #region CONSTANTS: Persistent fold region
'======================================================================================
'Fields available in HP BIOS
Const sAsset = "Notebook Asset Tag"
Const sOwner = "Notebook Ownership Tag"
Const sMan = "Manufacturer"
Const sNoteModel = "Notebook Model"
Const sCPU = "Processor Type"
Const sCPUSpeed = "Processor Speed"
Const sRAM = "Memory Size"
Const sModel = "Product Name"
Const sBIOSName ="System BIOS"
Const sBIOSVer = "BIOS Version"
Const sBIOSDate = "BIOS Date"
'Other BIOS stuff you could use too
'Const sOwnerTag = "Enter Ownership Tag"
'Const sBIOS = "PCID"
'Const sBIOS = "Define Custom URL"
'Const sBIOS = "Set Alarm Time"
'Const sBIOS = "PCID Version"
Const TextMode="1" 'text case sensitive for dict obj
'WMI core constants
Const wbemFlagReturnImmediately = 16 'wmi - Causes the call to return immediately.
Const wbemFlagForwardOnly = 32 'wmi - Causes a forward-only enumerator to be returned.
'Forward-only enumerators are generally much faster and
'use less memory than conventional enumerators, but don't allow calls to SWbemObject.Clone_
'Advisory config values - as in "you want to the change these"
Dim strHTABootOrder
Dim strHTASATAMode
'Dim strHTACPU
' #endregion
'======================================================================================
' #region WQL: Persistent fold region
lFlags = wbemFlagReturnImmediately + wbemFlagForwardOnly
'Queries of things to check (HP)
strWQLBootOrder = "select Name, value from HP_BIOSSetting where Name='Boot order'"
strWQLSATAMode = "select Name, value from HP_BIOSSetting where (Name='SATA emulation' or name='SATA device mode')"
strWQLDisks ="SELECT * FROM Win32_DiskDrive where mediatype like 'Fixed%hard disk%'" 'win32_disk only avail after W7
strWQLFSType ="SELECT * from Win32_LogicalDisk where DriveType='3'" 'only bother with HDDs
'Generic WMI query strings
strWQLGenericBIOS="SELECT Manufacturer,SMBIOSBIOSVersion,ReleaseDate FROM Win32_BIOS WHERE PrimaryBIOS = True"
strWQLCPUCount= "SELECT NumberOfProcessors,NumberOfLogicalProcessors from Win32_ComputerSystem"
strWQLCPUInfo="SELECT Name,DataWidth,description,MaxClockSpeed,NumberofCores,NumberOfLogicalProcessors from Win32_Processor"
strWQLPCInfo="SELECT Domain,DomainRole,SystemType,Manufacturer,Model,TotalPhysicalMemory FROM Win32_ComputerSystem"
' strWQLPCInfo="SELECT Domain,DomainRole,SystemType,Manufacturer FROM Win32_ComputerSystem"
strWQLChassis="SELECT ChassisTypes from Win32_SystemEnclosure"
strWQLID="SELECT IdentifyingNumber,UUID from Win32_ComputerSystemProduct"
strWQLRAM="SELECT * FROM Win32_PhysicalMemory"
strWQLProc="SELECT * FROM Win32_Process"
strWQLBattery="SELECT * FROM BatteryStatus Where Voltage > 0"
' #endregion
' #region MAIN algorithm
'=====================================================================================================
' MAIN
'Algorithm
'1) Check make (vendor)
'2) Check model (in list)
'3) Check RAM >x
'4) Check HDD TYPE (HDD is not RAW)
'5) Check CPU architecture
'6) Check outlook
'7) Check battery
'=====================================================================================================
'Initialise
window.clearInterval(TimerInterval) 'Reset timer to 0
' blnDebug=True
blnDebug=False
bAbortBuild=False 'default to DON'T abort
' bAbortBuild=True
'Build list of approved vendors
Set objApprovedMakesDict = CreateObject("Scripting.Dictionary")
objApprovedMakesDict.comparemode=VBTextCompare
objApprovedMakesDict.add cApprovedOEM,"OK"
objApprovedMakesDict.add LegacyOEM1,"OK"
objApprovedMakesDict.add LegacyOEM2,"OK"
objApprovedMakesDict.add "Lenovo","Testdata"
If blnDebug Then Stop
'1) all machines check make
strHTAVendor=fCheckVendor(strWQLGenericBIOS) 'check vendor in BIOS - if vendor not approved ABORT without proceeding
If bAbortBuild=True Then
StatusBar.InnerText=StatusBar.InnerText & VbCrLf & "FATAL ERROR - goodbye cruel world"
iTimer = window.setTimeout("Abort", iAbortTimeout, "VBScript")
Else
StatusBar.InnerText="Vendor: " & strHTAVendor & vbTab & " " & strHTAVendorState
'2) Discover current Model
strHTAModel=fGetModelName(strWQLPCInfo) 'get model name from WMI
strHTAModel=fUniversalCheckData(strHTAModel,"'Discover Model - fGetModelName'") 'validate
Call fGetModels 'get list of all valid models (from text file)
strHTAModel=fCheckModel(strHTAModel)
'2a) Model number (optional)
strHTAProduct=fGetComputerSystemProdIDNumber(strWQLID) 'manufacturer's product ID
strHTAProduct=fUniversalCheckData(strHTAProduct,"'Discover ID - fGetComputerSystemProdIDNumber'")
' StatusBar.InnerText=StatusBar.InnerText & VbCrLf & vbTab & "Product Code: " & vbTab & strHTAProduct
'3) Check installed Memory
strHTARAM=fGetRAM(strWQLRAM) 'find RAM size
strHTARAM=fUniversalCheckData(strHTARAM,"'Detect RAM - fCheckRAM'")
strHTARAM=fCheckRAM(strHTARAM) 'check RAM meets req
If strHTARAMState=cFail Then Exit Function
'4) Disk format IS NTFS
strDisks=fGetDrives(strWQLFSType) 'Get formatting info for all drives
strHTACheckRAW=fUniversalCheckData(strDisks,"'Detect filesystem - fCheckNTFS'") 'Validate data
strHTACheckRAW=fCheckNTFS(strDisks) 'Check FS format is acceptable (not RAW)
If strHTACheckRAW=cFail Then Exit Function
'Generic CPU calls
strHTACPUFullInfo="CPUs:" & fGetCPUInfo(strWQLCPUInfo) & " with CPU cores:" & iCPUCoreCount
strBIOSInfo="BIOS version: " & strBIOSver & ", dated " & strBIOSDate
'5a) CPU Speed check (info from http://www.robvanderwoude.com/wmiexamples.php)
strCPUInfo=WMI(strWQLCPUInfo,strNamespace) 'Get CPU details
strTemp=split(strCPUInfo,"@"): strHTACPUSpeed=strTemp(1)
strHTACPUSpeed=fUniversalCheckData(strHTACPUSpeed,"'Check processor - fCheckCPUSpeed'") 'Validate data
strHTACPUSpeed=fCheckCPUSpeed(strHTACPUSpeed) 'Check CPU clock speed
'5b) cores check
strHTACPUCores=fUniversalCheckData(iCPUCoreCount,"Check core count - fCheckCores") 'Validate data
iCPUCoreCount=fCheckCores(iCPUCoreCount) 'pass or fail?
'5c) CPU address width
strHTAArchitecture=fUniversalCheckData(strHTAArchitecture,"Check core count - fCheckCores") 'Validate data
strHTAArchitecture=fCheckCPUArch(strHTAArchitecture)
'6) Check outlook
strHTAOutlook=fCheckProcess(strWQLProc)
'7) Check Battery
strHTABattery=fCheckBattery(strWQLBattery)
'end checkss
document.body.style.cursor = "default"
'Display hardware values in GUI (in table)
Vendor.innerhtml = strHTAVendor 'Use str...var..STATE if you want Pass/fail text instead
Model.innerhtml = strHTAModel
Product.innerhtml = strHTAProduct
RAM.innerhtml = strHTARAM
CPUspeed.innerhtml = strHTACPUSpeed
CPUInfo.innerhtml = strHTACPUFullInfo
HDDFS.innerhtml = strHTACheckRAW
CapableArchitecture.innerhtml=strHTAArchitecture
BIOSversion.innerhtml = strBIOSver
BIOSDate.innerhtml = strBIOSDate' CPUName.innerhtml = strCPUDesc 'GetCPUName
End If
'======================================================================================
' #endregion
End Function
'generic WMI queries, by field and namespace
Function WMI(strQuery,strNameSpace)
'Aim: generic WMI calls
'return value of BIOS
On Error Resume Next
Dim colItems,objItem
Dim objWMI
Const strService = "winmgmts:{impersonationlevel=impersonate}//" 'binding to WMI
Const strComputer = "." 'this machine
Set objWMI = GetObject(strService & strComputer & strNamespace) 'GLOBAL wmi
Set colItems = objWMI.ExecQuery(strQuery,,lFlags)
For Each objItem In colItems
If Err Then
StatusBar.InnerText=StatusBar.InnerText & VbCrLf & "WMI query: " & strQuery & " in " & strNamespace & objItem.Name
Call ErrHandler("WMI error " & strQuery,1)
Else
WMI=objItem.Name 'Return value
End If
Next
End Function
Function fGetModelName(strWQLPCInfo)
'Aim: Get model name from BIOS - WMI field sometimes varies if laptop, so try two
'Return STRING: Model string from BIOS or "UNKNOWN" if null
On Error Resume Next
Dim colPCInfo,objPCItem
Dim strModel
Set colPCInfo = GetObject("winmgmts:").ExecQuery(strWQLPCInfo,"WQL",lFlags)
If Err Then
Call ErrHandler("fGetModelName: Error querying WMI " & strWQLPCInfo,2)
Else
For Each objPCItem In colPCInfo
If Not IsNull(objPCItem.Model) Then
strModel=objPCItem.Model
' iRAM=objPCItem.TotalPhysicalMemory
Else
If (strHTAVendor=cApprovedOEM And IsLaptop = True) Then ' resort to HP specific query for older laptops
'Notebook
strModel=QueryHPBIOS(sNoteModel)
if strModel="" then strModel=QueryHPBIOS(sModel) 'try alt value
Else
strModel=QueryHPBIOS(sModel)
End If
End If
Next
End If
If strModel = "" Then
fGetModelName = "UNKNOWN"
Model.style.visibility="hidden"
Else
fGetModelName=strModel
End If
End Function
'====================================================
'====================================================
Function fGetRAM(strQuery)
'Aim: get RAM installed. NB Win32_ComputerSystem::TotalPhysicalMemory may not be accurate
'Return integer
On Error Resume Next 'equiv to Err.Clear
Dim colItems, item
Dim iTotalMemory
Set colItems = GetObject("winmgmts:").ExecQuery(strQuery,"WQL",lFlags)
If Err Then
Call ErrHandler("fGetRAM: Error querying " & strQuery,2)
Else
iTotalMemory = 0
For Each item In colItems
iTotalMemory = iTotalMemory + CDBL(item.Capacity)/(1024^2)
Next
End If
If iTotalMemory = "" Then
fGetRAM = "RAM UNKNOWN"
RAM.style.visibility="hidden"
Else
fGetRAM=iTotalMemory
End If
End Function
'====================================================
'====================================================
Function fGetCPUInfo(strQuery)
'Aim: query WMI for CPU info - number and number of cores
'Return: function=CPU count, var for the cores: iCPUCoreCount, strHTAArchitecture, strCPUDesc
On Error Resume Next
Dim colItems, objItem
Dim NumberOfProcessors
Set colItems = GetObject("winmgmts:").ExecQuery(strQuery,"WQL",lFlags)
If Err Then
Call ErrHandler("GetCPUInfo: Error querying " & strQuery,2)
Else
For Each objItem In colItems
If Err Then
Else
If Not IsNull(objItem.NumberOfCores) Then
NumberOfProcessors = Trim(objItem.NumberOfCores) 'NumberOfProcessors
End If
If Not IsNull(objItem.NumberOfLogicalProcessors) Then
iCPUCoreCount = Int(Trim(objItem.NumberOfLogicalProcessors))
End If
If Not IsNull(objItem.DataWidth) Then
strHTAArchitecture=Trim(objItem.DataWidth) & "-bit"
End If
If Not IsNull(objItem.description) Then
strCPUDesc = Trim(objItem.description) 'cpu name
End If
End If
Next
If NumberOfProcessors = "" Then
NumberOfProcessors = "UNKNOWN"
End If
fGetCPUInfo = Int(NumberOfProcessors)
' iCPUCoreCount = Int(NumberOfLogicalProcessors)
End If
End Function
'====================================================
'====================================================
Function fGetComputerSystemProdIDNumber(strWQLID)
'Aim: Get UUID from Win32_ComputerSystemProduct
'Return: great big integer
Dim colSys,objSys
Dim strUUID
On Error resume next
Set colSys = GetObject("winmgmts:").ExecQuery(strWQLID,"WQL",lFlags)
If Err then
Call ErrHandler("fGetComputerSystemProdIDNumber: Error querying " & strWQLID,2)
Else
For Each objSys In colSys
If Not IsNull(objSys.IdentifyingNumber) Then
strUUID = Trim(objSys.IdentifyingNumber)
End If
Next
If strUUID = "" Then
fGetComputerSystemProdIDNumber = "UNKNOWN"
Else
fGetComputerSystemProdIDNumber = strUUID
End If
End If
End Function
'=================================================================================
'=================================================================================
Function fGetDrives(strQuery)
Dim colDisks,objHDD
Dim strDriveType, strDiskSize, strDisk
Dim strDiskFSType
Dim iGBUnits
On Error Resume Next
iGBUnits=1073741824
Dim iRAW
iRAW=0
Set colDisks = GetObject("winmgmts:").ExecQuery(strQuery)
For Each objHDD In colDisks
Select Case objHDD.DriveType
Case 1 strDriveType = "Drive could not be determined."
Case 2 strDriveType = "Removable Drive"
Case 3 strDriveType = "Local hard disk."
Case 4 strDriveType = "Network disk."
Case 5 strDriveType = "Compact disk (CD)"
Case 6 strDriveType = "RAM disk."
Case Else strDriveType = "Drive type Problem."
End Select
strDiskFSType = objHDD.FileSystem
'Find C
If objHDD.Name="C:" Then
If isNull(objHDD.FreeSpace) Then
If blnDebug=True then Call ErrHandler("ALERT!! Volume " & objHDD.Name & "is RAW",1) 'Abort/clean
fCheckDrives="ALERT!! Volume " & objHDD.Name & "is RAW"
End If
End If
strDiskSize = Int(objHDD.Size /iGBUnits) & "GB" 'calc size of disk
strDisk = strDisk & VbCrLf & "Vol " & objHDD.Name & " (" & strDriveType & ") size: " & strDiskSize & " (free: " & Int(objHDD.FreeSpace /iGBUnits) & "GB), " & strDiskFSType
fGetDrives=strDisk
Next
If (Err.Number <>0) Then
Call ErrHandler("WMI Property Query Error: [" & Err.Number & "]",2)
fGetDrives = -1
Exit Function
End If
End Function
'=================================================================================
'=================================================================================
Function fUniversalCheckData(varData,strStage) 'template
'Aim: Check value passed...
'is not blank
'is in range x..y
'spelt OK
'is in a list
'format is text, numeric
'return: string: the original value
On Error Resume Next
Dim Err
if blnDebug Then StatusBar.InnerText = StatusBar.InnerText & VbCrLf & "Validating " & strStage & " data..."
If Err Then
Call ErrHandler("WARNING: Error discovering value in " & strStage,2) '1=Quit,2=Warn
strHTAModel="Unknown"
Else
Select Case varData
Case IsEmpty(varData) Or IsNull(varData)
Call ErrHandler("WARNING: Error in "& strStage,2) '1=Quit,2=Warn
fUniversalCheckData="Unknown"
Case IsNumeric(varData)
If varData<0 Then
Call ErrHandler("WARNING: Value negative"& strStage,2) '1=Quit,2=Warn
fUniversalCheckData="Unknown"
End if
' & varData &
Case IsDate(varData)
Case Else
fUniversalCheckData=varData 'Data OK - return value unchanged
End Select
End If
End Function
'=================================================================================
'Checks - follow if true DO, if false warn/abort
'=================================================================================
Function fCheckBattery(strQuery)
'Aim: Find if battery is running
'Return pass/fail
On Error Resume Next 'equiv to Err.Clear
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Dim colItems, item
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\WMI")
Set colItems = objWMIService.ExecQuery("SELECT * FROM BatteryStatus Where Voltage > 0", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each item In colItems
if objItem.PowerOnline = True Then
strHTABattery=objItem.PowerOnline
strHTABatteryState = cFail
Err.Raise 9010,"fCheckBattery",strHTABattery & " Laptop running on battery. OSD Cannot continue."
Call ErrHandler(ucase(strHTABatteryState) & ": " & Err.Description & " (Code: " & Err.Number & " - " & Err.Source & ")",1)
StatusBar.InnerText=StatusBar.InnerText & VbCrLf & "FATAL ERROR - Laptop on Battery. Please plug into an outlet before proceeding."
iTimer = window.setTimeout("Abort", iAbortTimeout, "VBScript")
Else
strHTABatteryState = cPassed
End if
Next
fCheckBattery=strHTABattery
End Function
'====================================================
Function fCheckProcess(strQuery)
'Aim: Find if outlook is running
'Return pass/fail
On Error Resume Next 'equiv to Err.Clear
Dim colItems, item
Set colItems = GetObject("winmgmts:").ExecQuery(strQuery,"WQL",lFlags)
For Each item In colItems
if item.Name = "OUTLOOK.EXE" Then
strHTAOutlook=item.Name
strHTAOutlookState = cFail
Err.Raise 9010,"fCheckOutlook",strHTAOutlook & " running. OSD Cannot continue."
Call ErrHandler(ucase(strHTAOutlookState) & ": " & Err.Description & " (Code: " & Err.Number & " - " & Err.Source & ")",1)
StatusBar.InnerText=StatusBar.InnerText & VbCrLf & "FATAL ERROR - Outlook Running, please close outlook before proceeding."
iTimer = window.setTimeout("Abort", iAbortTimeout, "VBScript")
Elseif item.Name = "communicator.exe" Then
strHTAOutlook=item.Name
strHTAOutlookState = cFail
Err.Raise 9010,"fCheckOutlook",strHTAOutlook & " running. OSD Cannot continue."
Call ErrHandler(ucase(strHTAOutlookState) & ": " & Err.Description & " (Code: " & Err.Number & " - " & Err.Source & ")",1)
StatusBar.InnerText=StatusBar.InnerText & VbCrLf & "FATAL ERROR - Communicator Running, please close OCS before proceeding."
iTimer = window.setTimeout("Abort", iAbortTimeout, "VBScript")
Else
strHTAOutlookState = cPassed
End if
Next
fCheckProcess=strHTAOutlook
End Function
'====================================================
'1 - Make
Function fCheckVendor(strVendor)
'Aim: Check make is one the OS/build is designed For
'Return: STRINGS for "Make", BIOS version and BIOS date (generic): strHTAVendorState pass or fail
On Error Resume Next
Dim colItems,objItem
Set colItems = GetObject("winmgmts:").ExecQuery(strVendor, "WQL", lFlags)
For Each objItem In colItems
strHTAVendor=objItem.Manufacturer
if objApprovedMakesDict.exists(strHTAVendor) then
strBIOSver=objItem.SMBIOSBIOSVersion
strBIOSDate=Mid( objItem.ReleaseDate, 5, 2 ) & "/" & Mid( objItem.ReleaseDate, 7, 2 ) & "/" & Left( objItem.ReleaseDate, 4 )
strHTAVendorState=cPassed
Else
strHTAVendorState=cFail
Err.Raise 9010,"fCheckVendor",strHTAVendor & " found. The build will not work on this make of hardware"
Call ErrHandler(ucase(strHTAVendorState) & ": " & Err.Description & " (Code: " & Err.Number & " - " & Err.Source & ")",1)
bAbortBuild=True
end if
Next
fCheckVendor=strHTAVendor
End Function
'=================================================================================
'=================================================================================
'2 - Models check
Function fCheckModel(strThisModel)
'Aim Check target machine is in list of models
'Return string
On Error Resume Next
StatusBar.InnerText=StatusBar.InnerText & VbCrLf & "Checking model..." & VbCrLf
If objModelsDict.exists(trim(strThisModel)) then ' if current model in objDict then huzzah
strHTAModelState=cPassed
StatusBar.InnerText=StatusBar.InnerText & vbTab & "Model detected: " & vbTab & strHTAModelState
Else
strHTAModelState=cFail
Err.Raise 9010,"fCheckModel",strThisModel & " found. The build will not work on this model of hardware"
Call ErrHandler(ucase(strHTAModelState) & ": " & Err.Description & " (Code: " & Err.Number & " - " & Err.Source & ")",1)
end if
fCheckModel=strHTAModel
End Function
'=================================================================================
'=================================================================================
'3 - RAM
Function fCheckRAM(strRAM)
'Aim: Check installed RAM > x
'Return string digits with units, e.g. 4GB
'use strHTARAM for value
'==================================================================
' Memory Preflight Check (from MDT2012)
'==================================================================
On Error Resume Next
StatusBar.InnerText=StatusBar.InnerText & VbCrLf & "Checking RAM..."
If Err.Number <> 0 Then
Call ErrHandler("Error occurred while calculating computer's memory.",2)
End If
fCheckRAM = Int(strRAM/1024) & "GB" 'format in GB
If Int(strRAM) > cMinimumMemoryMB Then
strHTARAMState=cPassed 'Sufficient memory - show whole number in GB"
StatusBar.InnerText=StatusBar.InnerText & vbTab & "RAM installed: " & vbTab & strHTARAMState
Else
strHTARAMState=cFail
Err.Raise 9030 ,"fCheckRAM","Not enough memory in this machine!" & " Required physical memory is: " & cMinimumMemoryMB & " MB."
Call ErrHandler(ucase(strHTARAMState) & ": " & Err.Description & " (Code: " & Err.Number & " - " & Err.Source & ")",1) 'abort build
End If
End Function
'=================================================================================
'=================================================================================
'4 - NTFS disk
Function fCheckNTFS(strDiskFS)
'Aim: Check HDD is NTFS
'Return string
On Error Resume Next
StatusBar.InnerText=StatusBar.InnerText & VbCrLf & "Checking file system is not RAW..."
If Instr(1,strDiskFS,cMinFS,VBTextCompare)<>0 Then
fCheckNTFS=cMinFS 'disk format is OK (NTFS)
StatusBar.InnerText=StatusBar.InnerText & vbTab & " File system: " & cPassed
Else
fCheckNTFS=cFail
Err.Raise 9040 ,"fCheckNTFS","WARNING: Disk not correct file-system. Type required is: " & cMinFS & "." & VbCrLf & _
"The deployment will fail unless you reformat the target disk immediately."
Call ErrHandler(Err.Description & " (Code: " & Err.Number & " - " & Err.Source & ")",2) 'halt build
End If
End Function
'====================================================
'=================================================================================
'5 - CPU checks
'=================================================================================
Function fCheckCPUSpeed(strCPU) 'any HW
'Aim: Check CPU speed
'Return string = number + appropriate units, e.g. 5HGz (strCPU)
On Error Resume Next
StatusBar.InnerText=StatusBar.InnerText & VbCrLf & "Checking CPU spec..."
Select Case Right(strCPU,3) 'check units
Case "MHz"
strCPU=Left(strCPU,4)/1000 'reformat to GHz
Case "GHz"
strCPU=strCPU 'unit already OK
Case Else
Call ErrHandler("CPU units are unknown",2)
End Select
'Check clock speed
If Int(Left(trim(strCPU),1))>=iMinCPUSpeed Then
fCheckCPUSpeed=strHTACPUSpeed 'CPU is fine i.e don't change value
StatusBar.InnerText=StatusBar.InnerText & vbTab & "CPU Speed: " & cPassed
Else
fCheckCPUSpeed=cFail 'already in GHz
Err.Raise 9050,"fCheckCPUSpeed","CPU speed pre-requisite failed. Minimum processor clock speed is: " & iMinCPUSpeed
Call ErrHandler(Err.Description & " (Code: " & Err.Number & " - " & Err.Source & ")",1) 'halt build
End If
End Function
'=================================================================================
'=================================================================================
Function fCheckCPUArch(strCPUArch) 'any HW
'Aim: Check CPU width
'Return string
On Error Resume Next
StatusBar.InnerText=StatusBar.InnerText & VbCrLf & "Checking CPU bus width..."
'Check clock speed
If Int(Left(trim(strCPUArch),2))>=iMinCPUArch Then
fCheckCPUArch=strHTAArchitecture 'CPU is fine i.e don't change value
StatusBar.InnerText=StatusBar.InnerText & vbTab & "CPU width: " & cPassed
Else
fCheckCPUArch=cFail 'already in GHz
Err.Raise 9052,"fCheckCPUArch","CPU width pre-requisite failed. Minimum processor width required is: " & iMinCPUArch
Call ErrHandler(Err.Description & " (Code: " & Err.Number & " - " & Err.Source & ")",1) 'abort build
End If
End Function
'=================================================================================
Function fCheckCores(iCores)
'Aim: Check hardware (CPU) has a minimum number of cores
'Return Integer
On Error Resume Next
StatusBar.InnerText=StatusBar.InnerText & VbCrLf & "Checking CPU cores..."
If iCores>=iMinCores Then
fCheckCores=iCores
StatusBar.InnerText=StatusBar.InnerText & vbTab & "Core count: " & vbTab & cPassed
'StatusBar.InnerText=StatusBar.InnerText & vbTab & "CPU cores: " & cPassed
Else
fCheckCores=cFail
Err.Raise 9051,"fCheckCores","WARNING: Not enough cores on the CPU to support the build. Minimum CPU cores is: " & iMinCores
Call ErrHandler(Err.Description & " (Code: " & Err.Number & " - " & Err.Source & ")",2) 'halt build
End If
End Function
'=================================================================================
'=================================================================================
Function fCheckHPCPUSpeed 'HP ONLY
'Aim: Check CPU speed
'return: string
'Check CPU speed
On Error Resume Next
strWQLCPU = "processor speed"
strTemp=QueryHPBIOS(strWQLCPU,"")
Select Case Right(strTemp,3)
Case "MHz"
strTemp=Left(strTemp,4)/1000 'reformat to GHz
Case "GHz"
strTemp 'is OK
Case Else
Call ErrHandler("CPU is unknown",2)
End Select
'Check clock speed
If strTemp>=iMinCPUSpeed Then
fCheckCPUSpeed= strTemp & "GHz"
Else
Err.Raise 9050,,"CPU speed pre-requisite failed"
Call ErrHandler("CPU is too slow",1)
fCheckCPUSpeed=cFail 'already in GHz
End If
End Function
'=================================================================================
'=================================================================================
Function fGetModels
'Aim: Read external text file
'return: dictionary object - models as key, integer as value e.g. Dell Optiplex,12
'On Error Resume Next
Dim objFSO
Dim objFile
Dim strFile
Dim strEntry
Dim n
Dim strfilepath
Dim iLineCount 'count lines to avoid listing first item with ,.
Set objModelsDict = CreateObject("Scripting.Dictionary")
set objFSO=CreateObject("Scripting.FileSystemObject")
Const ForReading=1
strfilepath = Left(window.location.pathname,InStrRev(window.location.pathname,"\"))
strFile=strfilepath & "Models.txt"
set objFile=objFSO.OpenTextFile(strFile,ForReading)
iLineCount=0
'read in each line of data until you reach the end of the file
do While objFile.AtEndOfStream<>True
strEntry=objFile.ReadLine
'you can now do what ever you want with the line as referenced with the strEntry variable such as
'echoing it back (e.g. wscript.Echo strEntry) or passing it as a variable to a function of subroutine (e.g. MyFunction strEntry)
objModelsDict.comparemode=VBTextCompare
objModelsDict.Add strEntry,iLineCount
iLineCount=iLineCount+1
If blnDebug then
If iLineCount=1 Then
StatusBar.InnerText=trim(strEntry)
Else
StatusBar.InnerText=StatusBar.InnerText & ", " & trim(strEntry) 'list models
End If
End If
Loop
objFile.Close
End Function
'=================================================================================
'=================================================================================
'====================================================
Function ErrHandler(strErrorMsg,iErrMode)
'Aim: to handle error states
' 1 = Abort
' 2 = Warn
'Return 'Appropriate text message explaining the error
'====================================================
Const msgTitle="SCCM Deployment Preflight Checklist"
'On Error Resume Next '< don't use that as we want to KEEP the error properties
'Abort=1
If iErrMode=1 Then
StatusBar.InnerText=strErrorMsg 'overwrite status with Error message
' StatusBar.InnerText=StatusBar.InnerText & VbCrLf & " " & strHTAOutlook & " " & strHTAVendor & " " & strHTAVendorState & _
' VbCrLf & " " & strHTAModel & strHTAModelState & _
' VbCrLf & " " & strHTARAM & strHTARAMState & _
' VbCrLf & " " & strHTAHDD & strHTAHDDState
iTimer = window.setTimeout("Abort", iAbortTimeout, "VBScript") 'Abort (close) after n seconds
'MsgBox strErrorMsg,vbExclamation,msgTitle
'ErrBar.class=""
ElseIf iErrMode=2 Then
'Warning
StatusBar.InnerText=StatusBar.InnerText & VbCrLf & strErrorMsg & " " '& "(" & Err.Description & " :" & Err.Number & ")"',vbExclamation,msgTitle
Err.Clear
End If
End Function
'====================================================
Sub Abort
'Aim: Quit gracefully
window.close()
End Sub
</script>
<!-- #region BODY -->
<body>
<br />
<div>
<span style="version"> <span id="VersionSpan"></span></div>
<div style="text-align: center;">
<H1 style="font-family: Arial, Helvetica, sans-serif; font-size: large; text-align: center; color: #000000; text-transform: capitalize">System information</H1>
<span>
<table border="1" cellspacing="0" cellpadding="0" style="width: 912px"
id="SysInfoTable">
<tr class="h1">
<td align="right" class="Header1" style="width: 76px; height: 18px">
</td>
<td align="right" class="Header1" style="height: 18px"><em id="VendorCaption">Vendor</em></td>
<td align="left" class="style2" style="height: 18px"><span id="Vendor"></span></td>
<td align="right" class="Header2" style="height: 18px"><em id="ModelCaption">Model</em></td>
<td align="center" class="style4" style="width: 400px; height: 18px"><span id="Model"></span></td>
</tr>
<tr>
<td align="right" class="Header1" style="width: 76px">
</td>
<td align="right" class="Header1"><em id="ProductCaption">Product ID</em></td>
<td align="left" class="style2"><span id="Product"></span></td>
<td align="right" class="Header2"><em id="RAMCaption">Memory(in MB)</em></td>
<td align="left" class="style4" style="width: 400px"><span id="RAM"></span></td>
</tr>`
<tr>
<td align="right" class="Header1" style="width: 76px">
</td>
<td align="right" class="Header1"><em id="CPUCaption">CPU speed (in GHz)</em></td>
<td align="left" class="style2"><span id="CPUspeed"></span></td>
<td align="right" class="Header2"><em id="CPUInfoCaption">No: CPU\Cores</em></td>
<td align="left" class="style4" style="width: 400px"><span id="CPUInfo"></span></td>
</tr>
<tr>
<td align="right" class="Header1" style="width: 76px">
</td>
<td align="right" class="Header1"><em id="DiskFSCaption">Filesystem info</em></td>
<td align="left" class="style2"><span id="HDDFS"></span></td>
<td align="right" class="Header2"><em id="CapableArchCaption">Architecture</em></td>
<td align="left" class="style4" style="width: 400px"><span id="CapableArchitecture"></span></td>
</tr>
<tr>
<td align="right" class="Header1" style="width: 76px">
</td>
<td align="right" class="Header1"><em id="BIOSVerCaption">BIOS version</em></td>
<td align="left" class="style2" ><span id="BIOSVERSION"></span></td>
<td align="right" class="Header2"><em id="BIOSDateCaption">BIOS Date</em></td>
<td align="left" class="style4" style="width: 400px"><span id="BIOSDate"></span></td>
</tr>
</table>
</span>
</div>
<div class="StatusBar">
<br />
<Span id="StatusBar">Loading...please wait.</Span>
</div> <br><br>
<div align="center">
<input type="button" name="btnStop" id="btnStop" value="Continue" onclick="Abort">
<input type="Button" value="Re-Scan Machine" name="button1" onClick="Window_Onload" class="button">
</div>
</body><!-- #endregion -->
</html> -
VirtualBox fails with script error on Wizard.hta
Hi there.
We have MDT working successfully for physical client machines but when attempting to install via VirtualBox we get an error after the PXEBOOT and WinPE stages. It is when the Wizard.hta script attempts to run and we see a window stating "Wizard.hta
Script Error".
If anyone can think what might be causing this or how I can troubleshoot this further it would be most appreciated.
Thanks.Ran it again and now get the following:
Script: X:\Deploy\Scripts\ZTIGather.wsf
Line: 0
Char: 1
Error: : VBScript
Code: 800705AA
Source: Windows Script Host
I can press F8 to get a command prompt and see the file.
Unsure of the error code. -
OSD HTA and Task Sequence Variable
Have a unusual issue that I cannot seem to find a answer anywhere or if it's even possible. I'm am very aware on how to setup a HTA to pass variables to the Task Sequence but there is a point where I want the HTA to display the current value of a TS Variable(s).
It's a custom variable that is set on a prior step via a VB script. Anyone know of a simple way to call and display the value in HTML/HTA.The variables are available using the same COM Object that you use to set them: Microsoft.SMS.TSEnvironment. The below VBScript will dump every variable to the screen. You can take this and just add it something you've displayed in your HTA like a static
control or text box.
Set env = CreateObject("Microsoft.SMS.TSEnvironment")
Wscript.echo "Dump of All Task Sequence Variables"
For Each TSvar In env.GetVariables
Wscript.echo "Variable " & TSvar & " = " & env(TSvar)
Next
Jason | http://blog.configmgrftw.com | @jasonsandys -
HTA application queries to AD in windows PE
Hi all,
i have created a hta application which checks for users in a specific OU and sets a TS variable to true if the user exist in that OU and false if they don't.The script is running in win-PE mode but when i am using my username to login it looks like it's
not able to query ad for the user and always sets the TS variable to false.
rest of the TS runs only when the variable is set to true else it shutdowns the machine.
Script is working fine when executed manually.
how to make HTA to connect to AD in Win-pe mode.(this hta script is calling a vb function to connect to AD).
Thanks
Pranay.This is the script i am using :-
<HEAD>
<style type="text/css">
@import url("pos.css");
</style>
<TITLE>
Login :
</TITLE>
<hta:application id="objAD"
applicationname="AD Query"
icon="Graphics\title.ico"
Border="thin"
Scroll="NO"
Maximizebutton="no"/>
</HEAD>
<SCRIPT LANGUAGE="VBScript">
sub Window_onLoad
window.resizeTo 400,400
End sub
function fnCheckAccess()
strDomain = "Server"
strUserID=Username.value
strUserPWD=password.value
MsgBox strDomain
MsgBox strUserID
MsgBox strUserPWD
const ADS_SECURE_AUTHENTICATION = &h0001
const ADS_CHASE_REFERRALS_ALWAYS = &H60
dim objDSO
dim objUser
dim strPath
strPath = "LDAP://" & strDomain & "/OU=Users,DC=" & strDomain
On Error Resume Next
set objDSO = GetObject("LDAP:")
set objUser = objDSO.OpenDSObject (strPath, strUserID, strUserPWD, ADS_SECURE_AUTHENTICATION OR ADS_CHASE_REFERRALS_ALWAYS)
if Err.Number <> 0 then
MsgBox "Incorrect Password for " & g_strDomain & "\" & g_strUserID & "." & vbCRLF & vbCRLF & "Error " & Err.Number & ": " & Err.Description, 16, "Access Denied"
fnCheckAccess = False
else
fnCheckAccess = True
end if
Err.Clear
On Error Goto 0
Set env = CreateObject("Microsoft.SMS.TSEnvironment")
set oTSProgressUI = CreateObject("Microsoft.SMS.TSProgressUI")
oTSProgressUI.CloseProgressDialog()
env("ALLOWOSDBUILD") = "NO"
If fnCheckAccess = "True" then
env("ALLOWOSDBUILD") = "YES"
End If
set objDSO = Nothing
set objUser = Nothing
end function
function Clear()
Username.value = ""
password.value = ""
end function
</SCRIPT>
<BODY Background="Graphics\sheet2.jpg" text="#000000" >
<font face="segoe ui light"><H3><center>To Start Deployment enter username password</center></H3></font>
<div id=T1>
Username: <input type="text" name="Username">
</div>
<div id=T2>
Password: <input type="password" name="password">
</div>
<input id=add type="button" value="Login"_name="run_button" onClick="fnCheckAccess">
<input id=Clear type="button" value="Clear"_name="run_button" onClick="Clear">
</p>
</BODY>
Script is running fine when executed in deployed os but in win pe mode it's failing to connect with ad.
Please help.
Thanks
Pranay. -
Having problem with x-ua-compatible" content="IE=11 and Script in HTA
I'm trying to modify the gradient demo found here https://social.technet.microsoft.com/Forums/forefront/en-US/7e146a5e-11cb-42ae-abbe-fe757ed539f9/gradient-not-working-on-htas-in-windows-8 with a button but I can't make it work
As long as I have <meta http-equiv="x-ua-compatible" content="IE=11" /> my HTA says that test is not defined but I have the gradient background
IF i comment out this line test works but I will not get the gradient background
I really would like to have both :)
Can anyone assist
<html>
<head>
<title>Gradient Example</title>
<meta http-equiv="x-ua-compatible" content="IE=11" />
<HTA:APPLICATION
APPLICATIONNAME="Gradient Example"
ID="GradientExample"/>
</head>
<script language="VBScript">
sub test
msgbox "Hello"
end sub
</script>
<body STYLE="background-image: linear-gradient(to right, #000000 0%, #0000FF 100%);
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#000000', EndColorStr='#0000FF');
height: 100%;
margin: 0;
background-repeat: no-repeat;
background-attachment: fixed;
font: 14 pt arial;
color: white;">
Is this cool or what?
<center><BUTTON onclick="test">Exit</BUTTON>
</center>
</body>
</html>Here is one way to make vbscript work:
<!DOCTYPE html>
<html>
<head>
<title>Gradient Example</title>
<HTA:APPLICATION
APPLICATIONNAME="Gradient Example"
ID="GradientExample"
/>
<script type="text/vbscript" language="vbscript">
Sub vbxit
MsgBox "VB Goodbye!"
window.close
End Sub
</script>
<script type='text/jscript'>
function xit(){
alert("JS Goodbye!");
window.close();
</script>
<style>
body{
background-image: linear-gradient(to right, #000000 0%, #0000FF 100%);
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr='#000000', EndColorStr='#0000FF');
height: 1000px;
margin: 0;
background-repeat: no-repeat;
background-attachment: fixed;
font: 14 pt arial;
color: white;
</style>
</head>
<body>
<h2>Is this cool or what?</h2>
<center><input type='button' onclick="xit()" Value='Exit'></center>
<center><input type='button' onclick="vbxit" Value='Exit2'></center>
</body>
</html>
\_(ツ)_/ -
ODBC access from HTA script fails
I am trying to connect to Oracle via ADO from a HTA(HTML Application) script.
I have trying both DSN and DSNLESS connections, see code below.
I have also tried the Microsoft ODBC for Oracle, Oracle 9i ODBC and Oracle10g ODBC drivers.
I have tried doing the connection from both vbscript and javascript.
Everything I try gives me the "[Microsoft][ODBC Driver Manager} Driver's SQLSetConnectAttr failed" error.
Any help will be greatly appreciated!
*** CODE ***
<script Language="JavaScript"><!--
function dotheconnectionx()
var sConnect="DSN=prod2;UID=tts;PWD=tts";
var objConnx= new ActiveXObject( "ADODB.Connection" );
objConnx.Open( sConnect );
alert(objConnx.errors.count);
alert(objConnx.errors(0).description);
//--></script>
<script language="vbscript">
Dim objConn
Dim rsetQuery
Dim tmpSQL
Dim tmpDSN
tmpDSN="DSN=prod2;uid=tts;pwd=tts"
Dim strConn
strConn="Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=prod; uid=TTS; pwd=tts;"
sub dotheconnection
Set objConn = CreateObject("ADODB.Connection")
objConn.ConnectionString = tmpDSN
objConn.Open
If objConn.errors.count <> 0 Then
alert(objConn.errors.count)
alert("problem connecting to the database")
alert(objConn.errors(0).description)
alert(objConn.ConnectionString)
end if
end sub
</script>
<body onload="dotheconnection();">This is running off my laptop for development and I have several version of the Oracle client installed. Specifically 8, 9 and 10.
I can connect via ODBC from a query tool using the specified DSN and can connect to the specified database using several Oracle tools.
I haven't tried doing this from a VBS but I will try that to see if it works or gives any diagnostic info
I tested as a vbscript .VBS and get the same results and the .HTA
*** vbscript code ***
Dim objConn
Dim rsetQuery
Dim tmpSQL
Dim tmpDSN
tmpDSN="DSN=prod2;uid=tts;pwd=tts"
Dim strConn
strConn="Driver={Microsoft ODBC for Oracle}; CONNECTSTRING=prod; uid=TTS; pwd=tts;"
sub dotheconnection
Set objConn = CreateObject("ADODB.Connection")
objConn.ConnectionString = strConn
objConn.Open
If objConn.errors.count <> 0 Then
Wscript.echo objConn.errors.count
Wscript.echo "problem connecting to the database"
Wscript.echo objConn.errors(0).description
Wscript.echo objConn.ConnectionString
end if
end sub
dotheconnection()
Edited by: JL Hainsworth on Mar 10, 2009 1:32 PM -
OSD: end of TS: hta with message, ok then reboot
Hi,
We would like to have a hta at the end of the task sequence which shows a predefined text then an ok button which reboots the pc. Rest of desktop should not be usable.
Any examples on howto do that?
J.
Jan HoedtTry the script below, it should do the thing.
cscript.exe "%SCRIPTROOT%\MDTMessageBox.wsf" /text:"Applications Installed" /type:64 /title:"Close"
<job id="MDTMessageBox">
<script language="VBScript" src="ZTIUtility.vbs"/>
<script language="VBScript">
'# MICROSOFT LEGAL STATEMENT FOR SAMPLE SCRIPTS/CODE
'# This Sample Code is provided for the purpose of illustration only and is not
'# intended to be used in a production environment.
'# THIS SAMPLE CODE AND ANY RELATED INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY
'# OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
'# WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
'# We grant You a nonexclusive, royalty-free right to use and modify the Sample Code
'# and to reproduce and distribute the object code form of the Sample Code, provided
'# that You agree:
'# (i) to not use Our name, logo, or trademarks to market Your software product
'# in which the Sample Code is embedded;
'# (ii) to include a valid copyright notice on Your software product in which
'# the Sample Code is embedded; and
'# (iii) to indemnify, hold harmless, and defend Us and Our suppliers from and
'# against any claims or lawsuits, including attorneys’ fees, that arise
'# or result from the use or distribution of the Sample Code.
' // ***** Script Header *****
' // Solution: Solution Accelerator - Microsoft Deployment Toolkit
' // File: MDTMessageBox.wsf
' // Purpose: Custom script to display a MsgBox or Popup box during LTI.
' // Usage: cscript.exe MDTMessageBox.wsf /text:"<message text>"
' // [/type:<button/icon type>] (MsgBox buttons argument value: http://msdn.microsoft.com/en-us/library/sfw6660x(v=VS.85).aspx)
' // [/title:"<title of the pop-up message box>"]
' // [/seconds:<seconds the pop-up message box is displayed>]
' // [/returnexit] (If specified, the button click return value will be used as the script exit code.)
' // [/returnvar:<task sequence variable to set with the button click return value]
' // Version: 1.0.2
' // History:
' // 1.0.0 MDM 06/04/2010 Created initial script.
' // 1.0.1 MDM 06/23/2011 Added /returnexit switch.
' // 1.0.2 MDM 06/23/2011 Added /returnvar switch.
' // ***** End Header *****
'// Global constant and variable declarations
'Option Explicit
Dim iRetVal
'// End declarations
'// Main routine
On Error Resume Next
iRetVal = ZTIProcess
ProcessResults iRetVal
On Error Goto 0
'// Function: ZTIProcess()
'// Input: None
'// Return: Success - 0
'// Failure - non-zero
'// Purpose: Perform main ZTI processing
Function ZTIProcess()
oLogging.CreateEntry "------------ Initialization " & oUtility.ScriptName & " -------------", LogTypeInfo
ZTIProcess = Success
sText = ""
bUsePopup = False
bButtonReturnIsExitCode = False
nType=0
iScriptFailure = 8
If WScript.Arguments.Named.Exists("text") Then
sText = WScript.Arguments.Named.Item("text")
oLogging.CreateEntry "The /text switch specified with value: " & sText, LogTypeInfo
Else
oLogging.CreateEntry "The /text switch must be specified. Exiting script.", LogTypeError
ZTIProcess = iScriptFailure
Exit Function
End If
If WScript.Arguments.Named.Exists("title") Then
sTitle = WScript.Arguments.Named.Item("title")
oLogging.CreateEntry "The /title switch specified with value: " & sTitle, LogTypeInfo
End If
If WScript.Arguments.Named.Exists("type") Then
nType = WScript.Arguments.Named.Item("type")
If (IsNumeric(nType) = False) Then
oLogging.CreateEntry "The /type switch must a numeric value. Exiting script.", LogTypeError
ZTIProcess = iScriptFailure
Exit Function
Else
oLogging.CreateEntry "The /type switch specified with value: " & nType, LogTypeInfo
End If
End If
If WScript.Arguments.Named.Exists("seconds") Then
bUsePopup = True
nSecondsToWait = WScript.Arguments.Named.Item("seconds")
If (IsNumeric(nSecondsToWait) = False) Then
oLogging.CreateEntry "The /seconds switch must a numeric value. Exiting script.", LogTypeError
ZTIProcess = iScriptFailure
Exit Function
Else
oLogging.CreateEntry "The /seconds switch specified with value: " & nSecondsToWait, LogTypeInfo
End If
End If
If WScript.Arguments.Named.Exists("returnexit") Then
bButtonReturnIsExitCode = True
oLogging.CreateEntry "The /returnexit switch specified. The button click return value will be used as the script exit code.", LogTypeInfo
End If
If WScript.Arguments.Named.Exists("returnvar") Then
sTSVariable = WScript.Arguments.Named.Item("returnvar")
oLogging.CreateEntry "The /returnvar switch specified with value: " & sTSVariable, LogTypeInfo
Else
sTSVariable = "MessageBoxReturn"
oLogging.CreateEntry "The /returnvar was not specified. Default task sequence variable of MessageBoxReturn will be used.", LogTypeInfo
End If
If bUsePopup Then
intButton = oShell.Popup(sText, nSecondsToWait, sTitle, nType)
Else
intButton = MsgBox(sText, nType, sTitle)
End If
oEnvironment.Item(sTSVariable) = intButton
oLogging.CreateEntry "Button value returned: " & intButton, LogTypeInfo
If bButtonReturnIsExitCode Then ZTIProcess = intButton
oLogging.CreateEntry "------------ Departing " & oUtility.ScriptName & " -------------", LogTypeInfo
End Function
</script>
</job>
Juke Chou
TechNet Community Support -
HTA VBS errors in WinPE are blank! Why?
Hi folks,
I have an HTA which has some VBS.
Whenever I get a script error, a blank dialog box appears. Blue top bar, with an X, no text, and a large white box, no text or buttons.
The WinPE version we are using, if I type VER, is 6.1.7600.
Any ideas why this happens... and how to fix it? Would be really handy to know what line my script errors occur on. At the moment I have to put msgbox's in to try to catch where the error lies.
Thanks."You should not use the Body "onload" to generate an error. There is no UI when the onload
event is fired. onload is usually used to set up variables prior to display of the body."
The same problem happens if I present a button in HTML and fire the function that way. It is not related to the onload event. Regardless of whether it's a button trigger or an onLoad trigger (or any other event), the error appears in Windows 7, but not Windows
PE. I just used the onLoad event in my example to show a quick issue without any interaction.
"Errors in HTML/HTA are not handled the same as in VBScript an are platform sensitive. JUst
write good HTA code and debug it prior to running on PE."
As you mentioned, platform sensitive. Something that runs in Windows 7 may not run in WinPE due to missing
components and other issues. I need to debug in PE for the solutions I am creating.
"The MDT currently eliminates the need for an HTA in most cases. Try using the MDT to
build your UI interaction."
Doesn't help my issue here. My question remains; I'm trying to find the answer to a specific question,
not workarounds or alternatives.
"Deployment issues with PE are better posted in the deployment forum ass there is a larger body of
expertise there."
I'm not deploying anything... but I would be happier to post in a PE forum if there is one as this isn't
particularly a scripting issue (there is no code problem). Would you regard the deployment forum a PE forum? If so, I'll move over there. Otherwise, do you have a better suggestion that would act as a PE forum? -
Ipod and Windows Vista - VBScript
When trying to downlaod Itunes 7.1.1 - I am getting an error message "Itunes can not be installed beacuse Visual Basic Script is not installed or has been diabled". Dell tried downlaoding it still the same error message. They say Apple is not compadable with Itunes yet.
even though the following document talks about Windows XP rather than Vista, try using the instructions for registering VBScript.dll from it:
iTunes and QuickTime for Windows cannot be installed without Visual Basic Script (VBScript) -
Can No Longer Read Uninstall Keys with vbscript package run by SCCM
Hi,
I've been using vbscript packages in SCCM for over a decade, and one thing I do is use the registry to determine if I need to uninstall an old program with the Value:
HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\
or
HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall
Example code snip:
UnstKey = "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{81BE0B17-563B-45D4-B198-5721E6C665CD}"
UnstVal = wshShell.RegRead(UnstKey & "\UninstallString")
If I run this manually, it works great, but all of a sudden, when I run a vbscript like this in SCCM it now returns:
Invalid root in registry key "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{...}\UninstallString"
I normally run everything whether or not a user is logged on as System, but I did a test, and it even fails if I run the package as the user, which really surprised me. I check permissions in registry key, and Everyone has read, System has Modify.
This code was working about a month ago. No changes to SCCM that I know. Sadly, we are still running 2007 SP2
Please help!If anyone else stumbles on this issue, you're almost certainly running into the issue with 64bit clients. Config Manager Agent runs as a 32bit process so won't read the registry key from the location you're expecting. This uninstall strings will
be in the following location:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\
If you need an existing VBScript to run you'll want to call the following:
%windir%\Sysnative\wscript.exe
Hope this helps. I should have spotted this with my Config Manager earlier. Had me scratching my head for a while. -
Need help in writing a vbscript
Hi,
I need help in wring a vbscript. I have serached for the vbscript on the net, but could not find any.
I need to add a file to an msi using vbscript. - That's the requirement.
For this I have done the following with the help of vbscript.
1. With the insert statement I inserted a new copmonent in the FeatureComponent Table.
2. Now the next thing I did is, I inserted a new row in the File table using insert statement again. The file is uncompressed.
3. Since the file is a non-version file I also added a row in the MSIFileHash table.
4. Also, now added the Component in the component table.
After doing this I am able to see the chnages in the mst, however whrn I try to install it I get an error 2725 (Invalid database tables).
Can somebody please post a vbscript which can add a file to an msi?Hi All,
Thanks for all your responses.
Yes, It is not so easy. I never said it was. Thanks for pointing out Orca. We use Orca on a daily basis.
What exactly I am looking at, is this.
We have some standard applications which needs to be repackaged every month. The repackaging process is same and does not change at least for these packages. So I was actually looking at automating these things.
What I did so far.
First we have created an object for Windows installer. I have then taken a copy of the original msi and then opened the database of this temporary msi database in transact mode. Once the database is opened we can use select, insert, update
and delete statements to update the database.
I could successfully add a registry to the msi. The component was also added successfully to the component table. I also could make changes to the Property table.
The tricky part comes with the addition of file to the file table.
The addition of file requires the following steps.
1. Add a new row to the file table. This can be done with the Insert statement.
2. We then need to associate the file to a new component or any other component already existing in the msi. In my case I am creating a new component.
3. We then have to associate this components to a feature in the FeatureComponents table.
4. Since the file I am adding is a non-versioned file, a new row also has to be added to the MSIFILEHASH table.
I could see the changes that I have done using the mst. But when I try to install the msi with the mst, I get the error 2725. I checked everything. All the other steps except for the file addition works fine.
To check whether I am indeed right, I have did this.
Skipped the file addition part to the msi. Every other change that I make works and I am able to install the msi with the mst successfully.
For obvious security reasons I will not be able to share the vbscript with you. If you guys think, that this is not a right forum for this question, please let me know the right forum. I have been stuck with this issue from the past 6 months. Any help would
really be appreciated. -
VBScript editor with Intellisense/Code Hinting support for Adobe App
I am looking for some tool to write my InDesign VBScript files in. I would really like to know if there is any which support Intellisense/Code hinting for Adobe programs (InDesign especialy). Do you have anything to recommend?
I am quite good at hacking my computer, so no registry change etc. is a problem for me, I just can not find any. I already tried PrimalScript 2009 but it doesn not work.
What I need is that in following block of code
Set myInDesign = CreateObject("InDesign.Application.CS4")
Set myDialog = myInDesign.Dialogs.Add
I will get list of all methods/properties after I write the dot after "myInDesign" in second line. But it never worked. I even tried to put "InDesign.Application.CS4/C:\ProgramData\Adobe\InDesign\Version 6.0\cs_CZ\Scripting Support\6.0\Resources for Visual Basic.tlb" line into Options>Text editor>Type libraries.
I am using Windows Vista SP1 and I have Adobe Creative Suite CS4 installed (upgrade from CS3 which was upgraded from CS2)
Thanks a lot for any help/suggestion, as I start feeling desperate.Hi Everyone!
As I have said, I waited for next service release, which is as of now PrimalScript 2009 version 5.0.614 and I did some testing with it.
Results:
WinXP EN Professional
- Just pointing PrimalScript 2009 to typelib, no creative suite installed, working
- Installed Creative Suite CS3 Czech (trial mode) - Working, no need to setup anything
- Installed Creative Suite CS3 + CS4 Czech (trial mode) - Need to point PrimalScript 2009 to correct typelib, then 100% working
Windows Vista SP1 Ultimate EN (in trial/not activated mode)
- Just pointing PrimalScript 2009 to typelib, no creative suite installed, working
- Installed Creative Suite CS3 Czech (trial mode) - Need to point PrimalScript 2009 to correct typelib, then 100% working
- Installed Creative Suite CS3 + CS4 Czech (trial mode) - Need to point PrimalScript 2009 to correct typelib, then 100% working
Windows 7
I am not planning to use Win7 in near future, so I did not not run any test on it.
Windows Vista SP1 Home Premium Slovak (fully activated)
- Installed Creative Suite CS3 + CS4 Czech (full mode) - Not working. This is my main machine. It is Creative Suite CS2 upgraded to CS3 then CS4 (it is running for years without reinstall). I use CS3/CS4 side by side for some older projects. There are still references to CS2 in registry. I tried pointing PrimalScript 2009 to correct typelib, but to no avail. My conclussion is that there is someting messed with its config or registry, but I am pretty sure it would run after complete system reinstall.
Both WinXP EN Pro and Vista SP1 Ultimate EN were clean install into MS Virtual PC 2007, with only Creative Suite and PrimalScript 2009 5.0.614 installed into each machine so I made sure there are no other issues involved.
As I spend 80% of my time with developement of websites and scripting of MS Office/Creative Suite, I have some virtual machines set up for testing purposes. I will use one of them for development in PrimalScript and move it to main (real) Windows Vista Home Premium Slovak installed once I will decide to completely reinstall it. The need for seting up the typelibray link is no deal for me, as it is working as expected then, and I expect a lot ;-)
So problem solved, I found o program I will use. There may be others which do better or are cheaper (but I do not know about any) but $299 is not a big issue when I get what I want.
P.S.: The solution with making VBScript code with VBA declaration (using Dim) is not a solution I like, as I would need to comment it out everytime I run/edit the script and it would be pain in the *** while debugging it as i would need to do lot of comment/uncomment cycles and i can use my ime better then doing the monkey work as some fo the scripts I write are quite huge and I prefer to build them incrementaly and test/debug a lot.
I wish to thank everyone for their help and suggestions,
Matus
Maybe you are looking for
-
Hi All, I have been observing, there is a lot of below mentioned logs in sm21. "Enqueue: Lock group 0D contains invalid lock mode /. Lock object ED" Can u plz any one comment on this log meesage, why this is comming. Thanks in advance..
-
The SGA was inadequately sized, causing additional I/O or hard parses.
Dear all, We are using 10g RAC On Solaris 5.10 Very freuently,we are getting the below message in DB Console The SGA was inadequately sized, causing additional I/O or hard parses. Additional Information The value of parameter "sga_target" was "15360
-
Hi experts, Is it possible to upload data from local drive(presentation server) to sap in background mode. As I know ,in the background mode we can upload files from application server only. but here my functional consultant saying they did upload d
-
Where is the customs duty maintained - in PO or MIGO ?
where is the customs duty maintained - in PO or MIGO ?
-
Quicktime iPhoto Slideshow to iPod
Took iPhoto slideshow and exported it to iDVD. In the process it creates a Quicktime movie which can be moved to iTunes video and played. But when iPod is connected it says it cannot load it. Message suggests I convert format for iPod but only conver