Solved

Wake Computer from standby

Posted on 2004-04-14
4
2,469 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
  • 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How Does Quick Books store date / time? 3 97
Create an excel spreadsheet that reads and inserts data 5 61
dialer.exe 4 60
Using MS Code on my Mac 6 67
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

785 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