Announcement

Collapse
No announcement yet.

Detecting PC Standby in VB.net

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Detecting PC Standby in VB.net

    I have written my own fron-end for my car PC project.

    I have a settings.ini file which hold various variables that I need in my project.....winamp path, mp3 path, last played track, last used function.......etc.

    I have a sub called writeSettings() which as you would expect writes this file for me. I call this sub whenever I select an item in my main menu or after a certain media file is opened, so the front-end remembers what I was last doing when it is loaded again.

    When my shutdown controller tells the computer to shutdown, can I get VB.net to 'see' this and quickly write the settings.ini file, so if the power is completely removed it will know where it last was?

    A simpler way would be to keep writing the settings.ini file every 2 or 3 seconds, but would this knacker my hard disk eventually?

    Thanks for any help
    ViVE - Volkswagen In Van Entertainment:

    VoomPC 2, VIA C7 2GHz
    7" Lilliput
    120Gb Sata drive
    1GB RAM


    [||||||||||] 100% - Planning
    [||||||||||] 100% - Software coding
    [||||||||||] 100% - Built

    (Always tweaking!)

  • #2
    Just a thought, how about you write it only when it's modified?

    Comment


    • #3
      Originally posted by Dgege View Post
      Just a thought, how about you write it only when it's modified?

      thats what i did in my front end. every time you change something then it writes the changes

      Comment


      • #4
        Thanks for the replies, but the current track position is constantly changing!

        I want to be able to have the computer go into standby mode when the ignition is switched off. When the ignition is switched back on within the shutdown time the front-end will load back to where it was before. If the shutdown time expires, the power is completely lost and when the computer boots up the next time, it will load the settings.ini file. This file may have last been written 5 minutes before the time the computer shut down last, therefore the system will not be in the same place that it was last in.....If you get what I mean.


        I supose I could write the file every 3 or 4 seconds, therefore if the computer goes into standby mode and then shuts off, it will only be a maximum of 4 seconds behind the track position of when it was last playing.
        ViVE - Volkswagen In Van Entertainment:

        VoomPC 2, VIA C7 2GHz
        7" Lilliput
        120Gb Sata drive
        1GB RAM


        [||||||||||] 100% - Planning
        [||||||||||] 100% - Software coding
        [||||||||||] 100% - Built

        (Always tweaking!)

        Comment


        • #5
          Ok i see what you mean now. I did not know you wanted to save the track pos. I have tried this on mine but could not figure it out so it just starts the track from the begining on reboot. If you figure something out let me know cuz this would be usefull for me but its not that important to me so I not going to waste my time with it.

          Comment


          • #6
            As I said in my original post, if there was some way of finding out when Windows is going into standby mode, the settings.ini file could be quickly written then. It takes milliseconds to write the file.

            There must be something, but I can't seem to find it on the net. I'll keep looking and trying and post any results here
            ViVE - Volkswagen In Van Entertainment:

            VoomPC 2, VIA C7 2GHz
            7" Lilliput
            120Gb Sata drive
            1GB RAM


            [||||||||||] 100% - Planning
            [||||||||||] 100% - Software coding
            [||||||||||] 100% - Built

            (Always tweaking!)

            Comment


            • #8
              This should work, I retyped the code since I have it on a different PC so I haven't compiled this to make sure it's all correct but I think it is...

              <CODE>
              Imports Microsoft.Win32

              Public Class Main Form

              Private Sub MainForm_Load(ByVal sender as System.Object, ByVal e as System.EventArgs) Handles MyBase.Load
              AddHandler SystemEvents.PowerModeChanged, AddressOf MyPMC
              End Sub

              Private Sub MyPMC(ByVal sender as Object, ByVal e as PowerModeChangedEventArgs)
              If e.Mode = PowerModes.Suspend
              'Whatever you want to happen when it goes in standby/hibernate goes here
              End If
              If e.Mode = PowerModes.Resume
              'If you want something to happen when it wakes back up, put it here
              End If
              End Sub

              End Class
              </CODE>

              Comment


              • #9
                Thanks for all of the responses to my post.

                This is what I am using....

                ------------------------------------------------------------------------
                Private Const WM_POWERBROADCAST As System.Int32 = &H218
                Private Const PBT_APMSUSPEND As System.Int32 = 4


                Protected Overrides Sub WndProc(ByRef m As Message)
                Select Case m.Msg
                Case Is = WM_POWERBROADCAST
                Select Case m.WParam.ToInt32
                Case Is = PBT_APMSUSPEND
                WriteSettings()
                Case Else
                ' When it isn't in suspend mode
                End Select
                End Select
                MyBase.WndProc(m)
                End Sub
                ------------------------------------------------------------------------

                Thanks Enforcer.


                I played around with RickS code, but I couldn't get it to work on my machine.

                Cheers
                ViVE - Volkswagen In Van Entertainment:

                VoomPC 2, VIA C7 2GHz
                7" Lilliput
                120Gb Sata drive
                1GB RAM


                [||||||||||] 100% - Planning
                [||||||||||] 100% - Software coding
                [||||||||||] 100% - Built

                (Always tweaking!)

                Comment


                • #11
                  Here's a project (in .NET 2) that does it if you want...
                  Attached Files

                  Comment


                  • #12
                    Thanks,

                    Thank works fine

                    ViVE - Volkswagen In Van Entertainment:

                    VoomPC 2, VIA C7 2GHz
                    7" Lilliput
                    120Gb Sata drive
                    1GB RAM


                    [||||||||||] 100% - Planning
                    [||||||||||] 100% - Software coding
                    [||||||||||] 100% - Built

                    (Always tweaking!)

                    Comment

                    Working...
                    X