Ver Mensaje Individual
  #5  
Antiguo 13-04-2012
Rolando Glez Rolando Glez is offline
Miembro
 
Registrado: nov 2004
Ubicación: Havana
Posts: 62
Reputación: 20
Rolando Glez Va por buen camino
Lo que dice Roman es cierto pero no logro saber porque no hace el shutdown

Código Delphi [-]
const

SE_CREATE_TOKEN_NAME = 'SeCreateTokenPrivilege';
SE_ASSIGNPRIMARYTOKEN_NAME = 'SeAssignPrimaryTokenPrivilege';
SE_LOCK_MEMORY_NAME = 'SeLockMemoryPrivilege';
SE_INCREASE_QUOTA_NAME = 'SeIncreaseQuotaPrivilege';
SE_UNSOLICITED_INPUT_NAME = 'SeUnsolicitedInputPrivilege';
SE_MACHINE_ACCOUNT_NAME = 'SeMachineAccountPrivilege';
SE_TCB_NAME = 'SeTcbPrivilege';
SE_SECURITY_NAME = 'SeSecurityPrivilege';
SE_TAKE_OWNERSHIP_NAME = 'SeTakeOwnershipPrivilege';
SE_LOAD_DRIVER_NAME = 'SeLoadDriverPrivilege';
SE_SYSTEM_PROFILE_NAME = 'SeSystemProfilePrivilege';
SE_SYSTEMTIME_NAME = 'SeSystemtimePrivilege';
SE_PROF_SINGLE_PROCESS_NAME = 'SeProfileSingleProcessPrivilege';
SE_INC_BASE_PRIORITY_NAME = 'SeIncreaseBasePriorityPrivilege';
SE_CREATE_PAGEFILE_NAME = 'SeCreatePagefilePrivilege';
SE_CREATE_PERMANENT_NAME = 'SeCreatePermanentPrivilege';
SE_BACKUP_NAME = 'SeBackupPrivilege';
SE_RESTORE_NAME = 'SeRestorePrivilege';
SE_SHUTDOWN_NAME = 'SeShutdownPrivilege';
SE_DEBUG_NAME = 'SeDebugPrivilege';
SE_AUDIT_NAME = 'SeAuditPrivilege';
SE_SYSTEM_ENVIRONMENT_NAME = 'SeSystemEnvironmentPrivilege';
SE_CHANGE_NOTIFY_NAME = 'SeChangeNotifyPrivilege';
SE_REMOTE_SHUTDOWN_NAME = 'SeRemoteShutdownPrivilege';
SE_UNDOCK_NAME = 'SeUndockPrivilege';
SE_SYNC_AGENT_NAME = 'SeSyncAgentPrivilege';
SE_ENABLE_DELEGATION_NAME = 'SeEnableDelegationPrivilege';
SE_MANAGE_VOLUME_NAME = 'SeManageVolumePrivilege';

// Enables or disables privileges debending on the bEnabled
// Aktiviert oder deaktiviert Privilegien, abhängig von bEnabled








Código:
type
    
   
  TMainForm = class(TForm)
    PopupMenu1: TPopupMenu;
    ShowForm1: TMenuItem;
    HideForm1: TMenuItem;
    ImageList1: TImageList;
    ListBox1: TListBox;
    
Código Delphi [-]
procedure
FormCreate(Sender: TObject);
Código Delphi [-]
procedure
FormDestroy(Sender: TObject);
Código Delphi [-]
procedure
ShowForm1DrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
Código Delphi [-]
procedure
HideForm1DrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
Código Delphi [-]
procedure
Exit1DrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
Código Delphi [-]
 procedure
Exit1Click(Sender: TObject); procedure AnimateIcon1DrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
Código Delphi [-]
procedure
ShowForm1Click(Sender: TObject);
Código Delphi [-]
 procedure
HideForm1Click(Sender: TObject);
Código Delphi [-]
procedure
Exit1MeasureItem(Sender: TObject; ACanvas: TCanvas; var Width, Height: Integer);
Código Delphi [-]
procedure
AnimateIcon1Click(Sender: TObject);
Código Delphi [-]
procedure
FormActivate(Sender: TObject);
Código Delphi [-]
procedure
FormCanResize(Sender: TObject; var NewWidth, NewHeight: Integer; var Resize: Boolean);
Código Delphi [-]
procedure
WndProc(var Message: TMessage); override;
Código Delphi [-]
 private
