Jump to content
Fivewin Brasil

LogOff ao fechar o sistema (resolvido)


oribeiro

Recommended Posts

Tinha isso em meu sistema a muitos anos atras a pedido de um cliente. Veja ai, não sei se funciona, faça um teste:

 

#pragma BEGINDUMP

#include <windows.h>
#include "hbapi.h"

// SHUTDOWN()
// Funcao que Desliga o Computador no WindowsXP
// Chamando somente a função ExitWindowsEx o Windows só vai fazer logoff
// é preciso obter privilégios antes

HB_FUNC(SHUTDOWN)
{
  HANDLE hToken;
  TOKEN_PRIVILEGES tkp;

  if (!OpenProcessToken(GetCurrentProcess(),
      TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
    hb_retl( FALSE );
    
  LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,
     &tkp.Privileges[0].Luid);
     
  tkp.PrivilegeCount = 1;
  tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  
  AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,
     (PTOKEN_PRIVILEGES)NULL, 0);
  
  if (GetLastError() != ERROR_SUCCESS)
     hb_retl( FALSE );
     
  if (!ExitWindowsEx( 8, 0 ))
     hb_retl( FALSE );  
  
}

#pragma ENDDUMP

 

Link to comment
Share on other sites

	 
	#Include "FiveWin.ch"

Function ShutDown_Main()

   IF .NOT. MsgYesNo( "LogOff Windows?", "ShutDown Windows" )

      RETURN NIL

   ENDIF
                                                                   
   WINEXEC( "SHUTDOWN /L" )

Return Nil

// Fim
  

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...