tjguk / wmi

102 stars 29 forks source link

Bug in "Schedule a job" example #9

Open quentinhardy opened 4 years ago

quentinhardy commented 4 years ago

Hello,

Thank you for this project.

When I test your following example, I have an error:

import os
import wmi
from datetime import datetime, timedelta

c = wmi.WMI()
one_minutes_time = datetime.now() + timedelta(minutes=1)
job_id, result = c.Win32_ScheduledJob.Create(
    Command=r"cmd.exe /c dir /b c:\ > c:\\temp.txt",
    StartTime=wmi.from_time(one_minutes_time)
)
print(job_id)

Error:

wmi.x_wmi: <x_wmi: Unexpected COM Error (-2147352567, 'Exception occurred.', (0, 'SWbemProperty', 'Type mismatch ', None, 0, -2147217403), None)>

The error comes from _one_minutestime value. The value returned by _fromtime() is invalid. I have developed another function instead of _fromtime() for getting the valid UTC time (e.g. "****123000.000000-420") but the value returned (_jobid) is None and the system command is not executed on the host.

This example is here https://github.com/tjguk/wmi/blob/9d2fefc052859a171b049ae7b39d0691bf80e9e2/docs/_build/_sources/cookbook.txt or here http://timgolden.me.uk/python/wmi/cookbook.html

Thank you in advance for your help,