Solved

Task Scheduler

Posted on 2000-04-15
17
786 Views
Last Modified: 2013-12-03
Using Windows 98 (or 95) -

When a MS Windows software package (such as the SDK) is being installed - the Task Scheduler is "paused". When the installation is complete it is "unpaused".

The task scheduler icon resides in the system tray - right clicking on it gives two choice "Open" or "pause ..."

I have been searching MSDN for sometime and have come up with nothing on the subject - therefore I have come to the conclusion that the functions are undocumented.

Does anyone know how to pause and unpause the Task Scheduler ??

DarrinE
0
Comment
Question by:DarrinE
  • 7
  • 3
  • 3
  • +2
17 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 2720003
It is documented. See

Task Scheduler
http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/psdk/taskschd/ts_portal_690l.htm

TaskSched: Task Scheduler Sample
http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/devprods/vs6/visualc/vcsample/vcsmptasksched.htm

It is a service on Windows NT. So, you can pause and resume the service just like other services.

C/C++ Code Example: Starting Task Scheduler
http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/psdk/taskschd/ts_using_2182.htm
0
 
LVL 2

Author Comment

by:DarrinE
ID: 2720225
Chensu - I knew of the pages identified by you - I have read and reread them several times - what I am trying to do is "pause" the scheduler while my program runs

I am not trying to "play" with any of the tasks (or pause a specific task) - I am trying to pause the service so it does not run at all and can be unpaused when my program is ready for it to go

0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2722479
It seems it is undocumented.
I can find the info you want for 600 points+grade A.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 2

Author Comment

by:DarrinE
ID: 2724305
OK - 400 and a grade "A" - working example in C - sounds better - I'll have no points left but at least I'll have an answer <s>

DarrinE
0
 
LVL 3

Expert Comment

by:byang
ID: 2733199
Can I bid 399 points and a grade A for working code ?
0
 
LVL 3

Expert Comment

by:byang
ID: 2733212
And it's simple, nothing complicated.
0
 
LVL 15

Expert Comment

by:NickRepin
ID: 2733448
Sure, no problem.
0
 
LVL 2

Author Comment

by:DarrinE
ID: 2733812
OK - well how about this - first one in with the first working example gets the points -  now remember I work on win98/win95 and I work on in C - 400 points is what is available at the moment (sorry guys I dont have any more at the moment - it would also be nice if the sample works on NT but not absolute)

DarrinE
0
 
LVL 5

Accepted Solution

by:
robpitt earned 400 total points
ID: 2734692
Sorry for piping some of you folks at the post but I've done this one and could also do with the points.
This topici is looosly documented in MSDN, search for things like "SAGE" and "Task Scheduler".

Anyway heres some working code source code...

Enjoy...

-ROB


//TaskSchd.H
#define TASKSCHEDULER_GETSTATE     (0)
#define TASKSCHEDULER_ENABLE       (1)
#define TASKSCHEDULER_DISABLE      (2)

int WINAPI TaskSchedulerEnable(int newState);
//Call with one of the 3 settings above dependant upon
//whether you want to query the current state or change
//it to a new state. It returns the old state or 0 on error.





//TaskSchd.C
#include <windows.h>
#include "taskschd.h"

#define WM_TASKSCHEDULER_ENABLE     (WM_USER+6)
#define WM_TASKSCHEDULER_DISABLE    (WM_USER+7)
#define WM_TASKSCHEDULER_GETSTATUS  (WM_USER+8)

#define TASKSCHEDULER_WINDOWCLASS   ("SAGEWINDOWCLASS")
#define TASKSCHEDULER_WINDOW        ("SYSTEM AGENT COM WINDOW")

int WINAPI TaskSchedulerEnable(int newState)
{
    HWND hWnd;
    int state;
   
    hWnd=FindWindow(TASKSCHEDULER_WINDOWCLASS,TASKSCHEDULER_WINDOW);
    if (!hWnd) return 0;

    state=SendMessage(hWnd,WM_TASKSCHEDULER_GETSTATUS,0,0);
    if (state==TASKSCHEDULER_ENABLE)
    {
        if (newState==TASKSCHEDULER_DISABLE) SendMessage(hWnd,WM_TASKSCHEDULER_DISABLE,0,0);
        return state;
    }
    else if (state==TASKSCHEDULER_DISABLE)
    {
        if (newState==TASKSCHEDULER_ENABLE) SendMessage(hWnd,WM_TASKSCHEDULER_ENABLE,0,0);
        return state;
    }

    return 0;
}

0
 
LVL 5

Expert Comment

by:robpitt
ID: 2734715
Oh and for NT you could modify my wrapper to detect OS then call either the Win95 version (as above) or on NT do...
OpenService(hSC,"Schedule"), QueryServiceStatus() and  ControlService()

-ROB
0
 
LVL 3

Expert Comment

by:byang
ID: 2735982
robpitt is correct.
0
 
LVL 2

Author Comment

by:DarrinE
ID: 2736552
Adjusted points from 200 to 400
0
 
LVL 2

Author Comment

by:DarrinE
ID: 2736553
can you give me an example for use on NT ?
0
 
LVL 2

Author Comment

by:DarrinE
ID: 2736559
And a direction to where some documentation might be ?? - in the interim I'll try the answer (code) you've provided

DarrinE
0
 
LVL 5

Expert Comment

by:robpitt
ID: 2737348
Search MSDN for ... "sage.dll" task scheduler ... that will find an article entitled "Guidelines for Independent Software Vendors" which covers some of old Win9X stuff.

On NT the Task Scheduler (if loaded/installed) is just another service and so you pause/resume it via the service control functions (see MSDN). Below is *pseudo-code* showing how you could make my code handle NT as well...

-ROB

if (GetVersion()&0x80000000)//detect Win9X versus WinNT
{//Win9X
    ... code from previous post
}
else
{//WinNT
    hServControl = OpenSCManager(NULL,NULL,SC_MANAGER_CONNECT);
    hSchedule = OpenService(hServControl, "Schedule", SERVICE_QUERY_STATUS|SERVICE_PAUSE_CONTINUE);
    if (!hSchedule) return 0;// Schedule not running

    QueryServiceStatus(hSchedule, &serviceStatus);
    if (serviceStatus.dwCurrentState==SERVICE_PAUSED)
    {
      if (want_to_enable) ControlService(hSchedule, SERVICE_CONTROL_CONTINUE);
        return WAS PAUSED;
    }
    else if (serviceStatus.dwCurrentState==SERVICE_RUNNING)
    {
      if (want_to_disable) ControlService(hSchedule, SERVICE_CONTROL_PAUSE);
        return WAS ENABLED;
    }
    else
        return 0 - unknown state
}
0
 
LVL 2

Author Comment

by:DarrinE
ID: 2737350
Many thanks for the assistance - the points are yours - what for my queries I have another one coming up along these same lines
0
 
LVL 23

Expert Comment

by:chensu
ID: 2738137
>can you give me an example for use on NT ?

Did you have a look at the example I gave you with my very first comment?

"It is a service on Windows NT. So, you can pause and resume the service just like other services.

C/C++ Code Example: Starting Task Scheduler
http://msdn.microsoft.com/isapi/msdnlib.idc?theURL=/library/psdk/taskschd/ts_using_2182.htm"
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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 describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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.

685 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