
VB Code to log current user off NT
Quote:
> Hello, is there a way to log the current user off NT with VB? I want to
> have a program run as a login script, then when the progam ends, i want
> the user's session to end. (i'm trying to do the equivilent of setting the
> user's shell to the progam in UNIX)
> Thank you,
> Doug Melniker
> ** Please cc response to me by email **
http://www.mvps.org/vbnet/
Search for
Visual Basic Undocumented Shell32 Routines
Windows by the Numbers, Overview
Extract:
Dialog Functions (sorted by ordinal)
The "System Settings Change" message box ("You must restart your
computer before the new settings will take effect.")
Declare Function SHRestartSystemMB Lib "shell32" Alias "#59" _
(ByVal hOwner As Long, _
ByVal sExtraPrompt As String, _
ByVal uFlags As Long) As Long
hOwner = Message box owner; specify 0& for the desktop (will be
top-level)
sPrompt = Specified prompt string placed above the default prompt. The
default string can not be defeated, but additional explanation can be
provided to the user.
uFlags = Based on the OS, can be the following values:
WinNT
Appears to use ExitWindowsEx uFlags values and behave accordingly:
Public Const EWX_LOGOFF = 0
Public Const EWX_SHUTDOWN = 1 NT: needs SE_SHUTDOWN_NAME privilege (no
default prompt)
Public Const EWX_REBOOT = 2 NT: needs SE_SHUTDOWN_NAME privilege
Public Const EWX_FORCE = 4
Public Const EWX_POWEROFF = 8 NT: needs SE_SHUTDOWN_NAME privilege
Win95
Any Yes selection produces the equivalent to ExitWindowsEx(EWX_FORCE,
0&) (?), i.e. no WM_QUERYENDSESSION or WM_ENDSESSION is sent! Other than
noted below,
it was found that any other value shuts the system down (no reboot) and
includes the default prompt.
Shuts the system down (no reboot) and does not include the default
prompt.
Public Const shrsExitNoDefPrompt = 1
Reboots the system and includes the default prompt.
Public Const shrsRebootSystem = 2 ' = EWX_REBOOT
Return values: Yes = 6 (vbYes), No = 7 (vbNo)
The "Shut Down" dialog (i.e. Start menu / Shut Down)
Declare Function SHShutDownDialog Lib "shell32" Alias "#60" _
(ByVal YourGuess As Long) As Long
I have a comment here - as the author of the code specifies, this is
undocumented and might change with the next windows release.