Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2997 connectés 

  FORUM HardWare.fr
  Programmation
  Delphi/Pascal

  Comment éteindre le pc ?

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Comment éteindre le pc ?

n°940703
sbeex1
Posté le 07-01-2005 à 21:28:41  profilanswer
 

bonjour je travail sur un projet et je narrive pa a eteindre le pc avec la fonction  :pfff: :  
 
ExitWindowsEx(EWX_ShutDown,0);  
 
 je ne comprend pa...  
 
(jai delphi 7) si kelk1 peu maider :hello:  merci davance :)

mood
Publicité
Posté le 07-01-2005 à 21:28:41  profilanswer
 

n°940728
xfifi
Posté le 07-01-2005 à 21:51:54  profilanswer
 

A essayer :
 
Function EteindreWindows(modeForce : Boolean = False) : Boolean;
begin
   if not modeForce then Result := ExitWindowsEx(EWX_SHUTDOWN, 0)
   else Result := ExitWindowsEx(EWX_SHUTDOWN + EWX_FORCE, 0);
end;
 
 
 
 


---------------
Mon feed-back achats & ventes
n°940748
sbeex1
Posté le 07-01-2005 à 22:20:11  profilanswer
 

je doi le mettre ou ?

n°940817
gligli
Posté le 08-01-2005 à 00:16:31  profilanswer
 

je pense que ton probleme viens du fait que sous Windows NT, un processus n'a par défaut pas le droit d'éteindre l'ordinateur, voila un bout de code qui permettra de lui rajouter ce droit:
 


var  hToken, hProcess: THandle;
     tp, prev_tp: TTokenPrivileges;
     Len: DWORD;
begin
  if Win32Platform = VER_PLATFORM_WIN32_NT then
  begin
    hProcess := OpenProcess(PROCESS_ALL_ACCESS, True, GetCurrentProcessID);
    try
      if not OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
        hToken) then Exit;
    finally
      CloseHandle(hProcess);
    end;
    try
      if not LookupPrivilegeValue('', 'SeShutdownPrivilege',
        tp.Privileges[0].Luid) then Exit;
      tp.PrivilegeCount := 1;
      tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
      if not AdjustTokenPrivileges(hToken, False, tp, SizeOf(prev_tp),
        prev_tp, Len) then Exit;
    finally
      CloseHandle(hToken);
    end;
  end;
end;

n°948929
sbeex1
Posté le 08-01-2005 à 08:19:08  profilanswer
 

okay alor je suis désolé mais je ne c pa encore très bien manier delphi 7 et jaimerais ke mon appli soi compatible XP,NT etc.. etc... au maximum  
 
voila la partie du code a modifier :
 
-------------------------------------------------
procedure TForm1.Timer3Timer(Sender: TObject);
begin
 Label4.Caption:=FormatDateTime('hh:mm:ss',Time);
 if Label4.Caption=combobox1.text+':'+combobox2.Text+':'+combobox4.Text then
 if radiobutton2.Checked then ExitWindowsEx(EWX_ShutDown,0);  
 
 
end;
 
end.
 
---------------------------------------------------
si c'est possible de me le modfier sa serai simpa parce ke je comprendrais mieu merci davance

n°949098
gligli
Posté le 08-01-2005 à 13:23:31  profilanswer
 

ben euh tu copie le code dans ta fonction, c'est tout, ca donnera ca:
 


procedure TForm1.Timer3Timer(Sender: TObject);
var  hToken, hProcess: THandle;
     tp, prev_tp: TTokenPrivileges;
     Len: DWORD;  
begin
  if Win32Platform = VER_PLATFORM_WIN32_NT then
  begin
    hProcess := OpenProcess(PROCESS_ALL_ACCESS, True, GetCurrentProcessID);
    try
      if not OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY,
        hToken) then Exit;
    finally
      CloseHandle(hProcess);
    end;
    try
      if not LookupPrivilegeValue('', 'SeShutdownPrivilege',
        tp.Privileges[0].Luid) then Exit;
      tp.PrivilegeCount := 1;
      tp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;
      if not AdjustTokenPrivileges(hToken, False, tp, SizeOf(prev_tp),
        prev_tp, Len) then Exit;
    finally
      CloseHandle(hToken);
    end;
  end;  
 
 
 Label4.Caption:=FormatDateTime('hh:mm:ss',Time);
 if Label4.Caption=combobox1.text+':'+combobox2.Text+':'+combobox4.Text then
 if radiobutton2.Checked then ExitWindowsEx(EWX_ShutDown,0);  
 
end;  


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Delphi/Pascal

  Comment éteindre le pc ?

 

Sujets relatifs
eteindre win2k avec un .bat???appel system pour eteindre/fermer la session immediatement
Fonction pour eteindre le pcC/C++/windows 2000 : empécher l'écran de s'éteindre
eteindre l'ordiEteindre un pc sous 2k avec un *.bat
eteindre le pcEteindre un PC avec un programme JAVA ???
[vc++] eteindre sa machine sous Windows NT[c++] Comment fait on pour éteindre le PC à partir d'un programme ?
Plus de sujets relatifs à : Comment éteindre le pc ?


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)