Results 1 to 7 of 7

Thread: [2005] Shutdown Help Needed!

  1. #1

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    [2005] Shutdown Help Needed!

    I need to change the shudown on my computer so that when the shutdown button is clicked it stops the shutdown, runs my application and then shuts down the computer when my application has finished.

    I've been thinking about having an application running all the time in the background and then cataching the shutdown command and stopping it, then running my application and then shutting down.

    Does anyone have any code that can help with this please?

    Thanks in advance.
    ------
    KNXRB
    Last edited by knxrb; Nov 3rd, 2007 at 07:03 AM.

  2. #2
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: [2005] Shutdown Help Needed!

    You can do this by two method. One is in the Form1_FormClosing and check for the
    Code:
    e.CloseReason=CloseReason.WindowsShutDown
    and to the job there.

    Another method you can use the system events to detect the shutdown
    Code:
    'Add two command buttons
    Imports Microsoft.Win32
    Imports System.EventArgs
    Imports System
    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            AddHandler SystemEvents.SessionEnding, AddressOf ShutDownDetect
        End Sub
        Public Sub ShutDownDetect(ByVal sender As Object, ByVal e As EventArgs)
            'Detect Shutdown and Do your job her
            Me.Text = "Shutdown in Progress"
            'Do your stuff here
        End Sub
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            RemoveHandler SystemEvents.TimeChanged, AddressOf ShutDownDetect
        End Sub
    Hope this helps.
    Please mark you thread resolved using the Thread Tools as shown

  3. #3

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: [2005] Shutdown Help Needed!

    thanks. will try it later!

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Shutdown Help Needed!

    Why does your app need to be run before the shutdown?

    The Systemevents is your best bet since you state your app isnt running at the time.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: [2005] Shutdown Help Needed!

    It will be a backup thing copying changed files from one path to another. This needs to run before it shuts down so that I don't lose any of the data I have changed since logging in.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: [2005] Shutdown Help Needed!

    Well then try just coding in the save stuff to be called from the Closing event since it really doesnt matter what the reason is, just need to save it upon closing.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Hyperactive Member knxrb's Avatar
    Join Date
    Jul 2007
    Location
    United Kingdom
    Posts
    321

    Re: [2005] Shutdown Help Needed!

    I can't do that as the computer will just shutdown the backing up process and turn off. I can't start another thing as it shuts down.

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