Delphi-PRAXiS
Seite 1 von 3  1 23      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Programm Ordner finden (https://www.delphipraxis.net/111602-programm-ordner-finden.html)

SaFu 6. Apr 2008 13:06


Programm Ordner finden
 
Hi

Und zwar habe ich ein kleines Problem. Ich las den Benutzer über eine Groupbox sein schreib Programm wählen.

Der Pfad zum Programm ordner ändert sich ja aber immer (XP, Vista) wie kann ich jetzt den Programmpfad herausfinden immoment mache ich das so mit der abfrage des betriebsystem jetzt habe ich den Tipp bekommen das, das nicht schön gelöst ist.

Delphi-Quellcode:
sWindowsVersionName:= JvComputerInfoEx1.OS.ProductName;

Label3.Caption:= 'Verwendetes Betriebssytem: ' + Form1.sWindowsVersionName; // Windows Version anzeigen

 if Form1.sWindowsVersionName = 'Microsoft Windows 2000' then
  begin
    sWinPfad:= 'C:\Programme';
  end;

 if Form1.sWindowsVersionName = 'Microsoft Windows XP' then
  begin
    sWinPfad:= 'C:\Programme';
  end;

 if Form1.sWindowsVersionName = 'Microsoft Windows Vista' then
  begin
    sWinPfad:= 'C:\Program Files';
  end;
end;


//================Auswahl Programm==============================================
procedure TSoftwareeinstellungen.GrBoxProgrammauswahlClick(Sender: TObject);
begin
 if GrBoxProgrammauswahl.ItemIndex = 0 then
  begin
   sProgrammPfad:= (sWinpfad +'\Windows NT\Accessories\wordpad.exe');
   if not FileExists(sProgrammPfad) then
    Begin
     sProgrammPfad:= ('c:\Programme\Windows NT\Zubehör\Wordpad.exe');
    End;
   sProgramLabel:= ('Wordpad');
  end;

   if GrBoxProgrammauswahl.ItemIndex = 1 then
    begin
     if not FileExists (sWinpfad + '\OpenOffice.org 2.4\program\swriter.exe') then
      begin
       if Form1.MessageDlgPos2('OpenOffice 2.4 ist nicht Installiert.' + #10 +'Wollen Sie OpenOffice installieren?'
       + #10 + #10 + 'Nehmen Sie nach der Installation die Einstellungen nochmals vor',mtInformation,[mbYes,mbNo],self) = mrYes then
        begin
         if ShellExecute(Application.Handle,'open',PChar(sWinpfad +  '\xxxxx\Support\OOo_2.4.0rc2_20080227_Win32Intel_install_de.exe'),Nil, Nil, SW_NORMAL) <= 32 then
        end
       else
        begin
         sProgrammPfad:= (sWinpfad + '\Windows NT\Accessories\wordpad.exe');
         if not FileExists(sProgrammPfad) then
          Begin
           sProgrammPfad:= ('c:\Programme\Windows NT\Zubehör\Wordpad.exe');
          End;
         Form1.MessageDlgPos2('Standard Programm Wordpad wird ausgeführt!',mtInformation,[mbOk],self);
         sProgramLabel:= ('Wordpad');
        end;
      end

     else
      begin
       if fileExists (sWinpfad + '\OpenOffice.org 2.4\program\swriter.exe')then
        begin
         sProgrammPfad:=(sWinpfad + '\OpenOffice.org 2.4\program\swriter.exe');
         sProgramLabel:= ('OpenOffice');
        end
      end;
    end;

     if GrBoxProgrammauswahl.ItemIndex = 2 then
      begin
       if not FileExists (sWinpfad + '\Microsoft Office\Office10\WINWORD.EXE')then
        begin
          if Form1.MessageDlgPos2('Word 2003 ist nicht Installiert.',mtInformation,[mbOK],self) = mrOK then
           begin
            sProgrammPfad:= (sWinpfad + '\Windows NT\Accessories\wordpad.exe');
             if not FileExists(sProgrammPfad) then
              Begin
               sProgrammPfad:= ('c:\Programme\Windows NT\Zubehör\Wordpad.exe');
              End;
            sProgramLabel:= ('Wordpad');
            Form1.MessageDlgPos2('Standard Programm Wordpad wird ausgeführt!',mtInformation,[mbOk],self);
           end;
        end
       else
        begin
         sProgrammPfad:=(sWinpfad + '\Microsoft Office\Office10\WINWORD.EXE');
         sProgramLabel:= ('Word 2003');
        end;
       end;


    if GrBoxProgrammauswahl.ItemIndex = 3 then
     begin
      if not FileExists (sWinpfad + '\Microsoft Office\Office12\WINWORD.EXE')then
       begin
         if Form1.MessageDlgPos2('Word 2007 ist nicht Installiert.',mtInformation,[mbOK],self) = mrOk then
          begin
           sProgramLabel:= ('Wordpad');
           sProgrammPfad:= (sWinpfad + '\Windows NT\Accessories\wordpad.exe');
            if not FileExists(sProgrammPfad) then
             Begin
              sProgrammPfad:= ('c:\Programme\Windows NT\Zubehör\Wordpad.exe');
             End;
           Form1.MessageDlgPos2('Standard Programm Wordpad wird ausgeführt!',mtInformation,[mbOk],self);
          end;
       end
      else
       begin
        sProgrammPfad:=(sWinpfad + '\Microsoft Office\Office12\WINWORD.EXE');
        sProgramLabel:= ('Word 2007');
       end;
     end;
   Label4.Caption:= 'Ihr gewähltes Programm: ' + sProgramLabel;
Oder hat jemand eine schönere Lösung

Gruß Sascha

[edit=MrSpock]Änderung am Programmpfad wie vom Ersteller gewünscht durchgeführt. Mfg, MrSpock[/edit]

Der.Kaktus 6. Apr 2008 13:14

Re: Programm Ordner finden
 
hallo,

zum ProgrammfilesPath gehts hierlang--->
Delphi-Quellcode:
JvComputerInfoEx1.Folders.ProgramFiles

SirThornberry 6. Apr 2008 13:19

Re: Programm Ordner finden
 
ohne zusätzliche Komponenten geht es über SHGetSpecialFolderPath

hathor 6. Apr 2008 13:28

Re: Programm Ordner finden
 
Das Thema wurde hier schon x-mal behandelt, aber da muss man natürlich den Suchbegriff GETSPECIALFOLDER kennen.

Delphi-Quellcode:
uses
  { ... },
  ActiveX, // IMalloc
  ShellAPI, // SHGetSpecialFolderLocation() und SHGetPathFromIDList()
  ShlObj;  // CSIDL_-Konstanten

.
.
.

function GetSpecialFolder(hWindow: HWND; Folder: Integer): String;
var
pMalloc: IMalloc;
pidl: PItemIDList;
Path: PChar;
begin
// get IMalloc interface pointer
if (SHGetMalloc(pMalloc) <> S_OK) then
begin
MessageBox(hWindow, 'Couldn''t get pointer to IMalloc interface.','SHGetMalloc(pMalloc)', 16);
Exit;
end;
// retrieve path
SHGetSpecialFolderLocation(hWindow, Folder, pidl);
GetMem(Path, MAX_PATH);
SHGetPathFromIDList(pidl, Path);
Result := Path;
FreeMem(Path);

// free memory allocated by SHGetSpecialFolderLocation
pMalloc.Free(pidl);
end;

//Mit folgendem Aufruf werden alle Specialfolder angezeigt, die auf DIESEM PC zur Verfügung stehen:
for i := 0 to 64 do Memo1.Lines.add(IntToStr(i)+' : '+ GetSpecialFolder(Form1.Handle,i));

SirThornberry 6. Apr 2008 13:31

Re: Programm Ordner finden
 
@hathor: Warum SHGetSpecialFolderLocation anstelle von SHGetSpecialFolderPath? Mit SHGetSpecialFolderPath ginge das ganze bedeutend einfacher.

Der.Kaktus 6. Apr 2008 13:38

Re: Programm Ordner finden
 
@SirThornberry & @hathor
Sascha schrieb doch im Quelltext...er wuerde JVCL Komponenten nutzen..dann eruebrigt sich das doch ..trinkt nen :cheers: *gggg*
@Sascha fuer die Suche nach installierten Programmen empfehle ich auch deshalb ..schau Dir mal die Komponente JvUninstallControls an. Da findest Du einiges.(im Quelltext gesehen..deshalb der Tip)

hathor 6. Apr 2008 13:43

Re: Programm Ordner finden
 
Zitat:

Zitat von SirThornberry
@hathor: Warum SHGetSpecialFolderLocation anstelle von SHGetSpecialFolderPath? Mit SHGetSpecialFolderPath ginge das ganze bedeutend einfacher.

The reason for using SHGetSpecialFolderLocation instead of SHGetSpecialFolderPath is that the second is only available from the version 4.71 (Internet Explorer 4) of the Shell32.dll while the first is present on all systems starting with NT 4 and Win 95.

SaFu 6. Apr 2008 14:04

Re: Programm Ordner finden
 
Zitat:

Zitat von Der.Kaktus
@SirThornberry & @hathor
Sascha schrieb doch im Quelltext...er wuerde JVCL Komponenten nutzen..dann eruebrigt sich das doch ..trinkt nen :cheers: *gggg*
@Sascha fuer die Suche nach installierten Programmen empfehle ich auch deshalb ..schau Dir mal die Komponente JvUninstallControls an. Da findest Du einiges.(im Quelltext gesehen..deshalb der Tip)

Ja mit Komponenten ist es halt einfacher ich Pruche Sie nicht unbending
die JvUninstallControls gibt es bei mir nicht aber der programmpfad mit der anderen Komponente Hilft schon viel weiter Danke

hathor 6. Apr 2008 14:17

Re: Programm Ordner finden
 
So - ich habe nun den Code "modernisiert" für "neuere" WINDOWS-Versionen.
Damit kann man alle SPECIALFOLDER bekommen: (wozu JVCL ???)

Delphi-Quellcode:
uses ...,ShlObj,...

procedure TForm1.FormShow(Sender: TObject);
var i:integer;
    Str : array[0..256] of char;
begin
Memo1.clear;
for i := 0 to 64 do
Begin
SHGetSpecialFolderPath(Application.Handle, @Str[0], i, false);
Memo1.Lines.add(IntToStr(i)+' : '+ Str);
END;
end;

SaFu 6. Apr 2008 14:29

Re: Programm Ordner finden
 
Danke für die mühe

Aber ich brauche wirklich nur den Programmordner
Das ist so kürzer

Delphi-Quellcode:
 if GrBoxProgrammauswahl.ItemIndex = 0 then
  begin
   sProgrammPfad:= LowerCase(JvComputerInfoEx2.Folders.ProgramFiles +'\Windows NT\Accessories\wordpad.exe');
   if not FileExists(sProgrammPfad) then
    Begin
     sProgrammPfad:= LowerCase(JvComputerInfoEx2.Folders.ProgramFiles + '\Windows NT\Zubehör\Wordpad.exe');
    End;
   sProgramLabel:= ('Wordpad');
  end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 01:46 Uhr.
Seite 1 von 3  1 23      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz