Autor Beitrag
kad_we
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 78


D6; Turbo Delphi 2006
BeitragVerfasst: Do 04.12.03 09:45 
was gibt shellexecute für einen wert zurück und wie kann ich prüfen,ob der Befehl wirklich ausgeführt wurde?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
if not isadmin then 
  ShellExecute (
      Application.Handle, 'open' ,PChar('z:\'), nil, PChar(''), sw_ShowNormal
    )
else
  showmessage ('Admins haben kein Home Laufwerk');
das funzt nur bei admins (z: ist unser home laufwerk...:-)
und die haben keins...
mach andere Accounts an unserer schule haben nämlich auch kein Homelaufwerk...und das soll überprüftwerden!
das beste wär, wenn es einfach boolean zurückgibt...


thx 4 help kad_we

Moderiert von user profile iconTino: Titel geändert.
MathiasSimmack
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 04.12.03 09:57 
Du solltest besser das Vorhandensein des Laufwerks prüfen. Schlicht und einfach mit
ausblenden Delphi-Quelltext
1:
2:
if not SetCurrentDir('Z:\'then
  ShowMessage('Kein Verzeichnis Z gefunden');

Wenn SetCurrentDir funktioniert, dann wird sicher auch ShellExecute klappen. Ansonsten hilft dir zu den Rückgabewerten das PSDK oder online das MSDN weiter.
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Do 04.12.03 10:09 
Soweit ich weiss gibt ShellExecute keinen Wert zurück...

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 04.12.03 11:17 
Doch gibt es.
PSDK hat folgendes geschrieben:

Return Value

Returns a value greater than 32 if successful, or an error value that is less than or equal to 32 otherwise. The following table lists the error values. The return value is cast as an HINSTANCE for backward compatibility with 16-bit Windows applications. It is not a true HINSTANCE, however. The only thing that can be done with the returned HINSTANCE is to cast it to an int and compare it with the value 32 or one of the error codes below.

0 The operating system is out of memory or resources.
ERROR_FILE_NOT_FOUND The specified file was not found.
ERROR_PATH_NOT_FOUND The specified path was not found.
ERROR_BAD_FORMAT The .exe file is invalid (non-Microsoft Win32® .exe or error in .exe image).
SE_ERR_ACCESSDENIED The operating system denied access to the specified file.
SE_ERR_ASSOCINCOMPLETE The file name association is incomplete or invalid.
SE_ERR_DDEBUSY The Dynamic Data Exchange (DDE) transaction could not be completed because other DDE transactions were being processed.
SE_ERR_DDEFAIL The DDE transaction failed.
SE_ERR_DDETIMEOUT The DDE transaction could not be completed because the request timed out.
SE_ERR_DLLNOTFOUND The specified dynamic-link library (DLL) was not found.
SE_ERR_FNF The specified file was not found.
SE_ERR_NOASSOC There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.
SE_ERR_OOM There was not enough memory to complete the operation.
SE_ERR_PNF The specified path was not found.
SE_ERR_SHARE A sharing violation occurred.
Chatfix
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1583
Erhaltene Danke: 10

Win 10, Win 8, Win 7, Win Vista, Win XP
VB.net (VS 2015), MsSQL (T-SQL), HTML, CSS, PHP, MySQL
BeitragVerfasst: Do 04.12.03 13:50 
Das ist ja praktisch, ich staune immer wieder was man hier noch lernen kann :D

gg thx, und sorry für meine fehlinformation

_________________
Gehirn: ein Organ, mit dem wir denken, daß wir denken. - Ambrose Bierce
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Do 04.12.03 13:59 
Easy Delphi Helper 2000 hat folgendes geschrieben:
Fehlercodes von ShellExecute


Die Funktion ShellExecute gibt bestimmte ErrorCodes zurück, wenn beim Starten der Anwendung Fehler auftreten. Diese Liste gibt eine Übersicht der möglichen Fehlerquellen und gibt verständliche Fehlermeldungen zurück. Als Parameter muss der ErrorCode übergeben werden
ausblenden 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:
Function ShellExecuteErrMessage(int_Code: INTEGER): STRING;
 //Gibt die passenede Fehlermeldung zum ShellExecute Fehlercode zurück
Begin
  CASE int_code OF
     0: result := 'Zuwenig Speicher, ausführbare Datei war zerstört, Relokationswerte waren ungültig';
     2: result := 'Datei wurde nicht gefunden.';
     3: result := 'Verzeichnis wurde nicht gefunden.';
     5: result := 'Fehler beim gemeinsamen Zugriff auf eine Datei im Netz oder Fehler beim Zugriff auf eine gesperrte Datei im Netz.';
     6: result := 'Bibliothek forderte separate Datensegmente für jede Task an.';
     8: result := 'Zuwenig Speicher, um die Anwendung zu starten.';
    10: result := 'Falsche Windows-Version.';
    11: result := 'Ungültige ausführbare Datei. Entweder keine Windows-Anwendung oder Fehler in der EXE-Datei.';
    12: result := 'Anwendung für ein anderes Betriebssystem.';
    13: result := 'Anwendung für MS-DOS 4.0.';
    14: result := 'Typ der ausführbaren Datei unbekannt.';
    15: result := 'Versuch, eine Real-Mode-Anwendung (für eine frühere Windows-Version) zu laden.';
    16: result := 'Versuch, eine zweite Instanz einer ausführbaren Datei mit mehreren Datensegmenten die nicht als nur lesbar gekennzeichnet waren, zu laden.';
    19: result := 'Versuch, eine komprimierte ausführbare Datei zu laden.' + #13 + 'Die Datei muß dekomprimiert werden, bevor sie geladen werden kann.';
    20: result := 'Ungültige dynamische Linkbibliothek (DLL).' + #13 + 'Eine der DLLs, die benötigt wurde, um die Anwendung auszuführen, war beschädigt.';
  ELSE
    result := 'Ein Unbekannter Fehler ist aufgetreten. (' + IntToStr(int_code) + ')';
  END;
End;


So könnte man die Funktion aufrufen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
uses ShellApi;

procedure TForm1.FormCreate(Sender: TObject);
var
  Err: Integer;
begin
  Err:=  ShellExecute(0
               Nil,
               PChar('C:\Programm.exe'), 
               Pchar('-Parameter'), 
               Pchar('C:\StartDir'),
               SW_NORMAL);
  if Err<>0 then
    Showmessage(ShellExecuteErrMessage(Err));
end;

_________________
In the beginning was the word.
And the word was content-type: text/plain.