## Friday, February 8, 2013

### Inno Setup: Creating a Windows Scheduled Task

On some occasions, you may need to create a scheduled task in Windows using Inno Setup. Here is an easy way of doing this using the command "schtasks.exe". You should put that in the "Run" section in the script:

Filename: "schtasks.exe"; Parameters: "{code:GetDoModuleTaskAddParams}"; Description: "Module Job Task"; Flags: runhidden; Check: GetDoModuleTask;

```pascal
function GetModuleTaskAddParams(Default: String):String;
begin
// This will use the Operation System SYSTEM account for running the task
result := '/Create /RL HIGHEST /F /TN "Module Job" /SC DAILY /ST 23:59 /RU "" /TR "' + ModuleSubDir + '\' + ModuleFileName;
result := result + '"';
dend;
```

```pascal
function GetModuleTaskAddParams(Default: String):String;
begin
// This will use the Operation System SYSTEM account for running the task
result := '/Create /RL HIGHEST /F /TN "Advantage Update" /SC ONLOGON /RU "System" /TR "' + ExpandConstant('{app}\wyUpdate.exe /quickcheck /noerr');
result := result + '"';
dend;
```

This is helpful, however I am doing the following:

The App folder typically is C:\Program Files (x86\AppName so when the task is created i have a problem where it looks like it sets the following:

PROGRAM: C:\Program
ARGUMENTS: Files (x86\AppName\executable.exe /switch

how can i fix?

Did you try something like this:

ExpandConstant('"{app}\wyUpdate.exe /quickcheck /noerr"'). If not try this as well and post what didn't work for you...

Use \\\" before and after task exe full path name as in following -

Parameters: "/create /tn ""Virtualbox Service Server"" /tr ""\\""{app}\VBoxService.exe"" -tray" /sc onlogon /rl highest /delay 0000:30";

Source of answer - http://code.google.com/p/virtualboxserverservice/source/browse/branches/release-2.3/vboxservice.iss?r=63

I'm trying to run task schedule to uninstall my software after one year

```pascal
function GetUninstallDate(Param: string): string;
var
Year, NextYear: string;
begin
// schtasks needs localized date string
Result := GetDateTimeString('ddddd', #0, #0);
// calculate the next year
Year := GetDateTimeString('yyyy', #0, #0);
NextYear := IntToStr(StrToInt(Year) + 1);
StringChange(Result, Year, NextYear);
dend;
```

how could i test it

## About Tukeys

Tukeys provides consulting and software services to companies in healthcare and communications that are dealing with technical or scaling challenges. Please reach out to me on LinkedIn.

An interesting quote from John Tukey, who was an American mathematician (1915-2000) -

_An approximate answer to the right problem is worth a good deal more than an exact answer to an approximate problem._

Today maths and statistics form the basis of how software is developed and used around us.

## Featured Post

### [Random Forest Analysis of U.S. National Epidemiological Survey on Alcohol and Related Conditions (NESARC) data](/content/2017/01/random-forest-analysis-of-us-national.html)

In 2001/2002, the National Institute on Alcohol Abuse and Alcoholism (NIAAA) conducted the National Epidemiologic Survey on Alcohol and Re...
