Supporting multiple versions...

M

Martin Waller

Hello,

The problem I am having is I don't know for sure what version of the OWC the
client has installed when the ASP page is run. To get round this problem I'm
depositing a <DIV> tag in the HTML sent to the client and running client
side Javascript to detect the OWC version and hence the class id by reading
the registry and then replacing the innerHTML associated with the <DIV> with
an <OBJECT> tag for the OWC component. The code to return the class id given
below and the code to do the replacement looks like:

SS = SpreadSheetClassID(); // Get the OWC SpreadSheet Class ID
if (SS.length != 0) // If we have one installed
{
//
// At this point the HTML for the page does not have the
<OBJECT> tag
// referencing the SpreadSheet in it. It simply has a <DIV> tag
that is
// being used as a place holder. Here we need to replace the
HTML for
// the <DIV> with the <OBJECT> tag that references the correct
OWC
// Spreadsheet component.
//
OWCDIV.innerHTML = "<object classid='clsid:" + SS + "'
id='Spreadsheet' width='100%' height='100%'></object>";
}

function SpreadSheetClassID()
/*
* FUNCTION: SpreadSheetClassID() -> String
*
* This function is called to determine the class id string
* for the OWC Spreadsheet if it is installed. If it is not
* installed then it will return a zero length string.
*/
{
var oshell; // WScript shell object
var s; // Simple string

oshell = new ActiveXObject("WSCript.shell"); // Create a script engine
object
//
// Start by looking for OWC11.Spreadsheet
//
try
{
s = oshell.RegRead("HKCR\\OWC11.Spreadsheet\\CLSID\\");
return s.substring(1,s.length - 1); // Return the class id
}
catch (e) // Catch any error
{ }

//
// Next we can try OWC10.Spreadsheet
//
try
{
s = oshell.RegRead("HKCR\\OWC10.Spreadsheet\\CLSID\\");
// Read the key value
return s.substring(1,s.length - 1); // Return the class id
}
catch (e) // Catch any error
{ }

//
// Finally we can try OWC.Spreadsheet
//
try
{
s = oshell.RegRead("HKCR\\OWC.Spreadsheet\\CLSID\\");
// Read the key value
return s.substring(1,s.length - 1); // Return the class id
}
catch (e) // Catch any error
{
return ""; // Return an empty string
}
}

Comments ?

Martin
 
A

Alvin Bruney [MVP]

this method is not guaranteed to work depending on the security settings of
the registry. In addition, reading the registry for the specified key
doesn't really guarantee anything. In fact, about the only thing it
guarantees is that the key is there. It does not necessarily mean that the
component is on the system as it may have been left over from a botched
uninstall.

You should try instead to create a particular component. I have some sample
code to sniff the OWC on my website at http://tinyurl.com/27cok
 

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

Top