Arrêter l'ordinateur

Programmation d'applications complexes
Le Soldat Inconnu
Messages : 4312
Inscription : mer. 28/janv./2004 20:58
Localisation : Clermont ferrand OU Olsztyn
Contact :

Message par Le Soldat Inconnu »

j'ai testé sur XP pro et win2000 et c'est nickel. merci

j'ai un peu modifier le code pour le rendre polyvalent :

Code : Tout sélectionner

Procedure ComputerShutDown(Param.l)
  ; Param = paramètre d'instinction de l'ordinateur
  ; 1 : quitter session
  ; 2 : arrêter
  ; 3 : redémarrer
 
  #TOKEN_ADJUST_PRIVILEGES = 32
  #TOKEN_QUERY = 8
  #SE_PRIVILEGE_ENABLED = 2
  #EWX_LOGOFF = 0
  #EWX_SHUTDOWN = 1
  #EWX_REBOOT = 2
  #EWX_FORCE = 4
  #EWX_POWEROFF = 8
  
  Structure MyLUID
    LowPart.l
    HighPart.l
    Attributes.l
  EndStructure
  
  Structure MyTOKEN
    PrivilegeCount.l
    LowPart.l
    HighPart.l
    Attributes.l
  EndStructure
  
  Protected hdlTokenHandle.l, tmpLuid.MyLUID, tkp.MyTOKEN, tkpNewButIgnored.MyTOKEN, lBufferNeeded.l

  OpenProcessToken_(GetCurrentProcess_(), #TOKEN_ADJUST_PRIVILEGES | #TOKEN_QUERY, @hdlTokenHandle)
  SysName.s = "" + Chr(0)
  Name.s = "SeShutdownPrivilege" + Chr(0)
  LookupPrivilegeValue_(SysName, Name, @tmpLuid)
  tmpLuid\Attributes = #SE_PRIVILEGE_ENABLED
  tkp\PrivilegeCount = 1
  tkp\LowPart = tmpLuid\LowPart
  tkp\HighPart = tmpLuid\HighPart
  tkp\Attributes = tmpLuid\Attributes
  AdjustTokenPrivileges_(hdlTokenHandle, 0, @tkp, SizeOf(MyTOKEN), @tkpNewButIgnored, @lBufferNeeded)
  
  Select Param
    Case 1 : ExitWindowsEx_(#EWX_LOGOFF | #EWX_FORCE, 0)
    Case 2 : ExitWindowsEx_(#EWX_SHUTDOWN | #EWX_FORCE, 0)
    Case 3 : ExitWindowsEx_(#EWX_REBOOT | #EWX_FORCE, 0)
  EndSelect
  
EndProcedure
Je ne suis pas à moitié Polonais mais ma moitié est polonaise ... Vous avez suivi ?

[Intel quad core Q9400 2.66mhz, ATI 4870, 4Go Ram, XP (x86) / 7 (x64)]
Répondre