Logoff on exit

Logoff on exit

Postby modicr » Thu Feb 10, 2011 9:27 am

Hello!

I want to log off when the user exits FiveWin application.
Does anyone know how to do it?

Thanks,
Roman
© I'm not patented!
User avatar
modicr
 
Posts: 207
Joined: Fri Oct 07, 2005 7:58 am
Location: ljubljana, barje, slovenia

Re: Logoff on exit

Postby Enrico Maria Giordano » Thu Feb 10, 2011 10:28 am

Try this sample:

Code: Select all  Expand view
#define EWX_LOGOFF   0
#define EWX_SHUTDOWN 1
#define EWX_REBOOT   2
#define EWX_FORCE    4
#define EWX_POWEROFF 8


FUNCTION LOGOFF()

    ENABLEPERMISSIONS()

    EXITWINDOWSEX( EWX_LOGOFF, 0 )

    RETURN NIL


#pragma BEGINDUMP

#include "WinTen.h"
#include "Windows.h"
#include "HbApi.h"
#include "ClipApi.h"


HB_FUNC( ENABLEPERMISSIONS )

{
   LUID tmpLuid;
   TOKEN_PRIVILEGES tkp, tkpNewButIgnored;
   DWORD lBufferNeeded;
   HANDLE hdlTokenHandle;
   HANDLE hdlProcessHandle = GetCurrentProcess();

   OpenProcessToken( hdlProcessHandle, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hdlTokenHandle );

   LookupPrivilegeValue( NULL, "SeShutdownPrivilege", &tmpLuid );

   tkp.PrivilegeCount           = 1;
   tkp.Privileges[0].Luid       = tmpLuid;
   tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

   AdjustTokenPrivileges( hdlTokenHandle, FALSE, &tkp, sizeof( tkpNewButIgnored ), &tkpNewButIgnored, &lBufferNeeded );
}


HB_FUNC( EXITWINDOWSEX )

{
   hb_retl( ExitWindowsEx( ( UINT ) hb_parni( 1 ), ( DWORD ) hb_parnl( 2 ) ) );
}

#pragma ENDDUMP


EMG
User avatar
Enrico Maria Giordano
 
Posts: 8356
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Logoff on exit

Postby ukoenig » Thu Feb 10, 2011 10:42 am

Maybe You want to use a DLL-Function :

DLL32 FUNCTION ExitWindow;
( dwReserved AS LONG, ;
uReturnCode AS LONG ) ;
AS LONG PASCAL;
FROM "ExitWindows" LIB "USER32"

and

DLL32 FUNCTION ExitWindEx;
( uFlags AS LONG, ;
dwReserved AS LONG ) ;
AS LONG PASCAL;
FROM "ExitWindowsEx" LIB "USER32"

// uFlags-defines :
#define EWX_LOGOFF 0
#define EWX_SHUTDOWN 1
#define EWX_REBOOT 2
#define EWX_POWEROFF 8
#define EWX_RESTARTAPPS 40
// plus AT MOST ONE of the following two:
#define EWX_FORCE 4
#define EWX_FORCEIFHUNG 10

Value Meaning :

EWX_LOGOFF
0
Shuts down all processes running in the logon session of the process that called the ExitWindowsEx function. Then it logs the user off.

This flag can be used only by processes running in an interactive user's logon session.

EWX_POWEROFF 8
Shuts down the system and turns off the power. The system must support the power-off feature.

The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.

EWX_REBOOT 2
Shuts down the system and then restarts the system.

The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.

EWX_RESTARTAPPS 40
Shuts down the system and then restarts it, as well as any applications that have been registered for restart using the RegisterApplicationRestart function. These application receive the WM_QUERYENDSESSION message with lParam set to the ENDSESSION_CLOSEAPP value. For more information, see Guidelines for Applications.

EWX_SHUTDOWN 1
Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped.

The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section.

Specifying this flag will not turn off the power even if the system supports the power-off feature. You must specify EWX_POWEROFF to do this.

Windows XP with SP1: If the system supports the power-off feature, specifying this flag turns off the power.

This parameter can optionally include one of the following values.

Value Meaning
EWX_FORCE 4
This flag has no effect if terminal services is enabled. Otherwise, the system does not send the WM_QUERYENDSESSION message. This can cause applications to lose data. Therefore, you should only use this flag in an emergency.

EWX_FORCEIFHUNG 10
Forces processes to terminate if they do not respond to the WM_QUERYENDSESSION or WM_ENDSESSION message within the timeout interval.

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Logoff on exit

Postby modicr » Sat Feb 26, 2011 1:54 pm

Hello!

Thanks, it seems to be working OK. :D
The reason to use logoff on exit from our application is
RemoteApp feature of Windows 2008 server:
http://blogs.msdn.com/b/rds/archive/200 ... logic.aspx

BTW, the services have been renamed in 2008 R2:
http://blog.ronnypot.nl/?p=193
EDIT: http://msdn.microsoft.com/en-us/library/dd979766(v=vs.85).aspx

Regards, Roman
© I'm not patented!
User avatar
modicr
 
Posts: 207
Joined: Fri Oct 07, 2005 7:58 am
Location: ljubljana, barje, slovenia


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 32 guests