Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Preventing from shutting down 2

Status
Not open for further replies.

TechnicalChris

IS-IT--Management
Mar 18, 2003
8
0
0
NZ
Hi,
is it possible to detect if windows is shutting down or user is logging off the system, and if so, is there any API to cancel out the shutdown api from excuting?

we are tring to prevent our users from shutting down the computer without logging out of there applications first.

any idea's anyone?

Thanks
Chris.
 

Not sure if it works under all conditions but in the Form_QueryUnload event try adding
If UnloadMode = 2 Then Cancel = 1

Or maybe you could force the user log off to occur instead of cancelling ?


Hope this helps.

 
Thanks for the reply,

I would say that would work but unfortunity, this isn't a custom made application.

we do have time limits before a user automatically gets logged off in our application, but at the end of the day they forget to go through the correct log off procedure, and rather shut the machine down and cause us problems.
 
im not quite sure i follow, the program you want your users to log out of, is that a program you have wrote or one you have bought??

you can catch the shutdown message in the queryunload event of the form using either one of the unloadmode constants

vbAppWindows(2) The current Microsoft Windows operating environment session is ending.
vbAppTaskManager(3) The Microsoft Windows Task Manager is closing the application.

at which point you can autologout the user,


or (and im not sure about this) you might be able to use the abortsystemshutdown API (but im not sure if this does catch the actual windows message)

Code:
Private Declare Function AbortSystemShutdown Lib "advapi32.dll" _
    Alias "AbortSystemShutdownA" ( _
        ByVal lpMachineName As String _
) As Long

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    
    If UnloadMode = vbAppWindows And UserLoggedIn Then
        'call logout procedure or optionally
        'AbortSystemShutdown (if possibe)
        
    End If
    
End Sub

good luck!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
Thanks ADoozer, unfortunity that api call only hooks into the registry shutdown process of the machine and doesnt see any other under layer shutdown calls. if it did your solution would have been perfect.

The program we want the users to log out of is a bought product which uses a telnet session, if they dont use the log off command when they have finished it leaves sessions open and creates problems for us.

apparently there's an registry entry or policy? for win2k which can prevent windows from shutting down if a specific application is still loaded. anybody know anything about this?

Thanks for your help
 
For the OS stuff you might try the Win2K forum


________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Some good tools, heres an updated link .
some good additonal features from the NT resource kit, but none are any value to my shutdown suitation unfortunity.

if WinNT had a log off script procedure like 2K, i would probably be out of the woods by now, although i have seen a website that described once how to debug the NT shutdown and add a script in, pitty i didnt book mark it.
 
You could do it by subclassing the window that you don't want to close, and then intercept the relevant WM_SYSCOMMAND
 
That is true, the WM_SYSCOMMAND should detect a WM_QUERYENDSESSION and if that value = true then maybe i can sendmessage to ExitWindows API to cancel.

i guess the answer somewhere between these lines, i may have to do some more research on it, unless someone already knows how to capture the WM_SYSCOMMAND to a specific window handle.

Thanks Strongm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top