Solved

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

Posted on 2009-05-12
6
1,079 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
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.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

770 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