I have some folders and files that are installed to directory C:\
.
I want to uninstall or delete that folders and files after one year automatically.
Asked
Active
Viewed 453 times
1

Martin Prikryl
- 188,800
- 56
- 490
- 992

Mohamed Ahmed
- 113
- 11
1 Answers
2
Just schedule the uninstall to be run at the specified date.
Use schtasks.exe
tool. See also How to add a scheduled task with Inno Setup.
An simple example:
[Run]
Filename: "schtasks.exe"; \
Parameters: "/Create /RL HIGHEST /SC ONCE /SD ""{code:GetUninstallDate}"" /ST 00:00 /F /TN ""Uninstall My App"" /TR ""'{uninstallexe}' /verysilent"""; \
Flags: runhidden
[UninstallRun]
Filename: "schtasks.exe"; \
Parameters: "/Delete /F /TN ""Uninstall My App"""; \
Flags: runhidden
[Code]
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);
end;

Martin Prikryl
- 188,800
- 56
- 490
- 992
-
Martin how i test that – Mohamed Ahmed Apr 25 '16 at 12:00
-
1st test: Just run the created task manually from Windows Scheduler. If that works, 2nd test: Re-install and move the clock to the future, just a minute before the schedule time and wait. The same as with [inno setup create application valid for one year](http://stackoverflow.com/q/36823585/850848). – Martin Prikryl Apr 25 '16 at 12:15
-
sorry martin can you explain how ? – Mohamed Ahmed Apr 25 '16 at 13:41
-
1st test what is Windows Scheduler. – Mohamed Ahmed Apr 25 '16 at 13:56
-
In *Control Panel*, go to *System and Security > Administrative Tools > Schedule Tasks*. See https://en.wikipedia.org/wiki/Windows_Task_Scheduler and http://windows.microsoft.com/en-au/windows/schedule-task – Martin Prikryl Apr 25 '16 at 14:20
-
I can't find any Task has a relation with uninstall – Mohamed Ahmed Apr 25 '16 at 15:03
-
Yes after installed no task created.and sure I run the Schedule Tasks as administrator.its no log file created.I can print screen for Tasks Schedule and share it for you. – Mohamed Ahmed Apr 25 '16 at 15:28
-
You have to run the installer with `/log=C:\path\to\setup.log` switch. – Martin Prikryl Apr 25 '16 at 15:42
-
I can't find it but this what i'm doing ![valid XHTML][checkmark]. [checkmark]: http://postimg.org/image/ubgmzlwep/ Sorry i can't upload image in right way – Mohamed Ahmed Apr 28 '16 at 16:34
-
What you cannot find? You have add the `/LOG` to the `setup.exe` command line = meaning you have to run it manually yourself, not from the studio. Or you do not know where you `setup.exe` is or what? The option you set is compiler log, not installation log. In studio, you enable the installer log on "Compiler settings" page, the "Setup logging" option. You cannot specify a file name there. It logs to the `%TEMP%`. – Martin Prikryl Apr 28 '16 at 17:50