The basic problem is that the handle returned from GetPage is not an MFC
object, and win32ui is expecting an MFC property sheet page, not a raw
handle.
I played around with this a while back, and managed to display the property
page
by sending the window message PSM_ADDPAGE to a PyCPropertySheet.
However, you can't use SendMessage until you've called CreateWindow for the
property sheet, and you can't call CreateWindow until you've added a
property
page. (catch-22!) I got around this by adding a dummy page to the property
sheet,
calling CreateWindow & SendMessage to add the task page, and then removing
the stand-in. But since the task page isn't MFC, after I did that any
attempt to call methods on the property sheet caused an access violation.
Roger
import win32api,win32con, win32ui, pythoncom
import traceback, os
from win32com.taskscheduler import taskscheduler
PSM_ADDPAGE = win32con.WM_USER + 103
PSM_REMOVEPAGE = win32con.WM_USER + 102
task_name='test_addtask_4.job'
ts=pythoncom.CoCreateInstance(taskscheduler.CLSID_ CTaskScheduler,None,
pythoncom.CLSCTX_INPROC_SERVER,taskscheduler.IID_I TaskScheduler)
t=ts.Activate(task_name)
iptp=t.QueryInterface(taskscheduler.IID_IProvideTa skPage)
tp=iptp.GetPage(taskscheduler.TASKPAGE_TASK,False)
fname=os.path.join(os.environ['SYSTEMROOT'],'system32','mstask.dll')
dll=win32ui.LoadLibrary(fname)
try:
dll.AttachToMFC()
except:
traceback.print_exc()
ps=win32ui.CreatePropertySheet('eh ?????')
## property sheet won't let you CreateWindow unless there's already a
property page attached,
## and you can't do a SendMessage until you've created a window !!!!
pptask=win32ui.CreatePropertyPage(401) ## 401 is the task page template from
mstask.dll, identified using EnumResources
ps.AddPage(pptask)
ps.CreateWindow()
ps.SendMessage(PSM_ADDPAGE,0,tp)
## get rid of the dummy
ps.RemovePage(0)
"Fadly Tabrani" <no@spam.net> wrote in message
news:ck**********@mawar.singnet.com.sg...
Hi guys,
This is the first time I'm posting to the newsgroup, hope you can help
out.
I'm writing a module to interface with the task scheduler in windows
using PyWin32. Everything has been great so far but I'm stuck on
displaying the propertys page of a task. Here's the code:
import pythoncom
import win32api
from win32com.taskscheduler import taskscheduler
import win32ui
task_scheduler = pythoncom.CoCreateInstance\
(taskscheduler.CLSID_CTaskScheduler,
None, pythoncom.CLSCTX_INPROC_SERVER,
taskscheduler.IID_ITaskScheduler)
def show_schedule_page(task_name):
TASKPAGE_TASK = 0,
TASKPAGE_SCHEDULE = 1,
TASKPAGE_SETTINGS = 2
try:
task = task_scheduler.Activate(task_name)
except pythoncom.com_error, e:
print 'Task name not found...'
return
# ** This returns a PyHandle
handle =
task.QueryInterface(taskscheduler.IID_IProvideTask Page).\ GetPage(1, True)
# ** Can't create a window with it using win32ui, returns error
try:
win32ui.CreateWindowFromHandle(handle)
except win32ui.error, e:
print e
# ** Can't add it to a property sheet, return an error
property_sheet = win32ui.CreatePropertySheet('Task Schedule')
try:
property_sheet.AddPage(handle)
except (win32ui.error, TypeError), e:
print e
show_schedule_page('task1')
Any ideas on how to do it? The task schduler api reference is at
http://msdn.microsoft.com/library/de...start_page.asp
I'm pretty new at this, is there anything that I've missed out?
Cheers,
Fadly Tabrani
python loves me loves python