IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

API, COM et SDKs Delphi Discussion :

Arrêt Windows sur pc distant [InitiateSystemShutdown]


Sujet :

API, COM et SDKs Delphi

  1. #21
    Futur Membre du Club
    Profil pro
    Inscrit en
    Avril 2005
    Messages
    17
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Avril 2005
    Messages : 17
    Points : 6
    Points
    6
    Par défaut
    Je me suis basé sur le lien que tu m'as passé Laurent, sur la FAQ Delphi pour écrire ce code.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    42
    43
    44
    45
    Function ArretSystemDistant: Boolean;
    Var
     Token: THandle;
     TokenPrivilege: TTokenPrivileges;
     Outlen : Cardinal;
     Error:Dword;
     
    Const
     SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
     
    Begin
       Result:=False;
       // Récupère les informations de sécurité pour ce process.
       if not OpenProcessToken(GetCurrentProcess, TOKEN_ADJUST_PRIVILEGES, Token)
        then Exit;
      try
     
       FillChar(TokenPrivilege, SizeOf(TokenPrivilege),0);
         // Valeur de retour
       Outlen := 0;
         // Un seul privilége à positionner
       TokenPrivilege.PrivilegeCount := 1;
     
         // Récupère le LUID pour le privilége 'shutdown'.
         // un Locally Unique IDentifier est une valeur générée unique jusqu'a ce
         // que le système soit redémarré
       LookupPrivilegeValue('\\192.168.123.110', SE_SHUTDOWN_NAME, TokenPrivilege.Privileges[0].Luid);
     
         // Positionne le privilége shutdown pour ce process.
       TokenPrivilege.Privileges[0].Attributes:=SE_PRIVILEGE_ENABLED;
       AdjustTokenPrivileges(Token, False, TokenPrivilege, SizeOf(TokenPrivilege),nil, OutLen);
     
       Error:=GetLastError;
       If Error <> ERROR_SUCCESS
        then Exit;
     
         // Arrête le système distant
       if InitiateSystemShutdown('\\192.168.123.110', 'Shutting down !', 10, True, False)=False
          then Exit;
       Result:=True;
     
      finally
       CloseHandle(Token);
      end;
    end;
    J'ai essayé d'obtenir des droits sur le pc distant à l'aide de la fonction LookupPrivilegeValue, mais malheureusement le pc distant sur mon réseau ne reboot tjs pas !

    Si quelqu'un peut encore me donner un p'tit coup d'pouce, ça serait vraiment sympa.

  2. #22
    Membre du Club
    Profil pro
    Inscrit en
    Mai 2002
    Messages
    50
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2002
    Messages : 50
    Points : 61
    Points
    61
    Par défaut
    salut,

    dans le meme style j'ai trouve le lien ci dessous, a tester:

    http://www.swissdelphicenter.ch/en/showcode.php?id=2176

    ou

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
     
    {-----------------------------------------------------------------------------
     Unit Name:     formClient
     Author:        Stewart Moss
     
     Creation Date: 27 February, 2002 (16:30)
     Documentation Date: 27 February, 2002 (16:30)
     
     Version 1.0
     -----------------------------------------------------------------------------
     
     Description:
     
      This is to demonstrate shutting down a machine over the network.
      It is in reply to a question posted on www.delphi3000.com.
     
      ** Tobias R. requests the article "How to send a shutdown command in a network?" **
     
      This is not really what you want. I think you are looking for some kind
      of IPC or RPC command. But this will work. Each machine needs to run
      a copy of this server.
     
      It uses the standard delphi ServerSocket found in the "ScktComp" unit.
     
      Create a form (name frmClient) with a TServerSocket on it (name ServerSocket)
      set the Port property of ServerSocket to 5555. Add a TMemo called Memo1.
     
      It listens on port 5555 using TCP/IP.
     
      It has a very simple protocol.
      Z = Show message with "Z"
      B = Beep
      S = Shutdown windows
     
      Run the program.. Then from the command prompt type in
      "telnet localhost 5555". Type in one of the three commands above
      (all in uppercase) and the server will respond.
     
     Copyright 2002 by Stewart Moss. All rights reserved.
    -----------------------------------------------------------------------------}
     
    unit formClient;
     
    interface
     
    uses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      ScktComp, StdCtrls;
     
    type
      TfrmClient = class(TForm)
        ServerSocket: TServerSocket;
        Memo1: TMemo;
        procedure ServerSocketClientRead(Sender: TObject;
          Socket: TCustomWinSocket);
        procedure FormCreate(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
     
    var
      frmClient: TfrmClient;
     
    implementation
     
    {$R *.DFM}
     
    procedure TfrmClient.ServerSocketClientRead(Sender: TObject;
      Socket: TCustomWinSocket);
      var
      Incomming : string;
    begin
      // read off the socket
      Incomming := Socket.ReceiveText;
     
      memo1.Lines.Add(incomming);
     
      if Incomming = 'S' then // Shutdown Protocol
        ExitWindowsEx( EWX_FORCE or EWX_SHUTDOWN, 0 );
     
      If Incomming = 'B' then // Beep Protocol
        Beep;
     
      If Incomming = 'Z' then // Z protocol
        showmessage('Z');
    end;
     
    procedure TfrmClient.FormCreate(Sender: TObject);
    begin
      ServerSocket.Active := true;
    end;
     
    procedure TfrmClient.FormClose(Sender: TObject; var Action: TCloseAction);
    begin
      ServerSocket.Active := false;
    end;
     
    end.
    le code vient de http://www.delphi3000.com

    et il n'est pas teste...

  3. #23
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Points : 15 060
    Points
    15 060
    Billets dans le blog
    1
    Par défaut
    Salut,
    regarde ici http://www.luckie-online.de/Programme/RShutdown/index.shtml
    Source en allemand mais cela reste exploitable a mon avis.
    Je n'ai pas le temps de le tester par contre si cela fonctionne peux-tu nous proposer un exemple simple pour la FAQ ?

  4. #24
    Candidat au Club
    Profil pro
    Inscrit en
    Septembre 2005
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2005
    Messages : 3
    Points : 4
    Points
    4
    Par défaut
    Citation Envoyé par alec_002
    J'ai essayé d'obtenir des droits sur le pc distant à l'aide de la fonction LookupPrivilegeValue, mais malheureusement le pc distant sur mon réseau ne reboot tjs pas !
    Je vais ptet dire une connerie, mais penses-tu que ce soit normal que tu puisses augmenter tes droits à distance ?? Cela signifierait que n'importe qui pourrai le faire à travers internet...

    Il me semble que pour éteindre un pc à distance avec XP il faut spécifier les ip des ordinateurs de "confiance" qui peuvent le faire, mais je n'en sais pas plus...

Discussions similaires

  1. [batch] [services windows] état service sur serveur distant
    Par Deadpool dans le forum Scripts/Batch
    Réponses: 3
    Dernier message: 16/03/2009, 17h50
  2. Authentification Windows sur une machine distante
    Par titip dans le forum Windows Forms
    Réponses: 11
    Dernier message: 01/08/2008, 18h57
  3. récupérer la version d'OS windows sur un PC distant
    Par DegubError dans le forum Windows
    Réponses: 4
    Dernier message: 31/01/2006, 20h28
  4. [DBA] Arrêt Oracle sur Windows
    Par titof dans le forum Oracle
    Réponses: 6
    Dernier message: 26/01/2006, 14h14
  5. Application Windows gérant une DB ACCESS sur serveur distant
    Par paulgiot dans le forum Bases de données
    Réponses: 1
    Dernier message: 11/01/2005, 09h59

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo