schtasks.exe - How to add a scheduled task on network connection/disconnection event with Inno Setup -


i want use inno setup program installation , need inno setup create task in windows task scheduler launch program.exe every time internet connects.

i can do manually, want inno setup schtasks command. 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 +     { 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'] , 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)   begin     log('task xml created');   end     else   begin     log('failed create task xml');   end; end; 

can me? thanks.

as other obscure scheduling settings, have use xml definition of task.

the easiest configure task in windows task scheduler gui, select created task , choose export command.

it create xml definition of task, contain like:

<?xml version="1.0" encoding="utf-16"?> <task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">   <!-- ... -->   <triggers>     <eventtrigger>       <enabled>true</enabled>       <subscription>&lt;querylist&gt;&lt;query id="0" path="microsoft-windows-networkprofile/operational"&gt;&lt;select path="microsoft-windows-networkprofile/operational"&gt;*[system[provider[@name='networkprofile'] , eventid=10000]]&lt;/select&gt;&lt;/query&gt;&lt;/querylist&gt;</subscription>     </eventtrigger>   </triggers>   <!-- ... --> </task> 

edit xml remove everything, specific computer.

and use exported xml template file, create on fly in installer actual path installed application:

[run] filename: "schtasks.exe"; \     parameters: "/create /tn mytask /xml ""{tmp}\task.xml"""; \     statusmsg: "scheduling task..."; flags: runhidden; beforeinstall: createtaskxml  [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 +     { eventtrigger here }     '  </triggers>' + #13#10 +     { ... }     '  <actions context="author">' + #13#10 +     '    <exec>' + #13#10 +     '      <command>' + expandconstant('{app}\myprog.exe') + '</command>' + #13#10 +     '    </exec>' + #13#10 +     '  </actions>' + #13#10 +     '</task>' + #13#10;    if savestringtofile(expandconstant('{tmp}\task.xml'), taskxml, false)   begin     log('task xml created');   end     else   begin     log('failed create task xml');   end; end; 

the savestringtofile function in createtaskxml creates xml in ansi encoding. if need unicode, have create xml in utf-16 encoding (schtasks not support utf-8).


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -