I want to use Inno Setup for my program installation and I need Inno Setup to create a task in Windows Task Scheduler to launch my program.exe
every time the internet connects.
I can do this manually, but I want Inno Setup do this by Schtasks
command.
This is my inno setup code(here):
#define MyAppName "Desktop"
#define MyAppVersion "2"
#define MyAppPublisher "MH"
#define MyAppExeName "Desktop.exe"
[Setup]
AppId={{EFBBA2D3-C6F0-4D3D-BBD5-5AF126C3E8E9}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppPublisher={#MyAppPublisher}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=setup 2
Compression=lzma
SolidCompression=yes
PrivilegesRequired=admin
[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
[Files]
Source: "E:\IdeaProjects\Desktop\Desktop.exe"; DestDir: "{app}"; Flags: ignoreversion
[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
[Run]
Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
Filename: "schtasks.exe"; \
Parameters: "/Create /TN MyTask /XML ""{tmp}\Task.xml"""; \
StatusMsg: "Scheduling task..."; BeforeInstall: CreateTaskXml
;Flags: runhidden;
[Code]
procedure CreateTaskXml;
var
TaskXml: string;
begin
TaskXml :=
'<?xml version="1.0"?>' + #13#10 +
'<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">'
+ #13#10 +
' <Triggers>' + #13#10 +
{ The EventTrigger here }
' <EventTrigger>' +
' <Enabled>true</Enabled>' +
' <Subscription><QueryList><Query Id="0" Path="Microsoft-Windows-NetworkProfile/Operational"><Select Path="Microsoft-Windows-NetworkProfile/Operational">*[System[Provider[@Name='Microsoft-Windows-NetworkProfile'] and EventID=10000]]</Select></Query></QueryList></Subscription>' +
' </EventTrigger>' +
' </Triggers>' + #13#10 +
{ ... }
' <Actions Context="Author">' + #13#10 +
' <Exec>' + #13#10 +
' <Command>' + ExpandConstant('{app}\{#MyAppExeName}') + '</Command>' + #13#10 +
' </Exec>' + #13#10 +
' </Actions>' + #13#10 +
'</Task>' + #13#10;
if SaveStringToFile(ExpandConstant('{tmp}\Task.xml'), TaskXml, False) then
begin
Log('Task XML successfully created');
end
else
begin
Log('Failed to create task XML');
end;
end;
Can you help me? Thanks.