Autor Beitrag
King_Crasher
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37

WIN XP
Delphi 2003
BeitragVerfasst: Sa 11.02.06 12:53 
Hallo, gibt es eine Möglichkeit Dos Befehle bei Delphi miteinzubringen?


Danke schon im Voraus


Moderiert von user profile iconGausi: Topic aus VCL (Visual Component Library) verschoben am Sa 11.02.2006 um 12:59
WolfB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 39

WinXP Professional
Delphi 7
BeitragVerfasst: Sa 11.02.06 14:26 
ich habe das bisher immer so gemacht, dos befehle in ne stringlist zu schreiben, wie man es in nem normalen editor machen würde, diese stringlist dann als .bat zu speichern und dann auszuführen.
ist zwar umständlich, aber klappt :)
King_Crasher Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37

WIN XP
Delphi 2003
BeitragVerfasst: Sa 11.02.06 18:39 
Ich hab eher daran gedacht einen Button mit einem Dos Befehl zu belegen. z.b das Herunterfahren des Systems mit "shutdown".
Fädas
ontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 73

Win XP
Delphi 5
BeitragVerfasst: Sa 11.02.06 18:51 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, shellapi;

procedure TForm1.FormActivate(Sender: TObject);
begin
ShellExecute(0,'open','C:\WINDOWS\system32\tsshutdn.exe ',PChar(''),nil,SW_normal); // Herunterfahren


ShellExecute(0,'open','cmd.exe',PChar(''),nil,SW_normal);  // Dos öffnen
end;
WolfB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 39

WinXP Professional
Delphi 7
BeitragVerfasst: Sa 11.02.06 19:29 
könnteste ja mit meiner lösung. der shutdownbefehl würde dann zu beginn des programms in die stringlist geschrieben, als .bat gespeichert und der knopf würde dann die datei ausführen.
King_Crasher Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37

WIN XP
Delphi 2003
BeitragVerfasst: So 12.02.06 17:40 
Zu dem Quelltext von Fädas. Der funktioniert. Ich wollte aber nicht das sich die Eingabauffoderung öffnet. Den Shutdownbefehl kann ich ja noch ausbauen. z.B. selber die Zeit angebeben oder einen Nachricht anzeigen lassen. Der Benutzer soll nur wissen das sein rechner ausgeht. Geht so was auch???
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 12.02.06 18:30 
Es gibt eine Funktion ExWindows im EasyHelper --> www.delphi-source.de

Die fährt den PC herunter.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Fädas
ontopic starontopic starontopic starofftopic starofftopic starofftopic starofftopic starofftopic star
Beiträge: 73

Win XP
Delphi 5
BeitragVerfasst: Mo 13.02.06 21:41 
@King_crasher: ja, das geht auch aber dafür brauchst nicht shutdown.exe, sondern wa anderes. Und wenn du das Dos-Fenster nicht sehen willst setzt du SW_hide. Ich glaube aber, dass er nicht direkt herunterfahren wird, weil windows immer 30 sekunden wartet bevor es per dos heruntergefahren wird.(Ich glaube damit man genug Zeit zum Speichern hat oder so)
King_Crasher Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37

WIN XP
Delphi 2003
BeitragVerfasst: Mi 15.02.06 16:39 
Ich hab mir jetzt mal was geholt was Windows herunterfahren sollte. Allerdings kommt die Fehlermeldung "Undeclared identifier: 'result'" weiß einer was das heißt???

Hier mein Quelltext:

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:
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, shellapi, Menus;

var
  Form1: TForm1;
  vi     : TOSVersionInfo;
  hToken : THandle;
  tp     : TTokenPrivileges;
  h      : DWord;

procedure TForm1.Herunterfahren1Click(Sender: TObject);

begin
  result:= false;

  vi.dwOSVersionInfoSize:=SizeOf(vi);

  if GetVersionEx(vi) then
  begin
    if vi.dwPlatformId = VER_PLATFORM_WIN32_NT then
    begin
      // Windows NT
      // Achtung bei Delphi 2 muß @hToken stehen ...
      if OpenProcessToken(GetCurrentProcess,TOKEN_ADJUST_PRIVILEGES,hToken) then
      begin
        LookupPrivilegeValue(nil,'SeShutdownPrivilege',tp.Privileges[0].Luid);
        tp.PrivilegeCount := 1;
        tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
        h := 0;
        AdjustTokenPrivileges(hToken,False,tp,0,PTokenPrivileges(nil)^, h);
        CloseHandle(hToken);
        result := ExitWindowsEx(EWX_Logoff, 0);
      end;

    end;
  end;

end;

end.
Codewalker
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 46



BeitragVerfasst: Mi 15.02.06 17:01 
Result ist der Rückgabewert einer Funktion, der immer automatisch vorhanden ist. Du hast aber nur eine Prozedur (Herunterfahren1Click), da gibt es keinen Rückgabewert. Du musst einfach auswerten, ob

ausblenden Delphi-Quelltext
1:
ExitWindowsEx(EWX_Logoff, 0);					


True ergibt. Bei False, ist etwas schiefgelaufen und das System wird doch nicht heruntergefahren. Also etwa so

ausblenden Delphi-Quelltext
1:
2:
 If ExitWindowsEx(EWX_Logoff, 0) = False
  then ShowMessage("Ist schiefgelaufen!")
commin
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 17

WinXP
Delphi 5
BeitragVerfasst: Mi 15.02.06 17:48 
Du kannst das mit der *.bat Datei machen. Der Rechner fährt auch sofort runter wenn du in die datei "shutdown -f -s -t 01" schreibst. 01steht für die wartezeit - ob es auch mit 00 funktioniert weiß ich nicht genau - müsstest du mal ausprobieren.
King_Crasher Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 37

WIN XP
Delphi 2003
BeitragVerfasst: Mi 15.02.06 19:24 
Das mit der *.bat ist klar. Das funzt auch. Ich dachte bloß es gibt so einen Befehl in Delphi der das Herunterfahren realisert.

@Codewalker: Ich bin noch ein Anfänger. Hab Delphi erst seit 3 Wochen. Vielleicht könntest du mir ja mal den Quelltext volkommen zeigen. Ich versteh dich nähmlich nicht. Sorry