7 Replies - 13202 Views - Last Post: 01 March 2010 - 12:55 PM Rate Topic: -----

#1 conanim  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-September 08

Wake Up Computer With VB.NET

Posted 29 September 2008 - 12:08 PM

Hi,
I am creating a program which I will use as a kind of alarm clock. I can put the computer to sleep(using the C4F Powermanager) but don't know how to wake it up again. Here is my code at the moment:

			
If ListBox2.SelectedItem = "Stand By" Then
				PowerManager1.StandbyComputer(True, False)
			ElseIf ListBox2.SelectedItem = "Hibernate" Then
				PowerManager1.HibernateComputer(False)
			ElseIf ListBox2.SelectedItem = "Lock Computer" Then
				PowerManager1.LockWorkStation()
			Else

			End If


The user chooses with a listbox what to happen when the event is triggered (touchscreen). Now all I need to do is get the computer to wake up again..
Any Ideas? :?:

Is This A Good Question/Topic? 0
  • +

#3 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Wake Up Computer With VB.NET

Posted 29 September 2008 - 01:41 PM

In order to do this you're going to have to use Pinvoke for Win32 API calls. The API's you need to call are CreateWaitableTimer and SetWaitableTimer.

Below is an example of ow you can set a system to be awoken from sleep/hibernate using the API's I mentioned above. Here I'm setting a relative wakeup time of 300000000 (30 seconds). That means that the computer will wake-up within 30 seconds after setting the timer. First you need the following Namespaces

Imports System
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Threading



The Win32 API's you need are

<DllImport("kernel32.dll")> _
Public Function CreateWaitableTimer(ByVal lpTimerAttributes As IntPtr, ByVal bManualReset As Boolean, ByVal lpTimerName As String) As IntPtr
End Function

<DllImport("kernel32.dll")> _
Public Function SetWaitableTimer(ByVal hTimer As IntPtr, _
 <[In]()> ByRef pDueTime As Long, ByVal lPeriod As Integer, _
 ByVal pfnCompletionRoutine As IntPtr, ByVal lpArgToCompletionRoutine As IntPtr, _
 ByVal fResume As Boolean) As Boolean
End Function

Public Declare Auto Function WaitForSingleObject Lib "kernel32" (ByVal handle As IntPtr, ByVal milliseconds As UInteger) As Int32



Then I create a procedure called SetWakeUpTime (Note: this I created in a console application)

Private Sub SetWaitForWakeUpTime()
    ' negative value, so a  RELATIVE due time
    Dim duetime As Long = -300000000

    handle = CreateWaitableTimer(IntPtr.Zero, True, SetWaitableTimer(handle, duetime, 0, IntPtr.Zero, IntPtr.Zero, True))

    Console.WriteLine("{0:x}", duetime)
    handle = CreateWaitableTimer(IntPtr.Zero, True, SetWaitableTimer(handle, duetime, 0, IntPtr.Zero, IntPtr.Zero, True))
    Dim INFINITE As UInteger = 4294967295
    Dim ret As Integer = WaitForSingleObject(handle, INFINITE)
    MessageBox.Show("Wake up call")
End Sub


Was This Post Helpful? 1

#4 conanim  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 29-September 08

Re: Wake Up Computer With VB.NET

Posted 01 October 2008 - 08:01 AM

Thanks for the really informative reply :)

Im a bit lost here, I already have a system to trigger the wake up of the computer; so the timer thing is not neccessary. What would I need to just wake the computer up?
Was This Post Helpful? 0
  • +
  • -

#5 JKLMUK  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-December 08

Re: Wake Up Computer With VB.NET

Posted 18 December 2008 - 12:53 PM

Hi would it be possible to get a working project file? I have tried following what you have put in the post. when i run it all i get is errors.

thanks
jas :)
Was This Post Helpful? 0
  • +
  • -

#6 Guest_Conor*


Reputation:

Re: Wake Up Computer With VB.NET

Posted 28 February 2010 - 09:37 AM

Thats is a good idea, i have retried using the code but i get errors too.
:bigsmile:
Was This Post Helpful? 0

#7 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: Wake Up Computer With VB.NET

Posted 01 March 2010 - 10:31 AM

Well what errors...you cant say you've got errors and suddenly we will know what they are...
Was This Post Helpful? 0
  • +
  • -

#8 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: Wake Up Computer With VB.NET

Posted 01 March 2010 - 12:32 PM

View PostAsscotte, on 01 March 2010 - 11:31 AM, said:

Well what errors...you cant say you've got errors and suddenly we will know what they are...


Dude, you didnt get the SpidySense update?
Was This Post Helpful? 1
  • +
  • -

#9 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: Wake Up Computer With VB.NET

Posted 01 March 2010 - 12:55 PM

Sorry I think I missed it I will go have a look now B) .
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1