| Autor |
Beitrag |
Samolex
      
Beiträge: 22
Win xp
Delphi 5
|
Verfasst: Do 20.07.06 14:58
Hi,
wie Starte ich im Programm(a) ein anderes Programm(b) (*.Exe) ?
Programm(a) soll dann sofort beendet werden.
Gruß Samolex
|
|
Marco D.
      
Beiträge: 2750
Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
|
Verfasst: Do 20.07.06 15:00
Such mal nach ShellExecute und KillTask.
_________________ Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
|
|
JayEff
      
Beiträge: 2971
Windows Vista Ultimate
D7 Enterprise
|
Verfasst: Do 20.07.06 15:00
Oh man
PROGRAMM STARTEN
Und KillTask brauchst du nicht. einfach nach ShellExecute Form1.Close ausführen. ^^
_________________ >+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
|
|
jasocul
      
Beiträge: 6395
Erhaltene Danke: 149
Windows 7 + Windows 10
Sydney Prof + CE
|
Verfasst: Do 20.07.06 15:01
Fast richtig.
ShellExecute ist OK. Das Programm a kann sich aber einfach mit Close beenden.
Nimm doch nicht immer gleich den Dampfhammer. 
|
|
Samolex 
      
Beiträge: 22
Win xp
Delphi 5
|
Verfasst: Do 20.07.06 15:12
Hi,
kann mir jemand mal ein Bespiel zu ShellExecute geben ?
Meine Delphihilfe findet den Befehl nicht und mein Compiler meint dan Befehl nicht zu kennen.
Also ich will das Programm(a) aus Turbo Pascal aus starten un dem ein Parameter mitgeben, der besagt welches Programm, Programm(a) sterten soll.
also mit Paramcount und Paramstr kenn ich mich in etwa aus.
Was nehme ich für eine Anwendung dafür ? Eine Konsolen-Anwendung ?
MfG Samolex
Zuletzt bearbeitet von Samolex am Do 20.07.06 15:14, insgesamt 1-mal bearbeitet
|
|
Horschdware
      
Beiträge: 744
Erhaltene Danke: 54
Win XP Pro, Win 7 Pro x64
Delphi 7, Delphi XE, C++ Builder 5, SAP R/3
|
Verfasst: Do 20.07.06 15:13
_________________ Delphi: XE - OS: Windows 7 Professional x64
|
|
jasocul
      
Beiträge: 6395
Erhaltene Danke: 149
Windows 7 + Windows 10
Sydney Prof + CE
|
Verfasst: Do 20.07.06 15:20
Ich kopiere mal ein paar Häppchen aus einem meiner Programme:
Hier ist die ShellAPI wichtig:
Delphi-Quelltext 1: 2: 3: 4: 5:
| interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, JvComponent, JvLabel, JvExControls, ExtCtrls, ShellAPI; |
Hier mache ich dann eine Aufruf, der deinem ähnelt:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
| procedure TfrmStart.FormActivate(Sender: TObject); var Fehler : Integer; Parameter : String; SR : TSearchRec; begin if ParamCount > 0 then begin Parameter := ParamStr(1); end else begin Parameter := 'Offz'; end; Fehler := FindFirst(Parameter, faAnyFile, SR); if Fehler = 0 then begin Fehler := ShellExecute(Application.Handle, 'open', PChar(Parameter), Nil, Nil, SW_SHOW); Close; end; |
ACHTUNG. Das sind nur Programm-Ausschnitte.
|
|
Samolex 
      
Beiträge: 22
Win xp
Delphi 5
|
Verfasst: Do 20.07.06 15:23
ähm ja gut ich weis jetzt, dass ich die Uses ShellApi brauche aber mir sagen die Parameter rein garnichts. Was macht welcher Parameter? wozu dient er? usw.
Was muss ich eingeben wenn ich z.B die Test.exe starten möchte ?
ShellExecute ('C:\Test.exe'); ?
MfG Samolex
|
|
jasocul
      
