Recent

Author Topic: Fix scheduled tasks tool  (Read 3538 times)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Fix scheduled tasks tool
« on: July 22, 2014, 11:18:37 am »
fixscheduledtasks:

Wrote a tool that fixes corrupt scheduled tasks on Windows 2008/7/+
Basically automates the steps mentioned in
http://support.microsoft.com/kb/2305420

Requires setacl.exe to be present in path
(note: this could perhaps be replaced by cacls/icacls/whatever ships with current Windows?)

Inspired by batch file in
http://gallery.technet.microsoft.com/scriptcenter/Repair-CorruptedTampered-c8d2e975
with some refinements - no need to specify a list of tasks.

For all scheduled tasks, the program
- exports the task XML definition file
- deletes the task from the registry and removes the XML definition file
- recreates the task from the exported file
thereby fixing corrupted tasks errors

Code refers to the steps in that KB article
NOTE:
- MUST be compiled with x64 compiler if you are running x64/64 bit Windows
- MUST be compiled with x86 compiler if you are running x86/32 bit Windows

Code works on my x64 Windows 7 installation.
Use at your own risk; open source (MIT license).

Source code downloadable via
https://bitbucket.org/reiniero/smalltools/
(via mercurial or via download repository at https://bitbucket.org/reiniero/smalltools/downloads)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Fix scheduled tasks tool
« Reply #1 on: July 22, 2014, 01:04:10 pm »
Wouldn't it make more sense to do it via the API instead of calling setacl?  The JWscl security and permissions lib that is linked to winunits-jedi might be of interest:

http://blog.delphi-jedi.net/category/downloads/jwscl-downloads/

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Fix scheduled tasks tool
« Reply #2 on: July 22, 2014, 01:08:58 pm »
Yes, it would make more sense to call the API. However, I had looked into setting ACLs before using the API and IIRC it did not work.

I had to get something going and used what was to hand... if somebody wants to contribute the API calls to set owner of the registry objects, I'd be very grateful to lose a dependency ;)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Fix scheduled tasks tool
« Reply #3 on: July 22, 2014, 05:03:53 pm »
Yes, it would make more sense to call the API. However, I had looked into setting ACLs before using the API and IIRC it did not work.
My first attempt trying to use ACLs failed, apparently without a reason. Luckily there was a small application doing what I wanted to do. It turned out that FPC gives enumerated types like this one:
Code: [Select]
..
unit JwaAccCtrl;
..
  _TRUSTEE_FORM = (
    TRUSTEE_IS_SID,
    TRUSTEE_IS_NAME,
    TRUSTEE_BAD_FORM,
    TRUSTEE_IS_OBJECTS_AND_SID,
    TRUSTEE_IS_OBJECTS_AND_NAME);
one byte, while it should be four according to the docs and the other working application. Simply using {$PACKENUM 4} and {$PACKRECORDS 4} solved the problem on my system. Mind you I'm using an old 2.7.1 FPC.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11383
  • FPC developer.
Re: Fix scheduled tasks tool
« Reply #4 on: July 22, 2014, 05:15:44 pm »
(earlier post deleted, wrong test).

I tested against delphi, and in XE4 a variable of the above enum type has size 1.
« Last Edit: July 22, 2014, 06:35:10 pm by marcov »

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Fix scheduled tasks tool
« Reply #5 on: July 22, 2014, 09:40:47 pm »
You are right. I just double checked my project. Every unit is in objfpc mode except one is in delphi mode. JwaXXX units are used in two units, one objfpc and the other delphi mode unit.

 

TinyPortal © 2005-2018