Logoff windows session from VBA

  • Thread starter Thread starter AlexT
  • Start date Start date
A

AlexT

Folks

I'm trying to logoff the current Windows session from VBA.

I have looked into MSDN and came up with the following code

-----------------------------------------------------------------------

Private Const EWX_LogOff As Long = 0


Private Declare Function ExitWindowsEx Lib "user32" _
(ByVal dwOptions As Long, _
ByVal dwReserved As Long) As Long

Private Declare Function GetLastError Lib "kernel32" () As Long

Public Sub DOLogoff()

ExitWindowsEx (EWX_LogOff), &HFFFF
MsgBox "ExitWindowsEx's GetLastError " & GetLastError

End Sub

-----------------------------------------------------------------------

For some reason calling DOLogoff doesn't work, although
ExitWindowsEx returns 0 (no error ?)

Any idea ?

Regards

--alexT
 
May be, you can try with Force Logoff Function. From VBA while calling these API functions, add a force flag to Logoff or shutdown that will force close any application waiting for Use Input or Confirmation.
But, use this option carefully, because there are chances that you might loss some unsaved data.

Hope this helps. :)
 
Back
Top