Daniel Berger
2009-Jun-16 19:44 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
Hi, I''d like to add TaskScheduler#exists?(work_item) to the win32-taskscheduler library. Mostly I want it for testing, but it might come in handy for other people as well. What''s the best way to approach this? Just enumerate the tasks, and check for the name? Regards, Dan
Heesob Park
2009-Jun-17 01:46 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
Hi, 2009/6/17 Daniel Berger <djberg96 at gmail.com>:> Hi, > > I''d like to add TaskScheduler#exists?(work_item) to the win32-taskscheduler > library. Mostly I want it for testing, but it might come in handy for other > people as well. > > What''s the best way to approach this? Just enumerate the tasks, and check > for the name? >I think the best way to check taskscheduler item is just go to the Scheduled Tasks folder (in most case c:\winodws\tasks) and see the .job files. You can write it with ruby like this: def TaskScheduler#exists?(work_item) File.exist?("#{ENV[''windir'']}\\Tasks\\#{work_item}.job") end BTW, Do you mind I write pure ruby taskscheduler? Regards, Park Heesob
Daniel Berger
2009-Jun-17 03:15 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
> -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel- > bounces at rubyforge.org] On Behalf Of Heesob Park > Sent: Tuesday, June 16, 2009 7:47 PM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? > method > > Hi, > > 2009/6/17 Daniel Berger <djberg96 at gmail.com>: > > Hi, > > > > I''d like to add TaskScheduler#exists?(work_item) to the win32- > taskscheduler > > library. Mostly I want it for testing, but it might come in handy for > other > > people as well. > > > > What''s the best way to approach this? Just enumerate the tasks, and > check > > for the name? > > > I think the best way to check taskscheduler item is just go to the > Scheduled Tasks folder (in most case c:\winodws\tasks) and see the > .job files. > > You can write it with ruby like this: > > def TaskScheduler#exists?(work_item) > File.exist?("#{ENV[''windir'']}\\Tasks\\#{work_item}.job") > endThat will work, though I don''t think it''s a requirement that the .job file live there, is it?> BTW, Do you mind I write pure ruby taskscheduler?I don''t mind so long as you''re not using WMI. I never completed that because of the restrictions. Regards, Dan
Luis Lavena
2009-Jun-17 03:54 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
On Wed, Jun 17, 2009 at 12:15 AM, Daniel Berger<djberg96 at gmail.com> wrote:> > >> -----Original Message----- >> [...] >> I think the best way to check taskscheduler item is just go to the >> Scheduled Tasks folder (in most case c:\winodws\tasks) and see the >> .job files. >> >> You can write it with ruby like this: >> >> def TaskScheduler#exists?(work_item) >> ? File.exist?("#{ENV[''windir'']}\\Tasks\\#{work_item}.job") >> end > > That will work, though I don''t think it''s a requirement that the .job file > live there, is it?Well, on Windows 7 and Vista only list 2 job files for me, and are google related. On Windows 7 there is SchTasks which list *lot* of tasks not covered by Windows\Tasks folder.>> BTW, Do you mind I write pure ruby taskscheduler? > > I don''t mind so long as you''re not using WMI. I never completed that because > of the restrictions. >I believe there is an API not using instrumentation services, but quite don''t remember. A partner at my old job used to play with it on Windows 2000. Will check and get back to you. -- Luis Lavena AREA 17 - Perfection in design is achieved not when there is nothing more to add, but rather when there is nothing more to take away. Antoine de Saint-Exup?ry
Heesob Park
2009-Jun-17 04:06 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
2009/6/17 Daniel Berger <djberg96 at gmail.com>:> > >> -----Original Message----- >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel- >> bounces at rubyforge.org] On Behalf Of Heesob Park >> Sent: Tuesday, June 16, 2009 7:47 PM >> To: Development and ideas for win32utils projects >> Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? >> method >> >> Hi, >> >> 2009/6/17 Daniel Berger <djberg96 at gmail.com>: >> > Hi, >> > >> > I''d like to add TaskScheduler#exists?(work_item) to the win32- >> taskscheduler >> > library. Mostly I want it for testing, but it might come in handy for >> other >> > people as well. >> > >> > What''s the best way to approach this? Just enumerate the tasks, and >> check >> > for the name? >> > >> I think the best way to check taskscheduler item is just go to the >> Scheduled Tasks folder (in most case c:\winodws\tasks) and see the >> .job files. >> >> You can write it with ruby like this: >> >> def TaskScheduler#exists?(work_item) >> ? File.exist?("#{ENV[''windir'']}\\Tasks\\#{work_item}.job") >> end > > That will work, though I don''t think it''s a requirement that the .job file > live there, is it? >According to http://support.microsoft.com/kb/310424/en, I think so.>> BTW, Do you mind I write pure ruby taskscheduler? > > I don''t mind so long as you''re not using WMI. I never completed that because > of the restrictions. >Of course, I mean the literal translation of the current c code. I like to use the same technique used in pure win32ole ruby code. Regards, Park Heesob
Daniel Berger
2009-Jun-17 04:36 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
> -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel- > bounces at rubyforge.org] On Behalf Of Luis Lavena > Sent: Tuesday, June 16, 2009 9:55 PM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? > method > > On Wed, Jun 17, 2009 at 12:15 AM, Daniel Berger<djberg96 at gmail.com> > wrote: > > > > > >> -----Original Message----- > >> [...] > >> I think the best way to check taskscheduler item is just go to the > >> Scheduled Tasks folder (in most case c:\winodws\tasks) and see the > >> .job files. > >> > >> You can write it with ruby like this: > >> > >> def TaskScheduler#exists?(work_item) > >> ? File.exist?("#{ENV[''windir'']}\\Tasks\\#{work_item}.job") > >> end > > > > That will work, though I don''t think it''s a requirement that the .job > file > > live there, is it? > > Well, on Windows 7 and Vista only list 2 job files for me, and are > google related. > > On Windows 7 there is SchTasks which list *lot* of tasks not covered > by Windows\Tasks folder.On my Vista Home Premium laptop I only see a single file called SCHEDLGU.TXT under C:\Windows\Tasks. It appears to be nothing more than a record of the Task Scheduler Service. Regards, Dan
Daniel Berger
2009-Jun-17 04:47 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
> -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel- > bounces at rubyforge.org] On Behalf Of Heesob Park > Sent: Tuesday, June 16, 2009 10:07 PM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? > method > > 2009/6/17 Daniel Berger <djberg96 at gmail.com>: > > > > > >> -----Original Message----- > >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils- > devel- > >> bounces at rubyforge.org] On Behalf Of Heesob Park > >> Sent: Tuesday, June 16, 2009 7:47 PM > >> To: Development and ideas for win32utils projects > >> Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? > >> method > >> > >> Hi, > >> > >> 2009/6/17 Daniel Berger <djberg96 at gmail.com>: > >> > Hi, > >> > > >> > I''d like to add TaskScheduler#exists?(work_item) to the win32- > >> taskscheduler > >> > library. Mostly I want it for testing, but it might come in handy > for > >> other > >> > people as well. > >> > > >> > What''s the best way to approach this? Just enumerate the tasks, > and > >> check > >> > for the name? > >> > > >> I think the best way to check taskscheduler item is just go to the > >> Scheduled Tasks folder (in most case c:\winodws\tasks) and see the > >> .job files. > >> > >> You can write it with ruby like this: > >> > >> def TaskScheduler#exists?(work_item) > >> File.exist?("#{ENV[''windir'']}\\Tasks\\#{work_item}.job") > >> end > > > > That will work, though I don''t think it''s a requirement that the .job > file > > live there, is it? > > > According to http://support.microsoft.com/kb/310424/en, I think so. > > >> BTW, Do you mind I write pure ruby taskscheduler? > > > > I don''t mind so long as you''re not using WMI. I never completed that > because > > of the restrictions. > > > Of course, I mean the literal translation of the current c code. > I like to use the same technique used in pure win32ole ruby code.I thought it would be problematic because it''s C++, but if you can do it, by all means please go for it! Regards, Dan
Heesob Park
2009-Jun-17 04:56 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
2009/6/17 Daniel Berger <djberg96 at gmail.com>:> > >> -----Original Message----- >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel- >> bounces at rubyforge.org] On Behalf Of Luis Lavena >> Sent: Tuesday, June 16, 2009 9:55 PM >> To: Development and ideas for win32utils projects >> Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? >> method >> >> On Wed, Jun 17, 2009 at 12:15 AM, Daniel Berger<djberg96 at gmail.com> >> wrote: >> > >> > >> >> -----Original Message----- >> >> [...] >> >> I think the best way to check taskscheduler item is just go to the >> >> Scheduled Tasks folder (in most case c:\winodws\tasks) and see the >> >> .job files. >> >> >> >> You can write it with ruby like this: >> >> >> >> def TaskScheduler#exists?(work_item) >> >> ? File.exist?("#{ENV[''windir'']}\\Tasks\\#{work_item}.job") >> >> end >> > >> > That will work, though I don''t think it''s a requirement that the .job >> file >> > live there, is it? >> >> Well, on Windows 7 and Vista only list 2 job files for me, and are >> google related. >> >> On Windows 7 there is SchTasks which list *lot* of tasks not covered >> by Windows\Tasks folder. > > On my Vista Home Premium laptop I only see a single file called SCHEDLGU.TXT > under C:\Windows\Tasks. It appears to be nothing more than a record of the > Task Scheduler Service. >It''s in C:\Windows\System32\Tasks folder without .job extension. Regards, Park Heesob
Heesob Park
2009-Jun-18 01:22 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
Hi, 2009/6/17 Daniel Berger <djberg96 at gmail.com>:> ><snip>> I thought it would be problematic because it''s C++, but if you can do it, by all means please go for it! >Here is a pure ruby win32-taskscheduler. http://121.78.227.9/win32-taskscheduler/taskscheduler.rb Regards, Park Heesob
Daniel Berger
2009-Jun-18 13:24 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
> -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel- > bounces at rubyforge.org] On Behalf Of Heesob Park > Sent: Wednesday, June 17, 2009 7:23 PM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? > method > > Hi, > > 2009/6/17 Daniel Berger <djberg96 at gmail.com>: > > > > > <snip> > > I thought it would be problematic because it''s C++, but if you can do > it, by all means please go for it! > > > Here is a pure ruby win32-taskscheduler. > http://121.78.227.9/win32-taskscheduler/taskscheduler.rbAwesome! I''ve got it committed and I''m just doing some formatting on it and adding some RDoc. I''ll try to get this out as soon as possible. Regards, Dan
Daniel Berger
2009-Jun-18 23:04 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
> -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel- > bounces at rubyforge.org] On Behalf Of Heesob Park > Sent: Wednesday, June 17, 2009 7:23 PM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? > method > > Hi, > > 2009/6/17 Daniel Berger <djberg96 at gmail.com>: > > > > > <snip> > > I thought it would be problematic because it''s C++, but if you can do > it, by all means please go for it! > > > Here is a pure ruby win32-taskscheduler. > http://121.78.227.9/win32-taskscheduler/taskscheduler.rbLooks like there''s a bug in line 756 (in the file in CVS) in the new_work_item method: memcpy(lpVtbl, @pITask, 4) That''s segfaulting. Here''s a small sample to demonstrate: trigger = { ''start_year'' => 2011, ''start_month'' => 4, ''start_day'' => 11, ''start_hour'' => 7, ''start_minute'' => 14, ''trigger_type'' => TaskScheduler::DAILY, ''type'' => { ''days_interval'' => 1 } } ts = Win32::TaskScheduler.new(''foo'', trigger) ts.save ts.activate(''foo'') Hopefully I didn''t accidentally introduce it. Regards, Dan
Heesob Park
2009-Jun-19 00:36 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
Hi, 2009/6/19 Daniel Berger <djberg96 at gmail.com>:> > >> -----Original Message----- >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel- >> bounces at rubyforge.org] On Behalf Of Heesob Park >> Sent: Wednesday, June 17, 2009 7:23 PM >> To: Development and ideas for win32utils projects >> Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? >> method >> >> Hi, >> >> 2009/6/17 Daniel Berger <djberg96 at gmail.com>: >> > >> > >> <snip> >> > I thought it would be problematic because it''s C++, but if you can do >> it, by all means please go for it! >> > >> Here is a pure ruby win32-taskscheduler. >> http://121.78.227.9/win32-taskscheduler/taskscheduler.rb > > Looks like there''s a bug in line 756 (in the file in CVS) in the > new_work_item method: > > memcpy(lpVtbl, @pITask, 4) > > That''s segfaulting. > > Here''s a small sample to demonstrate: > > ? trigger = { > ? ? ?''start_year'' ? => 2011, > ? ? ?''start_month'' ?=> 4, > ? ? ?''start_day'' ? ?=> 11, > ? ? ?''start_hour'' ? => 7, > ? ? ?''start_minute'' => 14, > ? ? ?''trigger_type'' => TaskScheduler::DAILY, > ? ? ?''type'' ? ? ? ? => { ''days_interval'' => 1 } > ? } > > ? ts = Win32::TaskScheduler.new(''foo'', trigger) > ? ts.save > ? ts.activate(''foo'') > > Hopefully I didn''t accidentally introduce it. >I works fine with my XP box. What''s your OS and Ruby version? Regards, Park Heesob
Daniel Berger
2009-Jun-19 01:05 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
On Thu, Jun 18, 2009 at 6:36 PM, Heesob Park<phasis at gmail.com> wrote:> Hi, > > 2009/6/19 Daniel Berger <djberg96 at gmail.com>: >> >> >>> -----Original Message----- >>> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel- >>> bounces at rubyforge.org] On Behalf Of Heesob Park >>> Sent: Wednesday, June 17, 2009 7:23 PM >>> To: Development and ideas for win32utils projects >>> Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? >>> method >>> >>> Hi, >>> >>> 2009/6/17 Daniel Berger <djberg96 at gmail.com>: >>> > >>> > >>> <snip> >>> > I thought it would be problematic because it''s C++, but if you can do >>> it, by all means please go for it! >>> > >>> Here is a pure ruby win32-taskscheduler. >>> http://121.78.227.9/win32-taskscheduler/taskscheduler.rb >> >> Looks like there''s a bug in line 756 (in the file in CVS) in the >> new_work_item method: >> >> memcpy(lpVtbl, @pITask, 4) >> >> That''s segfaulting. >> >> Here''s a small sample to demonstrate: >> >> ? trigger = { >> ? ? ?''start_year'' ? => 2011, >> ? ? ?''start_month'' ?=> 4, >> ? ? ?''start_day'' ? ?=> 11, >> ? ? ?''start_hour'' ? => 7, >> ? ? ?''start_minute'' => 14, >> ? ? ?''trigger_type'' => TaskScheduler::DAILY, >> ? ? ?''type'' ? ? ? ? => { ''days_interval'' => 1 } >> ? } >> >> ? ts = Win32::TaskScheduler.new(''foo'', trigger) >> ? ts.save >> ? ts.activate(''foo'') >> >> Hopefully I didn''t accidentally introduce it. >> > I works fine with my XP box. > What''s your OS and Ruby version?Vista Home Premium Ruby 1.8.6 p111 (one click) windows-api 0.3.0 win32-api-1.4.2 Here''s the actual message. It''s the call at line 756 that''s ultimately causing the issue from what I can tell: C:/Ruby/lib/ruby/gems/1.8/gems/windows-api-0.3.0/lib/windows/api.rb:484: [BUG] Segmentation fault ruby 1.8.6 (2007-09-24) [i386-mswin32] Ideas? Regards, Dan PS - In other news, I messed something up with windows-api and VC++ 9: c:\Users\djberge\workspace\win32-taskscheduler\lib\win32>ruby9 taskscheduler.rb c:/rubyvc9/lib/ruby/gems/1.8/gems/windows-api-0.3.0/lib/windows/api.rb:333:in `initialize'': LoadLibrary() function faile d for ''msvcr90'': The specified module could not be found. (Win32::API::LoadLibraryError) from c:/rubyvc9/lib/ruby/gems/1.8/gems/windows-api-0.3.0/lib/windows/api.rb:333:in `new'' from c:/rubyvc9/lib/ruby/gems/1.8/gems/windows-api-0.3.0/lib/windows/api.rb:333:in `initialize'' from c:/rubyvc9/lib/ruby/gems/1.8/gems/windows-pr-1.0.5/lib/windows/msvcrt/string.rb:10:in `new'' from c:/rubyvc9/lib/ruby/gems/1.8/gems/windows-pr-1.0.5/lib/windows/msvcrt/string.rb:10 from c:/rubyvc9/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'' from c:/rubyvc9/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'' from c:/rubyvc9/lib/ruby/gems/1.8/gems/windows-pr-1.0.5/lib/windows/unicode.rb:2 from c:/rubyvc9/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'' from c:/rubyvc9/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'' from taskscheduler.rb:2
Daniel Berger
2009-Jun-19 01:22 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
> -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel- > bounces at rubyforge.org] On Behalf Of Heesob Park > Sent: Thursday, June 18, 2009 6:37 PM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? > method > > Hi, > > 2009/6/19 Daniel Berger <djberg96 at gmail.com>: > > > > > >> -----Original Message----- > >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils- > devel- > >> bounces at rubyforge.org] On Behalf Of Heesob Park > >> Sent: Wednesday, June 17, 2009 7:23 PM > >> To: Development and ideas for win32utils projects > >> Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? > >> method > >> > >> Hi, > >> > >> 2009/6/17 Daniel Berger <djberg96 at gmail.com>: > >> > > >> > > >> <snip> > >> > I thought it would be problematic because it''s C++, but if you can > do > >> it, by all means please go for it! > >> > > >> Here is a pure ruby win32-taskscheduler. > >> http://121.78.227.9/win32-taskscheduler/taskscheduler.rb > > > > Looks like there''s a bug in line 756 (in the file in CVS) in the > > new_work_item method: > > > > memcpy(lpVtbl, @pITask, 4) > > > > That''s segfaulting. > > > > Here''s a small sample to demonstrate: > > > > trigger = { > > ''start_year'' => 2011, > > ''start_month'' => 4, > > ''start_day'' => 11, > > ''start_hour'' => 7, > > ''start_minute'' => 14, > > ''trigger_type'' => TaskScheduler::DAILY, > > ''type'' => { ''days_interval'' => 1 } > > } > > > > ts = Win32::TaskScheduler.new(''foo'', trigger) > > ts.save > > ts.activate(''foo'') > > > > Hopefully I didn''t accidentally introduce it. > > > I works fine with my XP box. > What''s your OS and Ruby version?Quick followup. One of the things I changed was: hr != S_OK to FAILED(hr) I thought it looked a little nicer and it more closely follows the C code. But the FAILED() macro method only checks to see if its argument is less than 0. When I inspected the hr variable, it''s actually 2147942480 (The operation completed successfully). Regards, Dan
Heesob Park
2009-Jun-19 02:49 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
2009/6/19 Daniel Berger <djberg96 at gmail.com>:> > >> -----Original Message----- >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel- >> bounces at rubyforge.org] On Behalf Of Heesob Park >> Sent: Thursday, June 18, 2009 6:37 PM >> To: Development and ideas for win32utils projects >> Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? >> method >> >> Hi, >> >> 2009/6/19 Daniel Berger <djberg96 at gmail.com>: >> > >> > >> >> -----Original Message----- >> >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils- >> devel- >> >> bounces at rubyforge.org] On Behalf Of Heesob Park >> >> Sent: Wednesday, June 17, 2009 7:23 PM >> >> To: Development and ideas for win32utils projects >> >> Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? >> >> method >> >> >> >> Hi, >> >> >> >> 2009/6/17 Daniel Berger <djberg96 at gmail.com>: >> >> > >> >> > >> >> <snip> >> >> > I thought it would be problematic because it''s C++, but if you can >> do >> >> it, by all means please go for it! >> >> > >> >> Here is a pure ruby win32-taskscheduler. >> >> http://121.78.227.9/win32-taskscheduler/taskscheduler.rb >> > >> > Looks like there''s a bug in line 756 (in the file in CVS) in the >> > new_work_item method: >> > >> > memcpy(lpVtbl, @pITask, 4) >> > >> > That''s segfaulting. >> > >> > Here''s a small sample to demonstrate: >> > >> > ? trigger = { >> > ? ? ?''start_year'' ? => 2011, >> > ? ? ?''start_month'' ?=> 4, >> > ? ? ?''start_day'' ? ?=> 11, >> > ? ? ?''start_hour'' ? => 7, >> > ? ? ?''start_minute'' => 14, >> > ? ? ?''trigger_type'' => TaskScheduler::DAILY, >> > ? ? ?''type'' ? ? ? ? => { ''days_interval'' => 1 } >> > ? } >> > >> > ? ts = Win32::TaskScheduler.new(''foo'', trigger) >> > ? ts.save >> > ? ts.activate(''foo'') >> > >> > Hopefully I didn''t accidentally introduce it. >> > >> I works fine with my XP box. >> What''s your OS and Ruby version? > > Quick followup. One of the things I changed was: > > hr != S_OK > > to > > FAILED(hr) > > I thought it looked a little nicer and it more closely follows the C code. But the FAILED() macro method only checks to see if its argument is less than 0. When I inspected the hr variable, it''s actually 2147942480 (The operation completed successfully). >I checked the code works fine on Windows 2003. Also I confirmed the error you mentioned is same on Windows 7. The error means NewWorkItem returns null pointer. I guess TaskScheduler API is changed on Vista or higher version. Regards, Park Heesob
Heesob Park
2009-Jun-19 03:21 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
2009/6/19 Daniel Berger <djberg96 at gmail.com>:> > >> -----Original Message----- >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel- >> bounces at rubyforge.org] On Behalf Of Heesob Park >> Sent: Thursday, June 18, 2009 6:37 PM >> To: Development and ideas for win32utils projects >> Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? >> method >> >> Hi, >> >> 2009/6/19 Daniel Berger <djberg96 at gmail.com>: >> > >> > >> >> -----Original Message----- >> >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils- >> devel- >> >> bounces at rubyforge.org] On Behalf Of Heesob Park >> >> Sent: Wednesday, June 17, 2009 7:23 PM >> >> To: Development and ideas for win32utils projects >> >> Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? >> >> method >> >> >> >> Hi, >> >> >> >> 2009/6/17 Daniel Berger <djberg96 at gmail.com>: >> >> > >> >> > >> >> <snip> >> >> > I thought it would be problematic because it''s C++, but if you can >> do >> >> it, by all means please go for it! >> >> > >> >> Here is a pure ruby win32-taskscheduler. >> >> http://121.78.227.9/win32-taskscheduler/taskscheduler.rb >> > >> > Looks like there''s a bug in line 756 (in the file in CVS) in the >> > new_work_item method: >> > >> > memcpy(lpVtbl, @pITask, 4) >> > >> > That''s segfaulting. >> > >> > Here''s a small sample to demonstrate: >> > >> > ? trigger = { >> > ? ? ?''start_year'' ? => 2011, >> > ? ? ?''start_month'' ?=> 4, >> > ? ? ?''start_day'' ? ?=> 11, >> > ? ? ?''start_hour'' ? => 7, >> > ? ? ?''start_minute'' => 14, >> > ? ? ?''trigger_type'' => TaskScheduler::DAILY, >> > ? ? ?''type'' ? ? ? ? => { ''days_interval'' => 1 } >> > ? } >> > >> > ? ts = Win32::TaskScheduler.new(''foo'', trigger) >> > ? ts.save >> > ? ts.activate(''foo'') >> > >> > Hopefully I didn''t accidentally introduce it. >> > >> I works fine with my XP box. >> What''s your OS and Ruby version? > > Quick followup. One of the things I changed was: > > hr != S_OK > > to > > FAILED(hr) > > I thought it looked a little nicer and it more closely follows the C code. But the FAILED() macro method only checks to see if its argument is less than 0. When I inspected the hr variable, it''s actually 2147942480 (The operation completed successfully). >I noticed the current taskscheduler implementation is using Task Scheduler 1.0. In order to work with Vista or later, we should implement a new version using Task Scheduler 2.0. The header file for Task Scheduler 2.0 is taskchd.h, whereas for 1.0 is MSTask.h. Refer to http://msdn.microsoft.com/en-us/magazine/cc163350.aspx Regards, Park Heesob
Daniel Berger
2009-Jun-19 04:23 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
> -----Original Message----- > From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel- > bounces at rubyforge.org] On Behalf Of Heesob Park > Sent: Thursday, June 18, 2009 9:22 PM > To: Development and ideas for win32utils projects > Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? > method > > 2009/6/19 Daniel Berger <djberg96 at gmail.com>: > > > > > >> -----Original Message----- > >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils- > devel- > >> bounces at rubyforge.org] On Behalf Of Heesob Park > >> Sent: Thursday, June 18, 2009 6:37 PM > >> To: Development and ideas for win32utils projects > >> Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? > >> method > >> > >> Hi, > >> > >> 2009/6/19 Daniel Berger <djberg96 at gmail.com>: > >> > > >> > > >> >> -----Original Message----- > >> >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils- > >> devel- > >> >> bounces at rubyforge.org] On Behalf Of Heesob Park > >> >> Sent: Wednesday, June 17, 2009 7:23 PM > >> >> To: Development and ideas for win32utils projects > >> >> Subject: Re: [Win32utils-devel] Implementing a > TaskScheduler#exists? > >> >> method > >> >> > >> >> Hi, > >> >> > >> >> 2009/6/17 Daniel Berger <djberg96 at gmail.com>: > >> >> > > >> >> > > >> >> <snip> > >> >> > I thought it would be problematic because it''s C++, but if you > can > >> do > >> >> it, by all means please go for it! > >> >> > > >> >> Here is a pure ruby win32-taskscheduler. > >> >> http://121.78.227.9/win32-taskscheduler/taskscheduler.rb > >> > > >> > Looks like there''s a bug in line 756 (in the file in CVS) in the > >> > new_work_item method: > >> > > >> > memcpy(lpVtbl, @pITask, 4) > >> > > >> > That''s segfaulting. > >> > > >> > Here''s a small sample to demonstrate: > >> > > >> > trigger = { > >> > ''start_year'' => 2011, > >> > ''start_month'' => 4, > >> > ''start_day'' => 11, > >> > ''start_hour'' => 7, > >> > ''start_minute'' => 14, > >> > ''trigger_type'' => TaskScheduler::DAILY, > >> > ''type'' => { ''days_interval'' => 1 } > >> > } > >> > > >> > ts = Win32::TaskScheduler.new(''foo'', trigger) > >> > ts.save > >> > ts.activate(''foo'') > >> > > >> > Hopefully I didn''t accidentally introduce it. > >> > > >> I works fine with my XP box. > >> What''s your OS and Ruby version? > > > > Quick followup. One of the things I changed was: > > > > hr != S_OK > > > > to > > > > FAILED(hr) > > > > I thought it looked a little nicer and it more closely follows the C > code. But the FAILED() macro method only checks to see if its argument > is less than 0. When I inspected the hr variable, it''s actually > 2147942480 (The operation completed successfully). > > > I noticed the current taskscheduler implementation is using Task > Scheduler 1.0. > In order to work with Vista or later, we should implement a new > version using Task Scheduler 2.0. > The header file for Task Scheduler 2.0 is taskchd.h, whereas for 1.0 > is MSTask.h.Ok, how would you like to proceed? Should I release the current (pure Ruby) code with a warning regarding Vista or later? Or wait? Regards, Dan
Heesob Park
2009-Jun-19 05:05 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
2009/6/19 Daniel Berger <djberg96 at gmail.com>:> > >> -----Original Message----- >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel- >> bounces at rubyforge.org] On Behalf Of Heesob Park >> Sent: Thursday, June 18, 2009 9:22 PM >> To: Development and ideas for win32utils projects >> Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? >> method >> >> 2009/6/19 Daniel Berger <djberg96 at gmail.com>: >> > >> > >> >> -----Original Message----- >> >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils- >> devel- >> >> bounces at rubyforge.org] On Behalf Of Heesob Park >> >> Sent: Thursday, June 18, 2009 6:37 PM >> >> To: Development and ideas for win32utils projects >> >> Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? >> >> method >> >> >> >> Hi, >> >> >> >> 2009/6/19 Daniel Berger <djberg96 at gmail.com>: >> >> > >> >> > >> >> >> -----Original Message----- >> >> >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils- >> >> devel- >> >> >> bounces at rubyforge.org] On Behalf Of Heesob Park >> >> >> Sent: Wednesday, June 17, 2009 7:23 PM >> >> >> To: Development and ideas for win32utils projects >> >> >> Subject: Re: [Win32utils-devel] Implementing a >> TaskScheduler#exists? >> >> >> method >> >> >> >> >> >> Hi, >> >> >> >> >> >> 2009/6/17 Daniel Berger <djberg96 at gmail.com>: >> >> >> > >> >> >> > >> >> >> <snip> >> >> >> > I thought it would be problematic because it''s C++, but if you >> can >> >> do >> >> >> it, by all means please go for it! >> >> >> > >> >> >> Here is a pure ruby win32-taskscheduler. >> >> >> http://121.78.227.9/win32-taskscheduler/taskscheduler.rb >> >> > >> >> > Looks like there''s a bug in line 756 (in the file in CVS) in the >> >> > new_work_item method: >> >> > >> >> > memcpy(lpVtbl, @pITask, 4) >> >> > >> >> > That''s segfaulting. >> >> > >> >> > Here''s a small sample to demonstrate: >> >> > >> >> > ? trigger = { >> >> > ? ? ?''start_year'' ? => 2011, >> >> > ? ? ?''start_month'' ?=> 4, >> >> > ? ? ?''start_day'' ? ?=> 11, >> >> > ? ? ?''start_hour'' ? => 7, >> >> > ? ? ?''start_minute'' => 14, >> >> > ? ? ?''trigger_type'' => TaskScheduler::DAILY, >> >> > ? ? ?''type'' ? ? ? ? => { ''days_interval'' => 1 } >> >> > ? } >> >> > >> >> > ? ts = Win32::TaskScheduler.new(''foo'', trigger) >> >> > ? ts.save >> >> > ? ts.activate(''foo'') >> >> > >> >> > Hopefully I didn''t accidentally introduce it. >> >> > >> >> I works fine with my XP box. >> >> What''s your OS and Ruby version? >> > >> > Quick followup. One of the things I changed was: >> > >> > hr != S_OK >> > >> > to >> > >> > FAILED(hr) >> > >> > I thought it looked a little nicer and it more closely follows the C >> code. But the FAILED() macro method only checks to see if its argument >> is less than 0. When I inspected the hr variable, it''s actually >> 2147942480 (The operation completed successfully). >> > >> I noticed the current taskscheduler implementation is using Task >> Scheduler 1.0. >> In order to work with Vista or later, we should implement a new >> version using Task Scheduler 2.0. >> The header file for Task Scheduler 2.0 is taskchd.h, whereas for 1.0 >> is MSTask.h. > > Ok, how would you like to proceed? Should I release the current (pure Ruby) code with a warning regarding Vista or later? Or wait? >It is up to you. I don''t mind whether you release it or not. Regards, Park Heesob
Heesob Park
2009-Jun-19 08:36 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
2009/6/19 Daniel Berger <djberg96 at gmail.com>:> > >> -----Original Message----- >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils-devel- >> bounces at rubyforge.org] On Behalf Of Heesob Park >> Sent: Thursday, June 18, 2009 9:22 PM >> To: Development and ideas for win32utils projects >> Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? >> method >> >> 2009/6/19 Daniel Berger <djberg96 at gmail.com>: >> > >> > >> >> -----Original Message----- >> >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils- >> devel- >> >> bounces at rubyforge.org] On Behalf Of Heesob Park >> >> Sent: Thursday, June 18, 2009 6:37 PM >> >> To: Development and ideas for win32utils projects >> >> Subject: Re: [Win32utils-devel] Implementing a TaskScheduler#exists? >> >> method >> >> >> >> Hi, >> >> >> >> 2009/6/19 Daniel Berger <djberg96 at gmail.com>: >> >> > >> >> > >> >> >> -----Original Message----- >> >> >> From: win32utils-devel-bounces at rubyforge.org [mailto:win32utils- >> >> devel- >> >> >> bounces at rubyforge.org] On Behalf Of Heesob Park >> >> >> Sent: Wednesday, June 17, 2009 7:23 PM >> >> >> To: Development and ideas for win32utils projects >> >> >> Subject: Re: [Win32utils-devel] Implementing a >> TaskScheduler#exists? >> >> >> method >> >> >> >> >> >> Hi, >> >> >> >> >> >> 2009/6/17 Daniel Berger <djberg96 at gmail.com>: >> >> >> > >> >> >> > >> >> >> <snip> >> >> >> > I thought it would be problematic because it''s C++, but if you >> can >> >> do >> >> >> it, by all means please go for it! >> >> >> > >> >> >> Here is a pure ruby win32-taskscheduler. >> >> >> http://121.78.227.9/win32-taskscheduler/taskscheduler.rb >> >> > >> >> > Looks like there''s a bug in line 756 (in the file in CVS) in the >> >> > new_work_item method: >> >> > >> >> > memcpy(lpVtbl, @pITask, 4) >> >> > >> >> > That''s segfaulting. >> >> > >> >> > Here''s a small sample to demonstrate: >> >> > >> >> > ? trigger = { >> >> > ? ? ?''start_year'' ? => 2011, >> >> > ? ? ?''start_month'' ?=> 4, >> >> > ? ? ?''start_day'' ? ?=> 11, >> >> > ? ? ?''start_hour'' ? => 7, >> >> > ? ? ?''start_minute'' => 14, >> >> > ? ? ?''trigger_type'' => TaskScheduler::DAILY, >> >> > ? ? ?''type'' ? ? ? ? => { ''days_interval'' => 1 } >> >> > ? } >> >> > >> >> > ? ts = Win32::TaskScheduler.new(''foo'', trigger) >> >> > ? ts.save >> >> > ? ts.activate(''foo'') >> >> > >> >> > Hopefully I didn''t accidentally introduce it. >> >> > >> >> I works fine with my XP box. >> >> What''s your OS and Ruby version? >> > >> > Quick followup. One of the things I changed was: >> > >> > hr != S_OK >> > >> > to >> > >> > FAILED(hr) >> > >> > I thought it looked a little nicer and it more closely follows the C >> code. But the FAILED() macro method only checks to see if its argument >> is less than 0. When I inspected the hr variable, it''s actually >> 2147942480 (The operation completed successfully). >> > >> I noticed the current taskscheduler implementation is using Task >> Scheduler 1.0. >> In order to work with Vista or later, we should implement a new >> version using Task Scheduler 2.0. >> The header file for Task Scheduler 2.0 is taskchd.h, whereas for 1.0 >> is MSTask.h. > > Ok, how would you like to proceed? Should I release the current (pure Ruby) code with a warning regarding Vista or later? Or wait? >Good news is Task Sheduler 2.0 fully supports Scripting. Thus an implementation using win32ole is easy. Here is a sample for enumerating tasks: #--------------------------------------------------------- # This sample enumerates through the tasks on the local computer and # displays their name and state. #--------------------------------------------------------- require ''win32ole'' # Create the TaskService object. service = WIN32OLE.new("Schedule.Service") service.Connect() # Get the task folder that contains the tasks. rootFolder = service.GetFolder("\\") taskCollection = rootFolder.GetTasks(0) numberOfTasks = taskCollection.Count if numberOfTasks == 0 puts "No tasks are registered." else puts "Number of tasks registered: #{numberOfTasks}" taskCollection.each do |registeredTask| puts "Task Name: #{registeredTask.Name}" case registeredTask.State when "0" taskState = "Unknown" when "1" taskState = "Disabled" when "2" taskState = "Queued" when "3" taskState = "Ready" when "4" taskState = "Running" end puts " Task State: #{taskState}" end end Regards, Park Heesob
Daniel Berger
2009-Jun-19 20:52 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
Hi, <snip>> > Ok, how would you like to proceed? Should I release the current (pure > Ruby) code with a warning regarding Vista or later? Or wait? > > > Good news is Task Sheduler 2.0 fully supports Scripting. > Thus an implementation using win32ole is easy. > > Here is a sample for enumerating tasks: > > #--------------------------------------------------------- > # This sample enumerates through the tasks on the local computer and > # displays their name and state. > #--------------------------------------------------------- > require ''win32ole'' > > # Create the TaskService object. > service = WIN32OLE.new("Schedule.Service") > service.Connect() > > # Get the task folder that contains the tasks. > rootFolder = service.GetFolder("\\") > > taskCollection = rootFolder.GetTasks(0) > > numberOfTasks = taskCollection.Count > > if numberOfTasks == 0 > puts "No tasks are registered." > else > puts "Number of tasks registered: #{numberOfTasks}" > > taskCollection.each do |registeredTask| > puts "Task Name: #{registeredTask.Name}" > > case registeredTask.State > when "0" > taskState = "Unknown" > when "1" > taskState = "Disabled" > when "2" > taskState = "Queued" > when "3" > taskState = "Ready" > when "4" > taskState = "Running" > end > > puts " Task State: #{taskState}" > end > endOk, cool. I went ahead and released 0.2.0 without Vista support for now. Version 0.3.0 will support Vista and use win32ole behind the scenes. Regards, Dan
Heesob Park
2009-Jun-20 03:42 UTC
[Win32utils-devel] Implementing a TaskScheduler#exists? method
HI, 2009/6/20 Daniel Berger <djberg96 at gmail.com>:> Hi, > > <snip> > >> > Ok, how would you like to proceed? Should I release the current (pure >> Ruby) code with a warning regarding Vista or later? Or wait? >> > >> Good news is Task Sheduler 2.0 fully supports Scripting. >> Thus an implementation using win32ole is easy. >> >> Here is a sample for enumerating tasks: >> >> #--------------------------------------------------------- >> # This sample enumerates through the tasks on the local computer and >> # displays their name and state. >> #--------------------------------------------------------- >> require ''win32ole'' >> >> # Create the TaskService object. >> service = ?WIN32OLE.new("Schedule.Service") >> service.Connect() >> >> # Get the task folder that contains the tasks. >> rootFolder = service.GetFolder("\\") >> >> taskCollection = rootFolder.GetTasks(0) >> >> numberOfTasks = taskCollection.Count >> >> if numberOfTasks == 0 >> ? ? puts "No tasks are registered." >> else >> ? ? puts "Number of tasks registered: #{numberOfTasks}" >> >> ? ? taskCollection.each do |registeredTask| >> ? ? ? ? puts "Task Name: #{registeredTask.Name}" >> >> ? ? ? ? case registeredTask.State >> ? ? ? ? ? ? when "0" >> ? ? ? ? ? ? ? ? taskState = "Unknown" >> ? ? ? ? ? ? when "1" >> ? ? ? ? ? ? ? ? taskState = "Disabled" >> ? ? ? ? ? ? when "2" >> ? ? ? ? ? ? ? ? taskState = "Queued" >> ? ? ? ? ? ? when "3" >> ? ? ? ? ? ? ? ? taskState = "Ready" >> ? ? ? ? ? ? when "4" >> ? ? ? ? ? ? ? ? taskState = "Running" >> ? ? ? ? end >> >> ? ? ? ? puts " ? ?Task State: #{taskState}" >> ? ? end >> ? end > > Ok, cool. I went ahead and released 0.2.0 without Vista support for now. Version 0.3.0 will support Vista and use win32ole behind the scenes. >Ok, I made taskscheduler version 2.0 and it is available at http://121.78.227.9/win32-taskscheduler/taskscheduler2.rb As you know, some operations need Administration right and some operations need password. Regards, Park Heesob