error while runnning ado vbs in Windows PE

K

Koen

Hello,

Another ADO problem with Windows PE 1.2. I'm using the script below to
update a record in an SQL database. Becouse Windows PE does'nt support ADO
in HTA files properly (so it seems), i had to use a regular vbs script. But
when i run this one it gives me an error that the class isn't registered, im
getting reeealy tired of running into this kind of errors, why say that
Windows PE supports ADO while it really doesn't do a good job!

Ok, i am still using Windows PE 1.2, with the new
'buildoptionalcomponents.vbs'. This is becouse Ms has not yet updated the
msvl website...
When i run the script it gives me code: 80040154 line: 34 char:1 error:
'Class not registered' source: provider

Thanks for your time and any help.

Koen.

This is the script: (don't mind the incorrect line brakes)

'Opiton Explicit
'On Error Resume Next
Dim Catalog, SQLQery1, PWD, USERNAME, SERVER, strREG
Dim objDBConnection, objRecordSet

Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3

Set objShell = Wscript.CreateObject("Wscript.Shell")

'haal waarden op uit register
strBestand = objShell.RegRead("HKLM\Software\GWIS\Bestand")
strPartitie = objShell.RegRead("HKLM\Software\GWIS\Partitie")
strMacAdres = objShell.RegRead("HKLM\Software\GWIS\MacAdres")
strOmgeving = objShell.RegRead("HKLM\Software\GWIS\Omgeving")
strNaam = objShell.RegRead("HKLM\Software\GWIS\Name")

'Maak een connectie naar de database
set objDBConnection = Wscript.CreateObject("ADODB.Connection")
set objRecordSet = Wscript.CreateObject("ADODB.Recordset")

SERVER = "192.168.2.1"
USERNAME = "sa"
PWD = "password"
Catalog = "Images"

objDBConnection.ConnectionString = "Provider=SQLOLEDB;Data
Source="&SERVER&";Initial Catalog="&Catalog&";User
ID="&USERNAME&";Password="&PWD&";"
objDBConnection.Open

objRecordSet.CursorLocation = adUseClient
objRecordSet.ActiveConnection = objDBConnection

'This line below is line 34 in the script...
objRecordSet.Open "SELECT * From " & strOmgeving , objDBConnection,
adOpenStatic, adLockOptimistic
objRecordSet.MoveFirst

objRecordSet.Find = "Mac = '" & strMacAdres & "'"
If objRecordSet.EOF then
objRecordSet.MoveFirst
objRecordSet.Find = "Mac = 'leeg'"
If objRecordSet.EOF Then
strError = "Geen vrije station namen meer in de " & strOmgeving
& " omgeving."
Errors()
End If
objRecordSet("Mac") = strMacAdres
objRecordSet.Update
End If
strREG = objRecordSet("Naam")
objRecordSet.Close
objDBConnection.Close

Sub Errors()
Wscript.Echo strError
Wscript.Quit
End Sub

Msgbox "De naam van dit station is: " & strREG
'objShell.RegWrite "HKLM\Software\GWIS\QueryResult", strREG, "REG_SZ"
Wscript.Quit()
 
J

Johan Arwidmark

Hi Koen,

The script seems to works fine for me in Windows PE. Could you please
provide the database structure with some fictive samples?

Regarding the problem with using ADO in HTA pages I have some (sort of
bad) updates...

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.

regards
Johan Arwidmark

Windows User Group - Nordic
http://www.wug-nordic.net
 
K

Koen

Hello Johan,

You again! i'm getting the feeling were all alone in this... :)

Becouse the script and database setup is for testing only the script and
database setup are very basic and only used to test the core functionality
of the script. (at the moment)

The database structure is as follows:

There is a container named: 'Images' wich contains the table's: 'Images',
'Office' and 'Laboratorium'. The only Table that matters to this script is
the Office or Laboratorium table (that is the 'omgeving'=environment wich
was determined earlier in another hta script.) in those tables are two rows
named: Naam and Mac wich basicaly explain theirselves. The default value for
Mac is 'leeg' (meaning empty, this becouse i did't get a Select query to get
empty tables and was to lazy to look in to it at that moment...) The purpose
of the script is to find or determine the current computer's Name by
checking if it's Mac adress is in one of the 'Mac' tables (wich was ofcourse
put there earlier) and then retreve the (computer name) 'Naam'. If there is
no linking yet between the computer's mac and a name then create one and
retreve the name of the workstation: 'Naam'.

Thats all... real simple.

I know there is some overhead in this script, that is becouse it uses the
output of other scripts to determine the values of the variables used,
delete them if you like. In this script i only wanted to test the
manipulation of a single record actually...

By the way, i tested this script on the test server and it worked fine for
me to... Only when i use the same script in Windows PE it gives me the
'Class not registered' error. But as i said before i'm still using v1.2 what
version did you use?

Thank you for your time and any help.

Koen.
 
J

Johan Arwidmark

Hi Koen

Well it sure looks like there are not that many people using Windows
PE for Enterprise Deployment Solutions...:)


Anyway....

The error is caused by the objRecordSet.CursorLocation = adUseClient
line and the fact that you are using adLockOptimistic as locktype...

Windows PE 1.2 by default does not support that..(why I don't know)


Workaround:
Remove the objRecordSet.CursorLocation = adUseClient line

Change LockOptimistic to the default adLockReadOnly (don't forget to
add the const). Since this will stop you from updating the recordset
you need to use another method to update the SQL database, I have
successfully (in other solutions well as in your script) used the
following method from Windows PE 1.2

strSQL = "INSERT INTO Office (Naam,Mac) VALUES ('compname001','" &
strMacAdres & "') "
objDBConnection.Execute strSQL,, adCmdStoredText


regards
Johan Arwidmark

Windows User Group - Nordic
http://www.wug-nordic.net
 
K

Koen

Hi Johan,

Thank you for this post, I got it working now with Windows PE 2004.
I used the following:

strSQL = "UPDATE Office SET Mac = '"& strMacAdres &"' WHERE Naam =
'compname001'"
objDBConnection.Execute strSQL,, adCmdStoredText

Becouse I only wanted to update the record.
But i'm very happy that everything works now, so i can further develop this
deployment system...

Regards,

Koen.
 

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


Top