Solved

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

Posted on 2009-05-12
6
1,087 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So who is this article for? If you are like most of the computer users out there, you probably only realize the meaning of 'System maintenance' after something goes wrong. This article is for you if you care about keeping your system working opti…
There are many reasons a PC runs slower than when it was new, ranging from malicious software intended to mess things up to simple general Windows use.  Your PC performance may slowly degrade over time without you noticing but when you buy a PC from…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

726 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