Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find Microsoft office PATH? 1

Status
Not open for further replies.

eladna

Programmer
Dec 11, 2002
17
IL
Hi
Does anyone know how can I find if Microsoft office installed in the computer and if yes where can I find it's PATH?

I need it so I could execute the Excel.exe for example.

Any help would be appreciated

 
Thank you for the fast reply but this function does not search the subfolders
I still need to know where to look for it and for every version of office it's been installed in different directory.
 
Does this code exist in Delphi as well?
 
I can give you the code to do this later (once I get a chance to look through my code stash for it - not a matter of willingness, but a matter of time), but I thought of something you might want to consider, especially in the implementation of such a function:

1. A lot depends on what you're wanting to do and the function of your program. What I'm getting at here, is if it actually *has* to be Microsoft Office? Can it be one of the viewers Microsoft put out? Can it be OpenOffice?

2. With such a function, how are you going to deal with it if you were to find two copies of Excel.exe, which isn't entirely out of the question if someone is running multiple copies of office for some reason.

You might want to think things out a bit, depending on the function of your program. If "any" Excel file viewer works, you might want to consider looking for file association information in the registry, and if not that, force the user to indicate what you want to be run?

Something to think about, at least.
 
While Glenn's comments should be addressed, I KNOW that any machine that runs any of my applications will have Word installed (because that's part of our organization's standard setup). If all you need to do is run a program that you KNOW will be on the PC, then this works:
Code:
var
WordApp : variant;
begin
  try
    WordApp:= CreateOleObject('Word.Application');
    WordApp.Visible := True; //set to false to run with no user 
    WordApp.ActiveDocument.PrintOut;
    WordApp.ActiveDocument.Close(0); //0 - no save
  finally
    WordApp.Quit;
  end;

end;


Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for database developers:
The Fundamentals of Relational Database Design
Understanding SQL Joins
 
This should give you a start. Of course the questions asked above need answered:

Code:
$APPTYPE CONSOLE}
program part13; uses sysutils;
 { Delphi 3.0 version }
  var
    drive: string;
    fileinput: string;

  procedure listdirsizes(filedir: string);
    var
      f, s: string;
      dirinfo: TSearchRec;
      retcode: longint;
    begin
      f := filedir + '\*.*';
      FindFirst(f, faAnyFile-faVolumeID-faDirectory, dirinfo);
      repeat
        writeln(dirinfo.name);
        if dirinfo.name = fileinput then
           writeln('Found: ', filedir + '\' + dirinfo.name);
      until (FindNext(dirinfo) <> 0);
      FindClose(dirinfo);
      FindFirst(f, faDirectory, dirinfo);
      repeat
        if (dirinfo.attr = faDirectory) and (dirinfo.name <> '.')
           and (dirinfo.name <> '..') then
           begin
             s := filedir + '\' + dirinfo.name;
             listdirsizes(s);
           end;
      until (FindNext(dirinfo) <> 0);
      FindClose(dirinfo);
    end;

  procedure writehelp;
    begin
      writeln('Include a drive and a file name');
      writeln('FSEARCH C: README.TXT');
      halt(1);
    end;

  function upstr(instr: string): string;
    var
      tempstr: string;
      i: integer;
    begin
      tempstr := '';
      for i := 1 to length(instr) do
        tempstr := tempstr + upcase(instr[i]);
      upstr := tempstr;
    end;

  begin
    writeln('FSEARCH copyright 2005 by Glenn9999 in tek-tips.com.');
    writeln('Use of any of this code must include the copyright ',
            'statement listed above.');
    writeln;

    if paramcount <> 2 then
      writehelp;
    drive := paramstr(1);
    if (length(drive) <> 2) or (drive[2] <> ':') then
      writehelp;
    drive[1] := upcase(drive[1]);
    fileinput := upstr(paramstr(2));
    if (length(fileinput) > 12) or (fileinput = ' ') then
      writehelp;
    listdirsizes(drive);
  end.
 
I've always used this:
Code:
[navy][i]// for automatic syntax highlighting see faq102-6487 
[/i][/navy][b]uses[/b]
  Registry;
[b]var[/b]
  FOfficeDir: String;
[b]begin[/b]
  [b]with[/b] TRegistry.Create [b]do[/b]
    [b]try[/b]
      RootKey := HKEY_LOCAL_MACHINE;
      [b]if[/b] OpenKey([teal]'\Software\Microsoft\Windows\CurrentVersion\App Paths\EXCEL.EXE'[/teal], False) [b]then[/b]
      [b]begin[/b]
        FOfficeDir := IncludeTrailingPathDelimiter(ReadString([teal]'Path'[/teal]));
        CloseKey;
      [b]end[/b];
    [b]finally[/b]
      Free;
    [b]end[/b];
[b]end[/b];

Just change [tt]EXCEL.EXE[/tt] for whichever office application you're checking for.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top