Logoff windows session from VBA

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
 
Joined
Jun 6, 2014
Messages
11
Reaction score
0
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. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top