CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: How to prevent windows for shutdown/reboot/logoff?

  1. #1
    Join Date
    Dec 2010

    Question How to prevent windows for shutdown/reboot/logoff?

    Hi, i'm in project to make i-cafe software (i use microsoft access 2003). Any one can help me how to prevent user to shutdown the computer while my application still running even in windows vista/7? I can do that in windows xp without any problem. Here my code:

    Option Explicit
    Option Compare Database
    Dim exittes As Boolean, cekexit As Boolean

    Private Sub Form_Load()
    exittes = False
    cekexit = False
    End Sub

    Private Sub Form_Timer()
    Dim WsShell
    Set WsShell = CreateObject("WScript.Shell")
    If (Kosong(txt)) And (Kosong(GetFileName(GetHwndEXE(GetForegroundWindow())))) Then
    WsShell.SendKeys "{ESC}"
    End If
    If cekexit = True Then
    WsShell.SendKeys "{ESC}"
    cekexit = False
    End If
    End Sub

    Private Sub Form_Unload(Cancel As Integer)
    cekexit = True
    If exittes = False Then
    Cancel = 1
    End If
    End Sub

    The code in Form_Timer event i use for windows vista/7 to close the screen dialog for force close open application.

  2. #2
    Join Date
    Jan 2006
    Fox Lake, IL

    Re: How to prevent windows for shutdown/reboot/logoff?

    I wouldn't use a program that didn't let me control my own PC. Why prevent shutdown, if the user wants to. What happens if YOUR APP CRASHES?

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)