Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Betriebssysteme (https://www.delphipraxis.net/27-betriebssysteme/)
-   -   Ersatz für Batch Befehl CHOICE ? (https://www.delphipraxis.net/69165-ersatz-fuer-batch-befehl-choice.html)

turboPASCAL 13. Mai 2006 10:00

Re: Ersatz für Batch Befehl CHOICE ?
 
Das soll nicht funktionieren ?

Delphi-Quellcode:
program Dings;

{$APPTYPE CONSOLE}

uses
  Windows;

procedure Exec(FullFileName: String);
var
  Err : Integer;
begin
  Err := WinExec(@FullFileName[1], SW_SHOWNORMAL);
  if Err <= 31 then
  begin
    WriteLn(''''+FullFileName+'''');
    case Err of
      0                      : WriteLn('The system is out of memory or resources.');
      ERROR_BAD_FORMAT      : WriteLn('The .EXE file is invalid (non-Win32 .EXE'+
                                     ' or error in .EXE image).');
      ERROR_FILE_NOT_FOUND : WriteLn('The specified file was not found.');
      ERROR_PATH_NOT_FOUND : WriteLn('The specified path was not found.');
        else WriteLn('Unkown Error');
    end;
    // Halt;
  end;
end;

procedure WriteChars(AnyChar: Char; Count: Word; NewLine: Boolean);
var i: Word;
begin
  for i := 0 to Count do
    Write(AnyChar);
  if NewLine then Writeln;
end;

function MyStrToInt(s: string; var i: integer): Boolean;
var
  Err: Integer;
begin
  val(s, i, err);
  if err <> 0 then MyStrToInt := False
    else MyStrToInt := True;
end;

var
  s: string;
  n: Integer;

begin
  WriteLn;
  WriteChars('-', 40, TRUE);
  WriteLn;
  WriteLn('[1] - Dell Latitude C840');
  WriteLn('[2] - PC001');
  WriteLn('[3] - Abbruch');
  WriteLn;
  WriteChars('-', 40, TRUE);
  WriteLn;

  repeat
    Write('Ihre Auswahl: ');
    Readln(s);

    if MyStrToInt(s, n) then
    begin
      case n of
        1: Exec('c:\net\netbind.com');
        2: Exec('c:\net\net.exe');
        3: WriteLn('Abbruch durch User.');
        else Write('Unzulaessige Eingabe. ');
      end;
    end else
      Write('Unzulaessige Eingabe. ');

  until n in [1..3];
end.

Andreas L. 13. Mai 2006 10:32

Re: Ersatz für Batch Befehl CHOICE ?
 
Zitat:

Zitat von turboPASCAL
Das soll nicht funktionieren ?

Delphi-Quellcode:
program Dings;

{$APPTYPE CONSOLE}

uses
  Windows;

procedure Exec(FullFileName: String);
var
  Err : Integer;
begin
  Err := WinExec(@FullFileName[1], SW_SHOWNORMAL);
  if Err <= 31 then
  begin
    WriteLn(''''+FullFileName+'''');
    case Err of
      0                      : WriteLn('The system is out of memory or resources.');
      ERROR_BAD_FORMAT      : WriteLn('The .EXE file is invalid (non-Win32 .EXE'+
                                     ' or error in .EXE image).');
      ERROR_FILE_NOT_FOUND : WriteLn('The specified file was not found.');
      ERROR_PATH_NOT_FOUND : WriteLn('The specified path was not found.');
        else WriteLn('Unkown Error');
    end;
    // Halt;
  end;
end;

procedure WriteChars(AnyChar: Char; Count: Word; NewLine: Boolean);
var i: Word;
begin
  for i := 0 to Count do
    Write(AnyChar);
  if NewLine then Writeln;
end;

function MyStrToInt(s: string; var i: integer): Boolean;
var
  Err: Integer;
begin
  val(s, i, err);
  if err <> 0 then MyStrToInt := False
    else MyStrToInt := True;
end;

var
  s: string;
  n: Integer;

begin
  WriteLn;
  WriteChars('-', 40, TRUE);
  WriteLn;
  WriteLn('[1] - Dell Latitude C840');
  WriteLn('[2] - PC001');
  WriteLn('[3] - Abbruch');
  WriteLn;
  WriteChars('-', 40, TRUE);
  WriteLn;

  repeat
    Write('Ihre Auswahl: ');
    Readln(s);

    if MyStrToInt(s, n) then
    begin
      case n of
        1: Exec('c:\net\netbind.com');
        2: Exec('c:\net\net.exe');
        3: WriteLn('Abbruch durch User.');
        else Write('Unzulaessige Eingabe. ');
      end;
    end else
      Write('Unzulaessige Eingabe. ');

  until n in [1..3];
end.

Wenn du das mit Delphi32 kompilierst, hast du eine Win32-Konsolen-Anwendung. Autoexec.bat kann aber nur DOS-Programme (16-Bit) starten.

turboPASCAL 13. Mai 2006 10:37

Re: Ersatz für Batch Befehl CHOICE ?
 
Es gibt ja auch noch Turbo Pascal 5,6,7 oder Delphi 1 oder ... ;)
Delphi-Quellcode:
program dings;

{$M $16000,0,0 }

{----------------------------------------------------------------}

uses Dos;

procedure Exec_(App, Param: string);
begin
  SwapVectors;
  Exec(App, Param);
  SwapVectors;
  if DosError <> 0 then
  begin
    Case DosError of
      2: Writeln('DosError: File not found');
      3: Writeln('DosError: Path not found');
      6: Writeln('DosError: Invalid handle');
      8: Writeln('DosError: Not enough memory');
      else WriteLn('Dos error #', DosError);
    end;
    Halt;
  end;
end;

{----------------------------------------------------------------}

procedure WriteChars(AnyChar: Char; Count: Word; NewLine: Boolean);
var i: Word;
begin
  for i := 0 to Count do
    Write(AnyChar);
  if NewLine then Writeln;
end;

function MyStrToInt(s: string; var i: integer): Boolean;
var
  Err: Integer;
begin
  val(s, i, err);
  if err <> 0 then MyStrToInt := False
    else MyStrToInt := True;
end;

var
  s: string;
  n: Integer;

begin
  WriteLn;
  WriteChars('-', 40, TRUE);
  WriteLn;
  WriteLn('[1] - Dell Latitude C840');
  WriteLn('[2] - PC001');
  WriteLn('[3] - Abbruch');
  WriteLn;
  WriteChars('-', 40, TRUE);
  WriteLn;

  repeat
    Write('Ihre Auswahl: ');
    Readln(s);

    if MyStrToInt(s, n) then
    begin
      case n of
        1: Exec_('c:\net\netbind.com', '');
        2: Exec_('c:\net\net.exe', '');
        3: WriteLn('Abbruch durch User.');
        else Write('Unzulaessige Eingabe. ');
      end;
    end else
      Write('Unzulaessige Eingabe. ');

  until n in [1..3];
end.
Done.

Jürgen Thomas 21. Apr 2007 15:14

Re: Ersatz für Batch Befehl CHOICE ?
 
Hallo,

zur Information, falls es noch für andere wichtig ist:

Ich habe für einen Kunden heute genau dieses Problem lösen müssen und festgestellt: Es ist grundsätzlich kein Problem, choice.com (in meinem Fall von Win95) zu kopieren und im cmd-Fenster von WinXP durch eine Batchdatei aufzurufen. Es ist lediglich (wie immer) darauf zu achten, dass dieses Hilfsprogramm auch über den Pfad erreichbar ist.

Jürgen


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:15 Uhr.
Seite 2 von 2     12   

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