Beiträge: 6395
Erhaltene Danke: 149
Windows 7 + Windows 10
Sydney Prof + CE
|
Verfasst: Do 20.07.06 15:28
Ich weiß ja nicht, was mit deiner Delphi-Hilfe los ist, aber hier mal ein Ausschnitt:
| Zitat: | ShellExecute Function
--------------------------------------------------------------------------------
Performs an operation on a specified file.
Syntax
HINSTANCE ShellExecute(HWND hwnd,
LPCTSTR lpOperation,
LPCTSTR lpFile,
LPCTSTR lpParameters,
LPCTSTR lpDirectory,
INT nShowCmd
);
Parameters
hwnd
[in] Handle to a parent window. This window receives any message boxes that an application produces, such as error reporting.
lpOperation
[in] Pointer to a null-terminated string, referred to in this case as a verb, that specifies the action to be performed. The set of available verbs depends on the particular file or folder. Generally, the actions available from an object's shortcut menu are available verbs. For more information about verbs and their availability, see Object Verbs. See Extending Shortcut Menus for further discussion of shortcut menus. The following verbs are commonly used.
edit
Launches an editor and opens the document for editing. If lpFile is not a document file, the function will fail.
explore
Explores the folder specified by lpFile.
find
Initiates a search starting from the specified directory.
open
Opens the file specified by the lpFile parameter. The file can be an executable file, a document file, or a folder.
print
Prints the document file specified by lpFile. If lpFile is not a document file, the function will fail.
NULL
For systems prior to Microsoft® Windows® 2000, the default verb is used if it is valid and available in the registry. If not, the "open" verb is used.
For Windows 2000 and later systems, the default verb is used if available. If not, the "open" verb is used. If neither verb is available, the system uses the first verb listed in the registry.
lpFile
[in] Pointer to a null-terminated string that specifies the file or object on which to execute the specified verb. To specify a Shell namespace object, pass the fully qualified parse name. Note that not all verbs are supported on all objects. For example, not all document types support the "print" verb.
lpParameters
[in] If the lpFile parameter specifies an executable file, lpParameters is a pointer to a null-terminated string that specifies the parameters to be passed to the application. The format of this string is determined by the verb that is to be invoked. If lpFile specifies a document file, lpParameters should be NULL.
lpDirectory
[in] Pointer to a null-terminated string that specifies the default directory.
nShowCmd
[in] Flags that specify how an application is to be displayed when it is opened. If lpFile specifies a document file, the flag is simply passed to the associated application. It is up to the application to decide how to handle it.
SW_HIDE
Hides the window and activates another window.
SW_MAXIMIZE
Maximizes the specified window.
SW_MINIMIZE
Minimizes the specified window and activates the next top-level window in the z-order.
SW_RESTORE
Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW
Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT
Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. An application should call ShowWindow with this flag to set the initial show state of its main window.
SW_SHOWMAXIMIZED
Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED
Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE
Displays the window as a minimized window. The active window remains active.
SW_SHOWNA
Displays the window in its current state. The active window remains active.
SW_SHOWNOACTIVATE
Displays a window in its most recent size and position. The active window remains active.
SW_SHOWNORMAL
Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
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. |
Ich hoffe, du bist des englischen mächtig.
|
|
Gausi
      
Beiträge: 8554
Erhaltene Danke: 481
Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
|
Verfasst: Do 20.07.06 15:31
Wegen der Hitze, und weil ich mich damit auch schon öfter rumgeplagt habe: So öffnet man Paint:
Delphi-Quelltext 1:
| shellexecute(Handle, 'open', 'mspaint.exe', Nil, NIl, SW_Show) |
@jasocul: Die Info finde ich in meiner Delphi-Hilfe auch nicht...aber hier
_________________ We are, we were and will not be.
|
|
jasocul
      
Beiträge: 6395
Erhaltene Danke: 149
Windows 7 + Windows 10
Sydney Prof + CE
|
Verfasst: Do 20.07.06 15:38
Es kommt nicht als Kontext-Hilfe. Aber wenn ich bei "Suchen nach" ShellExecute eingebe, wird es angezeigt.
|
|
Samolex 
      
