Autor Beitrag
noNeed 4 aNick
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Mo 30.05.05 15:37 
Hi zusammen,
ich möchte mit meinem Programm Verknüpfungen öffnen.
Dabei bin ich auf ein wesentliches Problem gestoßen:

Spezielle Ordner wie der Arbeitsplatz oder der Papierkorb lassen sich nicht über die Verknüpfung öffnen.
Ich mache das ganze so:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
  TShellLinkInfo = record
    PathName: string;
    Arguments: string;
    Description: string;
    WorkingDirectory: string;
    IconLocation: string;
    IconIndex: integer;
   end;

{...}

procedure GetShellLinkInfo(const LinkFile: WideString; var SLI: TShellLinkInfo);
 var
    SL:          IShellLink;
    PF:          IPersistFile;
    FindData:    TWin32FindData;
    AStr:        Array[0..MAX_PATH] of char;
 begin
        OleCheck(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER, IShellLink, SL));
        PF := SL as IPersistFile;
        OleCheck(PF.Load(PWideChar(LinkFile), STGM_READ));
        OleCheck(SL.Resolve(0, SLR_ANY_MATCH or SLR_NO_UI));

        with SLI do
         begin
                OleCheck(SL.GetPath(AStr, MAX_PATH, FindData, SLGP_RAWPATH));
                PathName := AStr;

                OleCheck(SL.GetArguments(AStr, MAX_PATH));
                Arguments := AStr;

                OleCheck(SL.GetDescription(AStr, MAX_PATH));
                Description := AStr;

                OleCheck(SL.GetWorkingDirectory(AStr, MAX_PATH));
                WorkingDirectory := AStr;

                OleCheck(SL.GetIconLocation(AStr, MAX_PATH, IconIndex));
                IconLocation := AStr;
         end;
 end;

procedure TMenuIcon.RunLink;
 var SLI: TShellLinkInfo;
 begin
        if ExtractFileExt(FileName) = '.lnk' then
         begin
                GetShellLinkInfo(Filename, SLI);
                if ExtractFileExt(SLI.PathName) = '' then
                 ShellExecute(Application.Handle, 'open''explorer.exe', PChar(SLI.PathName), nil, SW_NORMAL)
                else
                 ShellExecute(Application.Handle, 'open', PChar(FileName), nil, PChar(ExtractFilePath(FileName)), SW_NORMAL);
         end
        else
         ShellExecute(Application.Handle, 'open', PChar(FileName), nil, PChar(ExtractFilePath(FileName)), SW_NORMAL);

 end;


Wenn nun aber so ein Papierkorb kommt, dann is das SLI-Record absolut leer. Ich hab zwar nen Code gefunden um den Papierkorb zu öffnen, aber insgesamt is es doch totaler Mist, wenn ich sage
ausblenden Delphi-Quelltext
1:
2:
3:
//...
if ExtractFileName(Filename) = 'Papierkorb.lnk' then {Öffne Papierkorb}
//...

Wenn nun jmd das Programm benutzten würde und den Papierkorb Trash oder Mülleimer oder [beliebigerNameEinerEx] nennt, könnte das Programm nicht entsprechend reagieren.

Hat jmd ne Idee?

ThxInAdv
Alex

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 30.05.05 16:15 
2 Jahre alt, aber scheinbar immer noch für Überraschungen gut: klick.
noNeed 4 aNick Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Mo 30.05.05 19:19 
Hi
den Code hab ich selber auch gefunden.
Mir geht's nicht darum wie ich den Papierkorb öffne.

Ich habe ein Programm, dass Shortcuts aus einem Ordner lädt und auf die ich dann klicken kann und dann der Shortcut ausgeführt wird.

Nur sind die Shortcuts der Systemordner irgendwie anders aufgebaut. Sie enthalten nämlich keinerlei Pfadangaben oder ähnliche Identifikationsmöglichkeiten. Daher kann ich bisher nur über den Dateinamen feststellen, ob die Verknüpfung nun auf den Papierkorb oder auf den Arbeitsplatz verweist.

Ich suche also nicht nach einer Möglichkeit, diese Ordner zu öffnen, sondern nach einer Möglichkeit welcher Ordner im Shortcut gespeichert ist...
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 30.05.05 19:28 
Auch dafür gibt´s was in den FAQs. Aber a) hast du das sicher auch schon selbst gefunden, und b) wird nicht jeder spezielle Ordner ein Ergebnis zurückliefern. Der Arbeitsplatz dürfte dazu zählen, so wie die Systemsteuerung, weil es keine derartigen Ordner auf der Festplatte gibt.
noNeed 4 aNick Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20



BeitragVerfasst: Mo 30.05.05 20:16 
Hi, das sieht ja nett aus...
Ich hab das Ganze mal mit dem SL.getIDList kombiniert, aber trotzdem bekomm ich nichts raus...
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
procedure GetShellLinkInfo(const LinkFile: WideString;
 var SLI: TShellLinkInfo);
{ Retrieves information on an existing shell link }
 var
    SL:          IShellLink;
    PF:          IPersistFile;
    FindData:    TWin32FindData;
    AStr:        Array[0..MAX_PATH] of char;
    pIdL:        PItemIDList;
 begin
        OleCheck(CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER, IShellLink, SL));
        PF := SL as IPersistFile;
        OleCheck(PF.Load(PWideChar(LinkFile), STGM_READ));
        OleCheck(SL.Resolve(0, SLR_ANY_MATCH or SLR_NO_UI));

        with SLI do
         begin
                OleCheck(SL.GetPath(AStr, MAX_PATH, FindData, SLGP_RAWPATH));
                PathName := AStr;
                OleCheck(SL.GetArguments(AStr, MAX_PATH));
                Arguments := AStr;
                OleCheck(SL.GetDescription(AStr, MAX_PATH));
                Description := AStr;
                OleCheck(SL.GetWorkingDirectory(AStr, MAX_PATH));
                WorkingDirectory := AStr;
                OleCheck(SL.GetIconLocation(AStr, MAX_PATH, IconIndex));
                IconLocation := AStr;
                if PathName = '' then
                 begin
                   OleCheck(SL.GetIDList(pIDL));
                   SHGetPathFromIDList (pIDL, AStr);
                   PathName := AStr;
                 end;
         end;
 end;

procedure TForm1.Button1Click(Sender: TObject);
var SLI: TShellLinkInfo;
    f:   string;
begin
        f := 'E:\Borland\Delphi6\Projects\MyDesk\Desktop\Papierkorb.lnk';

        if not FileExists(f) then showMessage('N/A')
        else
         begin
                GetShellLinkInfo(f,SLI);
                showMessage('Pathname: ' + SLI.PathName + #13#10+
                            'Arguments: ' + SLI.Arguments + #13#10+
                            'Description: ' + SLI.Description + #13#10+
                            'WorkingDirectory: ' + SLI.WorkingDirectory);
         end;
end;


Kommt immernoch nix raus :(