Solved

Wake Computer from standby

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now