win32::ole and retrieval of GUID

D

Domenico Discepola

Hello. My goal is to determine if a particular version of Microsoft Excel
is installed on the local computer. Reading the Roth book's chapter on OLE
Automation led me to discover that my answer lies in GUIDs. Although I can
create COM objects using the class name (i.e. Excel.Application), how can I
retrieve the GUID of the "Excel.Application" class referred to when creating
a COM object?

TIA,

Domenico
 
M

Mark S Pryor

Domenico,
Domenico Discepola said:
Hello. My goal is to determine if a particular version of Microsoft Excel
is installed on the local computer. Reading the Roth book's chapter on OLE
Automation led me to discover that my answer lies in GUIDs. Although I can
create COM objects using the class name (i.e. Excel.Application), how can I
retrieve the GUID of the "Excel.Application" class referred to when creating
a COM object?

TIA,

Domenico

There are 2 methods:

Directly enumerating the registry keys under
hkcr\typelib for this excel library (Tie::Registry)

or

use Win32::OLE;
my $Obj = Win32::OLE->new('TLI.TypeLibInfo', \&OleQuit)
|| die("could not create Obj\n");

The methods and propterties of the TypeLibInfo (see OleView.exe)
object will get the GUID and help string for your object.

I don't have a complete Perl example for the above, but if you have
ActivePerl, there should more than enough written by Jan D.

hth,
msp
 
M

Mark S Pryor

Mark S Pryor said:
Domenico,
can

There are 2 methods:

Directly enumerating the registry keys under
hkcr\typelib for this excel library (Tie::Registry)

or

use Win32::OLE;
my $Obj = Win32::OLE->new('TLI.TypeLibInfo', \&OleQuit)
|| die("could not create Obj\n");

The methods and propterties of the TypeLibInfo (see OleView.exe)
object will get the GUID and help string for your object.

I don't have a complete Perl example for the above, but if you have
ActivePerl, there should more than enough written by Jan D.

hth,
msp

Did I find a bug in ActivePerl 5.8?
Can anyone run this code without it throwing fatal errors when
the TypeLib helpstring misses? This concept won't work unless
we can handle fatal OLE errors

#!/usr/bin/perl
#
# Author: unknown
# script: ExcelGUID.pl
# Description: loop over possible excel libnames till we find one
# keywords: typelib progid test perl
# Date: 12/30/03

use strict;
use warnings;
#use Win32;
use Win32::OLE qw(in with);
use Win32::OLE::Const ;

# I tried all variations of key Warn that let
# the script continue
Win32::OLE->Option(Warn => sub {goto CheckError});

#use Carp; # qw(cluck)
# Microsoft Excel 9.0 Object Library
my $Lib = '';
#use Data::Dumper;
#my $Consts;
my @excel;
my $vers = '';

$| = 1;
#

# i have version 9 installed
foreach $vers (7 .. 11) {

$Lib = "Microsoft Excel $vers\.0 Object Library";
print "Lib= $Lib \n";

#cluck "time to cluck" if Win32::OLE->LastError;

my $Consts = Win32::OLE::Const->LoadRegTypeLib( $Lib);

print ref( $Consts), "\n";
print "ok found it, exiting \n";
# @excel = keys %$Consts;
#print "Length=$#excel \n";
last;

CheckError:
print "normal error \n";
next
}
exit(0);

__END__
 
D

Domenico Discepola

Although I
There are 2 methods:

Directly enumerating the registry keys under
hkcr\typelib for this excel library (Tie::Registry)

or

use Win32::OLE;
my $Obj = Win32::OLE->new('TLI.TypeLibInfo', \&OleQuit)
|| die("could not create Obj\n");

The methods and propterties of the TypeLibInfo (see OleView.exe)
object will get the GUID and help string for your object.

I don't have a complete Perl example for the above, but if you have
ActivePerl, there should more than enough written by Jan D.
I figured this out... I had to get the official GUIDs from the Microsoft
website: http://www.microsoft.com/office/ork/xp/journ/prog0001.htm
####################
#!perl

use strict;
use warnings;
use diagnostics;
use Win32::OLE;

my $excel;
my $Object = 'Excel.Application';

$excel = new Win32::OLE( $Object );

print "$$excel{'ProductCode'}\n";
 

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

Members online

No members online now.

Forum statistics

Threads
474,145
Messages
2,570,824
Members
47,369
Latest member
FTMZ

Latest Threads

Top