home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / lan / spy / source / spyboot.pas < prev    next >
Pascal/Delphi Source File  |  1989-10-03  |  3KB  |  119 lines

  1. {$A+,B-,D-,E-,F+,I+,L-,N-,O-,R-,S-,V+}
  2. {$M 16384,0,655360}
  3. Program SpyBoot;
  4. { SPYBOOT Network Remote Opertaions.  Order SPYTSR to reboot.
  5.   This program is:
  6.   Copyright (c) 1989 by Edwin T. Floyd
  7.   All rights reserved
  8.  
  9.   Noncommercial use encouraged; direct commercial inquires and problem reports
  10.   to the author:
  11.  
  12.   Edwin T. Floyd [76067,747]
  13.   #9 Adams Park Court
  14.   Columbus, GA 31909
  15.   404-322-0076 (home)
  16.   404-576-3305 (work)
  17. }
  18. Uses Multi, NetBios, SpySup;
  19.  
  20. Var
  21.   Adapter : Byte;
  22.   SpyLsn : Byte;
  23.   SessionUp : Boolean;
  24.   MyName : NetNameType;
  25.   CallName : NetNameType;
  26.  
  27. Procedure SendBootRequest;
  28. Var
  29.   BootReq : RequestType;
  30.   BootNct : TaskNctType;
  31.   Err : Byte;
  32. Begin
  33.   With BootNct, BootReq Do Begin
  34.     NetSetAdapter(Nct, Adapter, NetNoWait, NetTaskPost);
  35.     BootReq.Count := 0;
  36.     Req := Boot;
  37.     NetSend(Nct, SpyLsn, BootReq, SizeOf(BootReq) - SizeOf(Key));
  38.     Err := NetWaitError(BootNct, 2000);
  39.     If Err = 0 Then
  40.       WriteLn('SPYTSR ordered to reboot: ', Copy(CallName, 1, 15))
  41.     Else Begin
  42.       WriteLn('Unable to send boot request ', Err);
  43.       If NetReturnAction(Nct) = SessionDead Then
  44.         SessionUp := False;
  45.     End;
  46.     NetShutdown;
  47.     If SessionUp Then Begin
  48.       NetHangup(Nct, SpyLsn);
  49.       Err := NetWaitError(BootNct, 500);
  50.     End;
  51.   End;
  52.   NetShutdown;
  53.   WriteLn('SPYBoot Terminated');
  54.   StopAll(0);
  55. End;
  56.  
  57. Procedure InitSpyBoot;
  58. Var
  59.   i, j : Integer;
  60.   NameNct : TaskNctType;
  61.   Status : NetAdapterStatusType;
  62.   Err : Byte;
  63.   s : String[2];
  64. Begin
  65.   SessionUp := False;
  66.   If (ParamCount < 1) Or (ParamStr(1) = '') Then Begin
  67.     WriteLn('Run like this: SPYBOOT <name>');
  68.     StopAll(1);
  69.   End Else Begin
  70.     CallName := ParamStr(1);
  71.     For i := 1 To Length(CallName) Do CallName[i] := UpCase(CallName[i]);
  72.     While Length(CallName) < 16 Do
  73.       Insert(' ', CallName, Succ(Length(CallName)));
  74.     CallName[16] := #$EF;
  75.   End;
  76.   If ParamCount > 1 Then Begin
  77.     s := ParamStr(2);
  78.     Val(s, i, j);
  79.     If (i >= 0) And (i < 3) Then Adapter := i Else Begin
  80.       WriteLn('Adapter must be 0..3, "', ParamStr(2), '" specified');
  81.       StopAll(2);
  82.     End;
  83.   End Else Adapter := 0;
  84.   If Not NetAdapterPresent(Adapter) Then Begin
  85.     WriteLn('Adapter ', Adapter, ' not found');
  86.     StopAll(3);
  87.   End;
  88.   With NameNct Do Begin
  89.     NetSetAdapter(Nct, Adapter, NetNoWait, NetTaskPost);
  90.     WriteLn('Getting Unit Name for adapter ', Adapter);
  91.     NetAdapterStatus(Nct, Status, '*');
  92.     Err := NetWaitError(NameNct, 1000);
  93.     If Err <> 0 Then Begin
  94.       WriteLn('Unable to acquire local adapter Unit Name, error ', Err);
  95.       StopAll(4);
  96.     End Else Begin
  97.       MyName[0] := #16;
  98.       FillChar(MyName[1], 10, 0);
  99.       Move(Status.UnitId, MyName[11], 6);
  100.     End;
  101.     WriteLn('Calling ', Copy(CallName, 1, 15));
  102.     NetCall(Nct, CallName, MyName, CallRto, CallSto);
  103.     Err := NetWaitError(NameNct, 1000);
  104.     If Err <> 0 Then Begin
  105.       WriteLn('Unable to connect to ', Copy(CallName, 1, 15),
  106.         ', error ', Err);
  107.       StopAll(5);
  108.     End;
  109.     SpyLsn := NetLsn(Nct);
  110.     SessionUp := True;
  111.   End;
  112.   WriteLn('Connected to ', Copy(CallName, 1, 15));
  113. End;
  114.  
  115. Begin
  116.   WriteLn('SPYBOOT Version 1.1 Starting');
  117.   InitSpyBoot;
  118.   SendBootRequest;
  119. End.