Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to shut down a machine across the network Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
14-Nov-02
Category
Internet / Web
Language
Delphi 2.x
Views
292
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			 Author: Stewart Moss

How to send a shutdown command in a network?

Answer:
1   
2   {-----------------------------------------------------------------------------
3    Unit Name:     formClient
4    Author:        Stewart Moss
5   
6    Creation Date: 27 February, 2002 (16:30)
7    Documentation Date: 27 February, 2002 (16:30)
8   
9    Version 1.0
10   -----------------------------------------------------------------------------
11  
12   Description:
13   
14    This is to demonstrate shutting down a machine over the network.
15  
16    ** Tobias R. requests the article "How to send a shutdown command in a network?" 
17  **
18  
19    This is not really what you want. I think you are looking for some kind
20    of IPC or RPC command. But this will work. Each machine needs to run
21    a copy of this server.
22  
23    It uses the standard delphi ServerSocket found in the "ScktComp" unit.
24  
25    Create a form (name frmClient) with a TServerSocket on it (name ServerSocket)
26    set the Port property of ServerSocket to 5555. Add a TMemo called Memo1.
27  
28    It listens on port 5555 using TCP/IP.
29  
30    It has a very simple protocol.
31    Z = Show message with "Z"
32    B = Beep
33    S = Shutdown windows
34  
35    Run the program.. Then from the command prompt type in
36    "telnet localhost 5555". Type in one of the three commands above
37    (all in uppercase) and the server will respond.
38  
39   Copyright 2002 by Stewart Moss. All rights reserved.
40  -----------------------------------------------------------------------------}
41  
42  unit formClient;
43  
44  interface
45  
46  uses
47    Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
48    ScktComp, StdCtrls;
49  
50  type
51    TfrmClient = class(TForm)
52      ServerSocket: TServerSocket;
53      Memo1: TMemo;
54      procedure ServerSocketClientRead(Sender: TObject;
55        Socket: TCustomWinSocket);
56      procedure FormCreate(Sender: TObject);
57      procedure FormClose(Sender: TObject; var Action: TCloseAction);
58    private
59      { Private declarations }
60    public
61      { Public declarations }
62    end;
63  
64  var
65    frmClient: TfrmClient;
66  
67  implementation
68  
69  {$R *.DFM}
70  
71  procedure TfrmClient.ServerSocketClientRead(Sender: TObject;
72    Socket: TCustomWinSocket);
73  var
74    Incomming: string;
75  begin
76    // read off the socket
77    Incomming := Socket.ReceiveText;
78  
79    memo1.Lines.Add(incomming);
80  
81    if Incomming = 'S' then // Shutdown Protocol
82      ExitWindowsEx(EWX_FORCE or EWX_SHUTDOWN, 0);
83  
84    if Incomming = 'B' then // Beep Protocol
85      Beep;
86  
87    if Incomming = 'Z' then // Z protocol
88      showmessage('Z');
89  end;
90  
91  procedure TfrmClient.FormCreate(Sender: TObject);
92  begin
93    ServerSocket.Active := true;
94  end;
95  
96  procedure TfrmClient.FormClose(Sender: TObject; var Action: TCloseAction);
97  begin
98    ServerSocket.Active := false;
99  end;
100 
101 end.


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC