Comment éteindre le pc ?

Comment éteindre le pc ? - Delphi/Pascal - Programmation

Marsh Posté le 07-01-2005 à 21:28:41    

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 :)

Reply

Marsh Posté le 07-01-2005 à 21:28:41   

Reply

Marsh Posté le 07-01-2005 à 21:51:54    

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
Reply

Marsh Posté le 07-01-2005 à 22:20:11    

je doi le mettre ou ?

Reply

Marsh Posté le 08-01-2005 à 00:16:31    

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;

Reply

Marsh Posté le 08-01-2005 à 08:19:08    

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

Reply

Marsh Posté le 08-01-2005 à 13:23:31    

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;  

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed