Solved

How to I read the registry to determine what version of Excel is on the PC

Posted on 2009-05-12
6
1,074 Views
Last Modified: 2013-11-23
I am unfamiliar with TRegistry and TRegIniFile
I want to determine the current version of Excel on the machine
Every effort simply returns a blank
I know it is un HKEYS_CLASSES_ROOT and under \Excel.Application\CurVer

procedure TForm1.Button1Click(Sender: TObject);

var

  Reg: TRegIniFile;

begin

  Reg := TRegIniFile.Create;
 

  Reg.RootKey := HKEY_CLASSES_ROOT;
 

//  if Reg.OpenKeyReadOnly('\Excel.Application\CurVer\') then

    ShowMessage(Reg.ReadString('Excel.Application','CurVer','Unknown'));
 

  Reg.Free

end;

Open in new window

0
Comment
Question by:bellfieldpark
  • 2
  • 2
  • 2
6 Comments
 
LVL 8

Expert Comment

by:BdLm
ID: 24362894
what is not workin on your approach ?
0
 
LVL 6

Accepted Solution

by:
bokist earned 250 total points
ID: 24362957
There are 2 possible solutions

1.  From registry :

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Excel.Application
    CurVer   >    Excel.ApplicationExcel...some_number
   
2.  With ole object :

Add ComObj  to uses

Function ExcelVersion: string;
var
   XLS: Variant;
begin
  Result := '';
  try
      Xls := CreateOleObject('Excel.Application');
      Result := Excel.Version;
  except
  end;
end;
0
 
LVL 8

Assisted Solution

by:BdLm
BdLm earned 250 total points
ID: 24363169

unit Unit_eval_excel_version;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Registry;
type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Button2: TButton;
    ListBox1: TListBox;
    procedure Button2Click(Sender: TObject);
  private
    function GetStringFromRegistry: String;
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;
var
  Form1: TForm1;
implementation
{$R *.dfm}
 

function  TForm1.GetStringFromRegistry : String;
var     Reg  :   TRegIniFile;
        results : TStringList;
begin
   //  Load from registry
   Reg := TRegIniFile.Create;
   results :=TStringList.Create;;
   try
   // Reg.RootKey := HKEY_LOCAL_MACHINE;
   // Reg.RootKey := HKEY_CURRENT_USER;
   Reg.RootKey := HKEY_CLASSES_ROOT;
   Reg.OpenKey('Excel.Application', true);
   try
     Reg.ReadSectionValues('CurVer', Results);

      ListBox1.Items := results ;
   except
       result :='';
   end;
   Reg.CloseKey;
   finally
   Reg.Free;
   end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
    edit1.text :=  GetStringFromRegistry;
end;
end.

ee-registry.bmp
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Closing Comment

by:bellfieldpark
ID: 31618522
ComObj answer was easy (although Result := XLs.Version)
Registry answer also worked, and can be used for other Registry issues
0
 

Author Comment

by:bellfieldpark
ID: 24365974
Comobj code should say Result := XLs.Version
Then it will work
0
 
LVL 6

Expert Comment

by:bokist
ID: 24367803
sorry, it was a typo...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
I'm a big fan of Windows' offline folder caching and have used it on my laptops for over a decade.  One thing I don't like about it, however, is how difficult Microsoft has made it for the cache to be moved out of the Windows folder.  Here's how to …
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now