Index: scripts/setup.iss =================================================================== diff -u -ra27d1acf1bda3c25b6dcce0d0eb0278009ce63ae -r694e362bf3ce049a7bbba8b4cf442d07e6741901 --- scripts/setup.iss (.../setup.iss) (revision a27d1acf1bda3c25b6dcce0d0eb0278009ce63ae) +++ scripts/setup.iss (.../setup.iss) (revision 694e362bf3ce049a7bbba8b4cf442d07e6741901) @@ -123,10 +123,9 @@ Filename: "{app}\{code:ExpandArch|ExeFilename}"; Flags: nowait postinstall skipifsilent; Description: "{cm:LaunchProgram,{#MyAppName}}" [Registry] +Root: "HKLM"; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; ValueType: none; ValueName: "Copy Handler"; Flags: deletevalue uninsdeletevalue +Root: "HKCU"; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; ValueType: none; ValueName: "Copy Handler"; Flags: uninsdeletevalue -Root: HKLM; Subkey: SOFTWARE\Microsoft\Windows\CurrentVersion\Run; ValueType: string; ValueName: Copy Handler; Flags: dontcreatekey deletevalue -Root: HKCU; Subkey: SOFTWARE\Microsoft\Windows\CurrentVersion\Run; ValueType: string; ValueName: Copy Handler; Tasks: startatboot; ValueData: {app}\{code:ExpandArch|ExeFilename}; Flags: uninsdeletevalue - [Dirs] Name: {app}\help; Flags: uninsalwaysuninstall Name: {app}\langs; Flags: uninsalwaysuninstall @@ -160,3 +159,16 @@ end; end; end; + +procedure CurStepChanged(CurStep: TSetupStep); +var + ResultCode: Integer; +begin + if CurStep = ssPostInstall then + begin + if IsTaskSelected('startatboot') then + ExecAsOriginalUser(ExpandConstant('{app}\{code:ExpandArch|ExeFilename}'), '--EnableLaunchAtStartup=1', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) + else + ExecAsOriginalUser(ExpandConstant('{app}\{code:ExpandArch|ExeFilename}'), '--EnableLaunchAtStartup=0', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) + end; +end; Index: src/ch/TCommandLineParser.cpp =================================================================== diff -u -r73583f2ca01fa1b2eae49bbc63bce46b9ecff5db -r694e362bf3ce049a7bbba8b4cf442d07e6741901 --- src/ch/TCommandLineParser.cpp (.../TCommandLineParser.cpp) (revision 73583f2ca01fa1b2eae49bbc63bce46b9ecff5db) +++ src/ch/TCommandLineParser.cpp (.../TCommandLineParser.cpp) (revision 694e362bf3ce049a7bbba8b4cf442d07e6741901) @@ -44,7 +44,8 @@ po::options_description desc(""); desc.add_options() - ("ImportTaskDefinition", po::wvalue< std::vector >(), ""); + ("ImportTaskDefinition", po::wvalue< std::vector >(), "") + ("EnableLaunchAtStartup", po::wvalue(), ""); po::variables_map vm; po::store(po::wcommand_line_parser(args).options(desc).run(), m_mapVariables); @@ -74,3 +75,14 @@ } } } + +bool TCommandLineParser::HasSystemStartupOption() const +{ + return m_mapVariables.count("EnableLaunchAtStartup") == 1; +} + +bool TCommandLineParser::IsSystemStartupEnabled() const +{ + bool bValue = m_mapVariables["EnableLaunchAtStartup"].as(); + return bValue; +} Index: src/ch/TCommandLineParser.h =================================================================== diff -u -r358a488269fd82d5d2566c407b95c4d519c5065e -r694e362bf3ce049a7bbba8b4cf442d07e6741901 --- src/ch/TCommandLineParser.h (.../TCommandLineParser.h) (revision 358a488269fd82d5d2566c407b95c4d519c5065e) +++ src/ch/TCommandLineParser.h (.../TCommandLineParser.h) (revision 694e362bf3ce049a7bbba8b4cf442d07e6741901) @@ -43,6 +43,10 @@ bool HasTaskDefinitionPath() const; void GetTaskDefinitionPaths(chcore::TPathContainer& vPaths) const; + // enable run at system startup + bool HasSystemStartupOption() const; + bool IsSystemStartupEnabled() const; + private: boost::program_options::variables_map m_mapVariables; }; Index: src/ch/ch.cpp =================================================================== diff -u -r8dc649003961dad64b92da67426814fb5dd862e0 -r694e362bf3ce049a7bbba8b4cf442d07e6741901 --- src/ch/ch.cpp (.../ch.cpp) (revision 8dc649003961dad64b92da67426814fb5dd862e0) +++ src/ch/ch.cpp (.../ch.cpp) (revision 694e362bf3ce049a7bbba8b4cf442d07e6741901) @@ -363,6 +363,17 @@ EnableHtmlHelp(); + // ================================= Handle early command line options ======================================== + if(m_cmdLineParser.HasCommandLineParams() && m_cmdLineParser.HasSystemStartupOption()) + { + SetPropValue(rCfg, m_cmdLineParser.IsSystemStartupEnabled()); + rCfg.Write(); + + SetAutorun(GetPropValue(rCfg)); + + return FALSE; + } + // ================================= Checking for running instances of CH ======================================== // check instance - return false if it's the second one LOG_INFO(_T("Checking for other running instances of Copy Handler"));