TrayIconData: TNotifyIconData; //procedure TimerCallback (Sender: TObject);
Código Delphi [-]
public
procedure TrayMessage(var Msg: TMessage); message WM_ICONTRAY; procedure DrawBar(ACanvas: TCanvas); end;
//Esta no son todas las property del objeto pero las que involucran al systray estan















//Esta funsion parece ser necesaria para realizar un shutdown en NT Y XP pero ni llamandola el programa realiza el mismo
//

Código:
Código Delphi [-]
function
NTSetPrivilege(sPrivilege: string; bEnabled: Boolean): Boolean; var hToken: THandle; TokenPriv: TOKEN_PRIVILEGES; PrevTokenPriv: TOKEN_PRIVILEGES; ReturnLength: Cardinal;
Código Delphi [-]
begin
Result := True; // Only for Windows NT/2000/XP and later.
Código Delphi [-]
if
not (Win32Platform = VER_PLATFORM_WIN32_NT)
Código Delphi [-]
then
Exit; Result := False; // obtain the processes token
Código Delphi [-]
if
OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES or TOKEN_QUERY, hToken)
Código Delphi [-]
then
  begin
Código Delphi [-]
 try
// Get the locally unique identifier (LUID) .
Código Delphi [-]
 if
LookupPrivilegeValue(nil, PChar(sPrivilege), TokenPriv.Privileges[0].Luid) then
Código Delphi [-]
 begin
TokenPriv.PrivilegeCount := 1; // one privilege to set
Código Delphi [-]
case
bEnabled
Código Delphi [-]
of
True: TokenPriv.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED; False: TokenPriv.Privileges[0].Attributes := 0;
Código Delphi [-]
end;
ReturnLength := 0; // replaces a var parameter PrevTokenPriv := TokenPriv; // enable or disable the privilege AdjustTokenPrivileges(hToken, bEnabled, TokenPriv, SizeOf(PrevTokenPriv), PrevTokenPriv, ReturnLength);
Código Delphi [-]
 end;
    finally
CloseHandle(hToken);
Código Delphi [-]
end;
  end;
// test the return value of AdjustTokenPrivileges. Result := GetLastError = ERROR_SUCCESS; if not Result then raise Exception.Create(SysErrorMessage(GetLastError)); end;







Código Delphi [-]
procedure
TMainForm.WndProc (var Message: TMessage);

Código Delphi [-]
var
hwnd,exitcode:word;


Código Delphi [-]
begin

hwnd:=Handle;
if (MESSAGE.MSG=WM_ENDSESSION) then
Código Delphi [-]
begin

Código Delphi [-]
if
MESSAGE.LParam=ENDSESSION_LOGOFF
Código Delphi [-]
then
then
Código Delphi [-]
begin
DestroyWindow(hwnd);
//postquitmessage(exitcode);
ExitWindowsEx(EWX_FORCE,0);//esta instruccion se ejecuta perfectamente cerrando la session, aunque para mi no es necesaria
Código Delphi [-]
end
Código Delphi [-]
  else
                         begin
DestroyWindow(hwnd);
//postquitmessage(exitcode);
NTSetPrivilege(SE_SHUTDOWN_NAME,true);
//Lei que es necesario el llamado para realizar shutdown
ExitWindowsEx(EWX_SHUTDOWN,0);
//No se ejecuta exitosamente la anterior instruccion, el programa se va de memoria pero para el shutdown

Código Delphi [-]
 end

Código Delphi [-]
end
[delphi]else
inherited WndProc (Message);


Código Delphi [-]
end;






La idea es que cuando MESSAGE.LParam=ENDSESSION_LOGOFF
se cierre la session pero que cuando sea otra cosa se apague el sistema, el llamado a cerrar la session se ejecuta exitosamente sin embargo el shutdown no ,sencillamente window para el mismo,pense que el privilegio era la causa ,me hice de esta funsion pero ni llamandola
el desgraciado shutdown se ejecuta
Responder Con Cita