Results 1 to 7 of 7

Thread: An Auto Shutdown

  1. #1

    Thread Starter
    Hyperactive Member parkes's Avatar
    Join Date
    Jan 1999
    Location
    Unitied Kingdom
    Posts
    303
    I want to write into my application a way to shut itself down (not the PC) if it hasn't been used for a set period of time, does anyone know how this can be done?
    Thanks in advance for any help provided.

    VB 6 Enterprise Edition SP4
    ADO, SQL 7/2000, ASP and some JavaScript


    >> Life goes on, but for how long? <<
    If you can smile when things go wrong, you have someone in mind to blame

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Code:
    'In declarations
    Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
    Enum exitmode
        Shutdown = 0
        Restart = 1
        Suspend = 2
    End Enum
    'In code
    Sub ExitWindows(how As exitmode)
        Const EWX_LOGOFF = 0
        Const EWX_SHUTDOWN = 1
        Const EWX_REBOOT = 2
        Const EWX_FORCE = 4
        Select Case how
            Case 0
                t& = ExitWindowsEx(EWX_SHUTDOWN, 0)
            Case 1
                t& = ExitWindowsEx(EWX_REBOOT Or EXW_FORCE, 0)
            Case 2
                SetSystemPowerState 1, 1
         End Select
     End Sub
    Well here's for the shut down part, but for checking any activity, i guess mouse movement is enough? You could use Getcursorpos and check if it has changed...
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3

    Thread Starter
    Hyperactive Member parkes's Avatar
    Join Date
    Jan 1999
    Location
    Unitied Kingdom
    Posts
    303
    Thanks but I've got that one and it shuts down the PC, which is not what I want. I just want to close my application.
    Thanks in advance for any help provided.

    VB 6 Enterprise Edition SP4
    ADO, SQL 7/2000, ASP and some JavaScript


    >> Life goes on, but for how long? <<
    If you can smile when things go wrong, you have someone in mind to blame

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Smile

    Here is a simple solution and the program will automatically terminal after 1hour:
    Code:
    Option Explicit
    Private tCnt As Long
    Private xForm As Form
    Private Sub Form_Load()
    Timer1.Interval = 60000
    Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
    
    If tCnt > 60 Then
        For Each xForm In Forms
            Unload Me
        Next
        End
    Else
        tCnt = tCnt + 1
    End If
    End Sub

  5. #5

    Thread Starter
    Hyperactive Member parkes's Avatar
    Join Date
    Jan 1999
    Location
    Unitied Kingdom
    Posts
    303
    Right, but won't this shut down even if someone is still using it. Is there not a way to check the last time the application was used????
    Thanks in advance for any help provided.

    VB 6 Enterprise Edition SP4
    ADO, SQL 7/2000, ASP and some JavaScript


    >> Life goes on, but for how long? <<
    If you can smile when things go wrong, you have someone in mind to blame

  6. #6
    Addicted Member
    Join Date
    Jul 1999
    Location
    St-Élie d'Orford, Quebec, Canada
    Posts
    133
    Hi, why don't you merge the two ideas together...

    Make tCnt a Global scope then you can check for mouse positions changes, keyboard input or even form loads to reset the count in tCnt. This will make the application shut down after 1 hour of stand still... You can also change the delay but you surely already knew this one :-)

  7. #7
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Smile

    Juz look like this

    Code:
    'Module file
    Option Explicit
    Global tCnt as Long
    Public RESET_COUNTER ()
        tCnt = 0
    End Sub
    
    'Form
    Option Explicit
    Private xForm As Form
    Private Sub Form_Load()
    Timer1.Interval = 60000
    Timer1.Enabled = True
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        RESET_COUNTER     
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        RESET_COUNTER
    End Sub
    
    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
        RESET_COUNTER
    End Sub
    
    Private Sub Timer1_Timer()
    
    If tCnt > 60 Then
        For Each xForm In Forms
            Unload Me
        Next
        End
    Else
        tCnt = tCnt + 1
    End If
    End Sub

Posting Permissions

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



Click Here to Expand Forum to Full Width