Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Detecting PC Standby in VB.net

  1. #1
    Constant Bitrate
    Join Date
    Sep 2006
    Location
    Cornwall, England
    Posts
    161

    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

  2. #2
    Low Bitrate
    Join Date
    Jul 2007
    Posts
    59
    Just a thought, how about you write it only when it's modified?

  3. #3
    Newbie alienmanfc6's Avatar
    Join Date
    Sep 2007
    Location
    Ashton
    Posts
    26
    Quote 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

  4. #4
    Constant Bitrate
    Join Date
    Sep 2006
    Location
    Cornwall, England
    Posts
    161
    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.

  5. #5
    Newbie alienmanfc6's Avatar
    Join Date
    Sep 2007
    Location
    Ashton
    Posts
    26
    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.

  6. #6
    Constant Bitrate
    Join Date
    Sep 2006
    Location
    Cornwall, England
    Posts
    161
    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

  7. #7

  8. #8
    Low Bitrate RickS's Avatar
    Join Date
    Nov 2005
    Location
    Bethesda, MD
    Posts
    86
    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>

  9. #9
    Constant Bitrate
    Join Date
    Sep 2006
    Location
    Cornwall, England
    Posts
    161
    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

  10. #10

Page 1 of 2 12 LastLast

Similar Threads

  1. 1998 Cadillac Deville Concours Install COMPLETE!!!
    By quantum in forum Show off your project
    Replies: 27
    Last Post: 03-20-2010, 11:28 PM
  2. Occasionally not resuming from Standby...
    By EBJUSTIN in forum General Hardware Discussion
    Replies: 3
    Last Post: 10-28-2004, 04:12 PM
  3. In progress car PC install.
    By Arathranar in forum Fabrication
    Replies: 1
    Last Post: 10-20-2004, 01:49 AM

Bookmarks

Posting Permissions

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