Beiträge: 22
Win xp
Delphi 5
|
Verfasst: Do 20.07.06 15:47
Danke für di Hilfe...
Ich habe jetz in eine Konsolen-Anwendung folgenden Quelltext geschrieben.
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9:
| program Project2; {$APPTYPE CONSOLE} uses sysutils,ShellApi;
begin ShellExecute (Handle,'open','F:\tests\Server.exe',Nil,Nil,SW_SHOW); Close; end. |
Und er bringt mir folgende Fehlermeldung :
undefinierter Bezeichner 'Handle'
undefinierter Bezeichenr 'SW_SHOW'
( erwartet aber ; gefunden (bei Close)
Wo muss Handle definiert sein von wo kommt es ? Hab ich noch eine Uses vergiessen, wo sw_show definiert ist ?
Moderiert von Gausi: Delphi-Tags hinzugefügt
|
|
Born-to-Frag
      
Beiträge: 1094
Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
|
Verfasst: Do 20.07.06 15:58
uses: + Windows, + Forms
Handle -> Application.Handle
_________________ Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
|
|
Samolex 
      
Beiträge: 22
Win xp
Delphi 5
|
Verfasst: Do 20.07.06 16:09
Ah es tur sich was ^^
Danke jetzt funzt es. Ich hoffe ich habe euch nicht zur verzweiflung gebracht.
Danke an allen die mir geholfen haben.
MfG Samolex
|
|
F34r0fTh3D4rk
      
Beiträge: 5285
Erhaltene Danke: 29
Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
|
Verfasst: Do 20.07.06 17:07
wobei du das close garnet brauchst bei non-vcl, und somit auch die unit forms net, was dein projekt um ~300kb kleiner macht, kA ob du sysutils brauchst, kannst du eventuell auch weglassen
|
|
Samolex 
      
Beiträge: 22
Win xp
Delphi 5
|
Verfasst: Do 20.07.06 18:12
Also die Units
ShellApi, Windows, Forms;
Brauch ich sonst meckert mein Compiler das er einige Definitionen nicht kennt.
|
|
Heiko
      
Beiträge: 3169
Erhaltene Danke: 11
|
Verfasst: Do 20.07.06 18:51
jasocul hat folgendes geschrieben: | Ich kopiere mal ein paar Häppchen aus einem meiner Programme:
Hier ist die ShellAPI wichtig:
Delphi-Quelltext 1: 2: 3: 4: 5:
| interface
uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, JvComponent, JvLabel, JvExControls, ExtCtrls, ShellAPI; |
Hier mache ich dann eine Aufruf, der deinem ähnelt:
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19:
| procedure TfrmStart.FormActivate(Sender: TObject); var Fehler : Integer; Parameter : String; SR : TSearchRec; begin if ParamCount > 0 then begin Parameter := ParamStr(1); end else begin Parameter := 'Offz'; end; Fehler := FindFirst(Parameter, faAnyFile, SR); if Fehler = 0 then begin Fehler := ShellExecute(Application.Handle, 'open', PChar(Parameter), Nil, Nil, SW_SHOW); Close; end; |
ACHTUNG. Das sind nur Programm-Ausschnitte. |
Nun ja jasocul, wolltest du den Source wirklich einem Anfänger so geben? Denn der Source ist dermaßen unelegant/komisch (wie man auf den Lösungsweg kommt *g*), das ich schon das grauen bekomme  . Und zwar: Seit wann überpüft man, ob es eine Datei gibt, mit TSearchRec oder ähnlichem? Dafür gibt es einen schönen Befehl: if FileExists then .
Und noch etwas. Was bringt es dir "Offz" als Paramater zu übergeben? Ich vermute mal, es ist so etwas wie "explorer", aber was genau? Office?
|
|
Born-to-Frag
      
Beiträge: 1094
Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
|
Verfasst: Do 20.07.06 19:01
Achso, ich dachte das mit der Konsolenanwendung solle nur ein Beispiel sein...
Sonst könntest du auch ShellExecute(0, 'open', 'C:\blubb.exe', nil, nil, SW_SHOW); machen.
Dann bräuchtest du nur noch die Units ShellAPI und Windows. Wenn du noch weniger willst, kannst du auch SW_SHOW einfach durch die Zahl 5 ersetzen, dann könntest du die ganze Unit Windows auch noch weglassen und SysUtils kannst du eh weglassen..
greetz
EDIT: Oder du deklarierst die Konstante der Übersichtlichkeits halber einfach neu:
Delphi-Quelltext 1: 2:
| SW_NORMAL = 1; SW_SHOW = 5; |
EDIT2: Ok das mit den neu deklarieren ist Sinnlos, die ShellAPI.pas hat in den Uses auch Windows 
_________________ Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
|
|
jasocul
      
Beiträge: 6395
Erhaltene Danke: 149
Windows 7 + Windows 10
Sydney Prof + CE
|
Verfasst: Fr 21.07.06 07:04
Heiko hat folgendes geschrieben: | Nun ja jasocul, wolltest du den Source wirklich einem Anfänger so geben? Denn der Source ist dermaßen unelegant/komisch (wie man auf den Lösungsweg kommt *g*), das ich schon das grauen bekomme . Und zwar: Seit wann überpüft man, ob es eine Datei gibt, mit TSearchRec oder ähnlichem? Dafür gibt es einen schönen Befehl: if FileExists then .
Und noch etwas. Was bringt es dir "Offz" als Paramater zu übergeben? Ich vermute mal, es ist so etwas wie "explorer", aber was genau? Office? |
"Offz" ist bei dem Programm eine interne Kennung. Hätte ich beim kopieren des Code besser rausnehmen sollen.
So besser? :
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
| procedure TfrmStart.FormActivate(Sender: TObject); var Fehler : Integer; begin if ParamCount > 0 then if FileExists(ParamStr(1)) then begin Fehler := ShellExecute(Application.Handle, 'open', PChar(Parameter), Nil, Nil, SW_SHOW); Close; end; end; |
Hey, solche "Fehler" können doch beim kopieren passieren. Einige Dinge sind dann einfach aus dem Kontext gerissen. Das SearchRec brauch ich übrigens aus einem besonderen Grund an der Stelle. Mein Programm vergleicht anhand der TSearchRec-Info zwei Dateien und macht bei Bedarf ein automatisches Update im LAN.
|
|
Samolex 
      
Beiträge: 22
Win xp
Delphi 5
|
Verfasst: Fr 21.07.06 08:33
So meine Code sieht jetzt so aus :
Delphi-Quelltext 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
| program Project2; {$APPTYPE CONSOLE} uses ShellApi, Windows;
Var i : Integer; Begin If ParamCount > 0 Then begin For i := 1 to ParamCount Do ShellExecute (0,'open',PChar(ParamStr(i)),Nil,Nil,SW_Show); End; End. |
Die Windows-Unit lass ich wegen SW_Show drinne.
Wie macht mann eigentlich diese "Delphi-Tags" ?
MfG Samolex
Moderiert von jasocul: Delphi-Tags hinzugefügt
|
|
|