Windows PE, HTA, SQL - Error

K

kederstedt

Hi

Can someone explain to me why I can run one VBS file and one HTA file
on my local computer (windows XP pro), but on another computer (Windows
PE) the HTA file fails. The HTA file just stops and I get no error
message, but the error is when I create the SQL connection object and
the recordset object. Both scripts contains SQL connection to
Northwind. I made a simple HTA file with just one MessageBox and that
file worked fine.


You can see both my scripts below


------- VBS -------
' Declare the variables
Dim objConn
Dim objRst
Dim strSQL
Dim strServer
Dim strDatabase
Dim strUserName
Dim strPassword
Dim strDisplay

' Set server, database and username
strServer = "MyComputer"
strDatabase = "Northwind"
strUserName = "sa"
strPassword = "password123"

'Create and open the database object
set objConn = CreateObject("ADODB.Connection")
set objRst = CreateObject("ADODB.Recordset")

strSQL ="SELECT FirstName, LastName FROM Employees "
objConn.open "Provider=SQLOLEDB;Data Source=" & strServer & ";Initial
Catalog=" & strDatabase & ";User ID=" & strUserName & ";Password=" &
strPassword & ";"

Set GetRst = objConn.Execute(strSQL)

If Not GetRst.EOF Then

strDisplay = "Users from the Employees table: " & vbcrlf & vbcrlf

Do While Not GetRst.EOF
strDisplay=strDisplay & GetRst("FirstName") & " " &
GetRst("LastName") & vbcrlf
GetRst.MoveNext
Loop

MsgBox strDisplay

Else

MsgBox "No data in Recordset"
End If

------- END VBS -------



-------- HTA --------

<HTA:APPLICATION ID="oBDDID"
APPLICATIONNAME="BDDIB"
BORDER="thin"
CAPTION="yes"
ICON="oemlogo.jpg"
SCROLL="auto"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
WINDOWSTATE="normal" />
</head>


<script language="vbscript">
' Declare the variables
Dim objConn
Dim objRst
Dim strSQL
Dim strServer
Dim strDatabase
Dim strUserName
Dim strPassword
Dim strDisplay

' Set server, database and username
strServer = "MyComputer"
strDatabase = "Northwind"
strUserName = "sa"
strPassword = "password123"

'Create and open the database object
set objConn = CreateObject("ADODB.Connection")
set objRst = CreateObject("ADODB.Recordset")

strSQL ="SELECT FirstName, LastName FROM Employees "
objConn.open "Provider=SQLOLEDB;Data Source=" & strServer & ";Initial
Catalog=" & strDatabase & ";User ID=" & strUserName & ";Password=" &
strPassword & ";"

Set GetRst = objConn.Execute(strSQL)

If Not GetRst.EOF Then

strDisplay = "Users from the Employees table: " & vbcrlf & vbcrlf

Do While Not GetRst.EOF
strDisplay=strDisplay & GetRst("FirstName") & " " &
GetRst("LastName") & vbcrlf
GetRst.MoveNext
Loop

msgbox strDisplay

Else

msgbox "No data in Recordset"

End If


</script>


------- END HTA -------
 
J

Johan Arwidmark

Regarding using ADO in HTA pages in WinPE I have some (sort of
bad) news...

ADO implementation internally checks if it’s running in script inside
a hosting container. When you run the VBS in Windows PE this
condition check is always false. So the rest of the ADO connection
opening code can run and succeed without further IE trusting/scripting
security checks.

When you run the HTA, this internal checking is done which
necessitates the rest of the IE trusting/scripting security checks.
But WinPE doesn’t have any of the IE trusting/scripting security
implementation. So the internal security checks fails. As a result,
the code bails and the ADO Connection open() fails.

Shorthand: ADO and HTA doesnt work very well together in WinPE :)

Use vbscript or a VB app instead

regards

Johan Arwidmark
Microsoft MVP - Setup/Deployment
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

WinPE + HTA + SQL = Error 0
Add Records to a Table 2
ADO OpenDatabaseConnection 2
Add new records to table 3
Very lost 5
ADODB HELP 7
Change font size and colour in footer through VBA 4
Can't find my error 6

Top