Solved

Wake Computer from standby

Posted on 2004-04-14
4
2,489 Views
Last Modified: 2013-12-03
I want to add programmatically a new task to the task scheduler, which has the option wake computer enabled. I already know how to add a task to the scheduler but I'm not able to eneable the option wake computer. Does anyone how I can do this? Please give me an examlpe in any of the folleowing languages: C++, C#, Delphi, VB, VBScript, Batch-file

Alternatively, I could also live with some other code which wakes the computer at a certain time from standby (using other timers).

0
Comment
Question by:maverick65
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 3

Expert Comment

by:MikProg
ID: 10840931
The only reason to add task to task sheduler is that: User want manage tasks shedule only by task sheduler. When I try to solve same problem the choice was Waitable Timers. Task sheduler REQUIRES user MUST have logon password. But I want shedule tasks send computer to sleep or suspend mode without logging off. AND I NEVER USE PASSWORD on my computer.
The choice Waitable Timers (see Windows API help ). Now I'm on distance from my source codes. But if you interested notice me about and I send you source example.
0
 
LVL 4

Author Comment

by:maverick65
ID: 10841535
I think that you are on the right way. I already have the example from MSDN, but further source code would be helpful.
0
 
LVL 3

Expert Comment

by:MikProg
ID: 10841573
Wait awhile. I will be back monday. If I'll be late I loose my points :(
0
 
LVL 3

Accepted Solution

by:
MikProg earned 500 total points
ID: 10856677
Here it is. It is part of project that never ends so source is not clean. The main Idea is covered by 2 proc's TimerAPCProc and Execute. As you can see main program must create one thread per waitable event, althought another approach is to use WaitForSingle/MultipleObjects.

unit iuStartAlerter;

interface

uses
  Classes {$IFDEF MSWINDOWS} , Windows {$ENDIF};

type
  AlertThread = class(TThread)
  private
    FAwakeningAt: TSystemTime;
    Fth: Thandle;
    FSheduleObject: pointer;
    procedure SetName;
    procedure SetAwakeningAt(const Value: TSystemTime);
    procedure SetSheduleObject(const Value: pointer);
  protected
    procedure Execute; override;
  public
    property th: Thandle read Fth;
    property AwakeningAt: TSystemTime read FAwakeningAt write SetAwakeningAt;
    property SheduleObject: pointer read FSheduleObject write SetSheduleObject;
    procedure MakeAction;
  end;

implementation

uses
  iuStartForm, SysUtils;

{$IFDEF MSWINDOWS}
type
  TThreadNameInfo = record
    FType: LongWord;     // must be 0x1000
    FName: PChar;        // pointer to name (in user address space)
    FThreadID: LongWord; // thread ID (-1 indicates caller thread)
    FFlags: LongWord;    // reserved for future use, must be zero
  end;
{$ENDIF}

{ AlertThread }

procedure TimerAPCProc(Subj: pointer;
  dwTimerLowValue: DWORD; dwTimerHighValue: DWORD); stdcall
begin
  with AlertThread(Subj) do
    Synchronize(MakeAction);
end;

procedure AlertThread.SetName;
{$IFDEF MSWINDOWS}
var
  ThreadNameInfo: TThreadNameInfo;
{$ENDIF}
begin
{$IFDEF MSWINDOWS}
  ThreadNameInfo.FType := $1000;
  ThreadNameInfo.FName := 'iuStartAlerter';
  ThreadNameInfo.FThreadID := $FFFFFFFF;
  ThreadNameInfo.FFlags := 0;

  try
    RaiseException( $406D1388, 0, sizeof(ThreadNameInfo) div sizeof(LongWord), @ThreadNameInfo );
  except
  end;
{$ENDIF}
end;

procedure AlertThread.SetSheduleObject(const Value: pointer);
begin
  FSheduleObject := Value;
end;

procedure AlertThread.MakeAction;
begin
  Form1.Startiu();
end;

procedure AlertThread.SetAwakeningAt(const Value: TSystemTime);
begin
  FAwakeningAt := Value;
end;

procedure AlertThread.Execute;
var
  ft, ft1: TFileTime;
  st: TSystemTime;
  c: Int64;
begin
  SetName;
  th:=CreateWaitableTimer(nil,True,'Local\iuStartAlerter');
  SystemTimeToFileTime(FAwakeningAt,ft);
  DateTimeToSystemTime(now,st);
  SystemTimeToFileTime(st,ft1);
  c:=Int64(ft1)-Int64(ft);
  if SetWaitableTimer(th,c,0,@timerAPCProc,Self,True) then
    while not Terminated do
      SleepEx(1000,True);
  CloseHandle(th);
  while not Terminated do
    SleepEx(1000,True);
end;

end.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question