diff --git a/installer/PowerToysSetupCustomActions/CustomAction.cpp b/installer/PowerToysSetupCustomActions/CustomAction.cpp index f72115d9b9..cf932f901b 100644 --- a/installer/PowerToysSetupCustomActions/CustomAction.cpp +++ b/installer/PowerToysSetupCustomActions/CustomAction.cpp @@ -221,22 +221,25 @@ UINT __stdcall CreateScheduledTaskCA(MSIHANDLE hInstall) { } // Run the task with the highest available privileges. - hr = pPrincipal->put_RunLevel(TASK_RUNLEVEL_HIGHEST); + hr = pPrincipal->put_RunLevel(TASK_RUNLEVEL_LUA); pPrincipal->Release(); ExitOnFailure(hr, "Cannot put principal run level: %x", hr); // ------------------------------------------------------ // Save the task in the PowerToys folder. - hr = pTaskFolder->RegisterTaskDefinition( - _bstr_t(wstrTaskName.c_str()), - pTask, - TASK_CREATE_OR_UPDATE, - _variant_t(username_domain), - _variant_t(), - TASK_LOGON_INTERACTIVE_TOKEN, - _variant_t(L""), - &pRegisteredTask); - ExitOnFailure(hr, "Error saving the Task : %x", hr); + { + _variant_t SDDL_FULL_ACCESS_FOR_EVERYONE = L"D:(A;;FA;;;WD)"; + hr = pTaskFolder->RegisterTaskDefinition( + _bstr_t(wstrTaskName.c_str()), + pTask, + TASK_CREATE_OR_UPDATE, + _variant_t(username_domain), + _variant_t(), + TASK_LOGON_INTERACTIVE_TOKEN, + SDDL_FULL_ACCESS_FOR_EVERYONE, + &pRegisteredTask); + ExitOnFailure(hr, "Error saving the Task : %x", hr); + } WcaLog(LOGMSG_STANDARD, "Scheduled task created for the current user."); diff --git a/src/runner/auto_start_helper.cpp b/src/runner/auto_start_helper.cpp index ac0d56d118..b979016ce3 100644 --- a/src/runner/auto_start_helper.cpp +++ b/src/runner/auto_start_helper.cpp @@ -1,6 +1,8 @@ #include "pch.h" #include "auto_start_helper.h" +#include "general_settings.h" + #include #include @@ -35,7 +37,7 @@ const DWORD USERNAME_DOMAIN_LEN = DNLEN + UNLEN + 2; // Domain Name + '\' + User Name + '\0' const DWORD USERNAME_LEN = UNLEN + 1; // User Name + '\0' -bool enable_auto_start_task_for_this_user() +bool create_auto_start_task_for_this_user(bool runEvelvated) { HRESULT hr = S_OK; @@ -217,8 +219,7 @@ bool enable_auto_start_task_for_this_user() hr = pPrincipal->put_LogonType(TASK_LOGON_INTERACTIVE_TOKEN); - // Run the task with the highest available privileges. - if (IsUserAnAdmin()) + if (runEvelvated) { hr = pPrincipal->put_RunLevel(_TASK_RUNLEVEL::TASK_RUNLEVEL_HIGHEST); } @@ -231,16 +232,19 @@ bool enable_auto_start_task_for_this_user() } // ------------------------------------------------------ // Save the task in the PowerToys folder. - hr = pTaskFolder->RegisterTaskDefinition( - _bstr_t(wstrTaskName.c_str()), - pTask, - TASK_CREATE_OR_UPDATE, - _variant_t(username_domain), - _variant_t(), - TASK_LOGON_INTERACTIVE_TOKEN, - _variant_t(L""), - &pRegisteredTask); - ExitOnFailure(hr, "Error saving the Task : %x", hr); + { + _variant_t SDDL_FULL_ACCESS_FOR_EVERYONE = L"D:(A;;FA;;;WD)"; + hr = pTaskFolder->RegisterTaskDefinition( + _bstr_t(wstrTaskName.c_str()), + pTask, + TASK_CREATE_OR_UPDATE, + _variant_t(username_domain), + _variant_t(), + TASK_LOGON_INTERACTIVE_TOKEN, + SDDL_FULL_ACCESS_FOR_EVERYONE, + &pRegisteredTask); + ExitOnFailure(hr, "Error saving the Task : %x", hr); + } LExit: if (pService) @@ -261,7 +265,7 @@ LExit: return (SUCCEEDED(hr)); } -bool disable_auto_start_task_for_this_user() +bool delete_auto_start_task_for_this_user() { HRESULT hr = S_OK; @@ -313,13 +317,7 @@ bool disable_auto_start_task_for_this_user() if (SUCCEEDED(hr)) { // Task exists, try disabling it. - hr = pExistingRegisteredTask->put_Enabled(VARIANT_FALSE); - pExistingRegisteredTask->Release(); - if (SUCCEEDED(hr)) - { - // Function disable. Sounds like a success. - ExitFunction(); - } + hr = pTaskFolder->DeleteTask(_bstr_t(wstrTaskName.c_str()), 0); } } diff --git a/src/runner/auto_start_helper.h b/src/runner/auto_start_helper.h index 3f09264dcc..fbadab553e 100644 --- a/src/runner/auto_start_helper.h +++ b/src/runner/auto_start_helper.h @@ -1,4 +1,5 @@ #pragma once + bool is_auto_start_task_active_for_this_user(); -bool enable_auto_start_task_for_this_user(); -bool disable_auto_start_task_for_this_user(); +bool create_auto_start_task_for_this_user(bool runEvelvated); +bool delete_auto_start_task_for_this_user(); diff --git a/src/runner/general_settings.cpp b/src/runner/general_settings.cpp index 5a16cd4071..134f2cc12f 100644 --- a/src/runner/general_settings.cpp +++ b/src/runner/general_settings.cpp @@ -115,6 +115,8 @@ json::JsonObject get_general_settings() void apply_general_settings(const json::JsonObject& general_configs) { + run_as_elevated = general_configs.GetNamedBoolean(L"run_elevated", false); + if (json::has(general_configs, L"startup", json::JsonValueType::Boolean)) { const bool startup = general_configs.GetNamedBoolean(L"startup"); @@ -124,18 +126,33 @@ void apply_general_settings(const json::JsonObject& general_configs) } else { - const bool current_startup = is_auto_start_task_active_for_this_user(); - if (current_startup != startup) + if (startup) { - if (startup) + if (is_process_elevated()) { - enable_auto_start_task_for_this_user(); + delete_auto_start_task_for_this_user(); + create_auto_start_task_for_this_user(general_configs.GetNamedBoolean(L"run_elevated", false)); } else { - disable_auto_start_task_for_this_user(); + if (!is_auto_start_task_active_for_this_user()) + { + delete_auto_start_task_for_this_user(); + create_auto_start_task_for_this_user(false); + + run_as_elevated = false; + } + else if (!general_configs.GetNamedBoolean(L"run_elevated", false)) + { + delete_auto_start_task_for_this_user(); + create_auto_start_task_for_this_user(false); + } } } + else + { + delete_auto_start_task_for_this_user(); + } } } if (json::has(general_configs, L"enabled")) @@ -169,7 +186,7 @@ void apply_general_settings(const json::JsonObject& general_configs) } } } - run_as_elevated = general_configs.GetNamedBoolean(L"run_elevated", false); + if (json::has(general_configs, L"theme", json::JsonValueType::String)) { settings_theme = general_configs.GetNamedString(L"theme"); diff --git a/src/settings-web/src/components/GeneralSettings.tsx b/src/settings-web/src/components/GeneralSettings.tsx index dfc774cae7..a7c33130c8 100644 --- a/src/settings-web/src/components/GeneralSettings.tsx +++ b/src/settings-web/src/components/GeneralSettings.tsx @@ -138,7 +138,8 @@ export class GeneralSettings extends React.Component { {this.state.settings.general.is_admin && ( {this.elevated_reference=input;}} />) diff --git a/src/settings/settings-html/dist/bundle.js b/src/settings/settings-html/dist/bundle.js index b4259a894d..a0523ac995 100644 --- a/src/settings/settings-html/dist/bundle.js +++ b/src/settings/settings-html/dist/bundle.js @@ -1,9 +1,9 @@ -!function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=35)}([function(e,t,n){"use strict";e.exports=n(26)},,,,,,,function(e,t,n){"use strict";!function e(){if("undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE){0;try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(e)}catch(e){console.error(e)}}}(),e.exports=n(27)},,,,,,,,,function(e,t,n){"use strict"; +!function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=34)}([function(e,t,n){"use strict";e.exports=n(25)},,,,,,,function(e,t,n){"use strict";!function e(){if("undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE){0;try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(e)}catch(e){console.error(e)}}}(),e.exports=n(26)},,,,,function(e,t,n){"use strict";var o={},r=void 0;try{r=window}catch(e){}function i(e,t){if(void 0!==r){var n=r.__packages__=r.__packages__||{};if(!n[e]||!o[e])o[e]=t,(n[e]=n[e]||[]).push(t)}}n.d(t,"a",(function(){return i})),i("@uifabric/set-version","6.0.0")},,,,function(e,t,n){"use strict"; /* object-assign (c) Sindre Sorhus @license MIT -*/var o=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable;function a(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}e.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var o={};return"abcdefghijklmnopqrst".split("").forEach((function(e){o[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},o)).join("")}catch(e){return!1}}()?Object.assign:function(e,t){for(var n,s,l=a(e),u=1;u0&&(!function(e){void 0===e&&(e=3);3!==e&&2!==e||(u(a.registeredStyles),a.registeredStyles=[]);3!==e&&1!==e||(u(a.registeredThemableStyles),a.registeredThemableStyles=[])}(1),s([].concat.apply([],e)))}}()}function u(e){e.forEach((function(e){var t=e&&e.styleElement;t&&t.parentElement&&t.parentElement.removeChild(t)}))}function c(e){var t=a.theme,n=!1;return{styleString:(e||[]).map((function(e){var o=e.theme;if(o){n=!0;var r=t?t[o]:void 0,i=e.defaultValue||"inherit";return!t||r||!console||o in t||"undefined"==typeof DEBUG||!DEBUG||console.warn('Theming value not provided for "'+o+'". Falling back to "'+i+'".'),r||i}return e.rawString})).join(""),themable:n}}}).call(this,n(17))},,,,,,,,function(e,t,n){"use strict"; +*/var o=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,i=Object.prototype.propertyIsEnumerable;function a(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}e.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},n=0;n<10;n++)t["_"+String.fromCharCode(n)]=n;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var o={};return"abcdefghijklmnopqrst".split("").forEach((function(e){o[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},o)).join("")}catch(e){return!1}}()?Object.assign:function(e,t){for(var n,s,l=a(e),u=1;u0&&(!function(e){void 0===e&&(e=3);3!==e&&2!==e||(u(a.registeredStyles),a.registeredStyles=[]);3!==e&&1!==e||(u(a.registeredThemableStyles),a.registeredThemableStyles=[])}(1),s([].concat.apply([],e)))}}()}function u(e){e.forEach((function(e){var t=e&&e.styleElement;t&&t.parentElement&&t.parentElement.removeChild(t)}))}function c(e){var t=a.theme,n=!1;return{styleString:(e||[]).map((function(e){var o=e.theme;if(o){n=!0;var r=t?t[o]:void 0,i=e.defaultValue||"inherit";return!t||r||!console||o in t||"undefined"==typeof DEBUG||!DEBUG||console.warn('Theming value not provided for "'+o+'". Falling back to "'+i+'".'),r||i}return e.rawString})).join(""),themable:n}}}).call(this,n(17))},,,,,,,function(e,t,n){"use strict"; /** @license React v16.8.6 * react.production.min.js * @@ -11,7 +11,7 @@ object-assign * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. - */var o=n(16),r="function"==typeof Symbol&&Symbol.for,i=r?Symbol.for("react.element"):60103,a=r?Symbol.for("react.portal"):60106,s=r?Symbol.for("react.fragment"):60107,l=r?Symbol.for("react.strict_mode"):60108,u=r?Symbol.for("react.profiler"):60114,c=r?Symbol.for("react.provider"):60109,d=r?Symbol.for("react.context"):60110,p=r?Symbol.for("react.concurrent_mode"):60111,f=r?Symbol.for("react.forward_ref"):60112,h=r?Symbol.for("react.suspense"):60113,m=r?Symbol.for("react.memo"):60115,g=r?Symbol.for("react.lazy"):60116,v="function"==typeof Symbol&&Symbol.iterator;function y(e){for(var t=arguments.length-1,n="https://reactjs.org/docs/error-decoder.html?invariant="+e,o=0;oD.length&&D.push(e)}function F(e,t,n){return null==e?0:function e(t,n,o,r){var s=typeof t;"undefined"!==s&&"boolean"!==s||(t=null);var l=!1;if(null===t)l=!0;else switch(s){case"string":case"number":l=!0;break;case"object":switch(t.$$typeof){case i:case a:l=!0}}if(l)return o(r,t,""===n?"."+O(t,0):n),1;if(l=0,n=""===n?".":n+":",Array.isArray(t))for(var u=0;uN.length&&N.push(e)}function F(e,t,n){return null==e?0:function e(t,n,o,r){var s=typeof t;"undefined"!==s&&"boolean"!==s||(t=null);var l=!1;if(null===t)l=!0;else switch(s){case"string":case"number":l=!0;break;case"object":switch(t.$$typeof){case i:case a:l=!0}}if(l)return o(r,t,""===n?"."+O(t,0):n),1;if(l=0,n=""===n?".":n+":",Array.isArray(t))for(var u=0;uthis.eventPool.length&&this.eventPool.push(e)}function pe(e){e.eventPool=[],e.getPooled=ce,e.release=de}r(ue.prototype,{preventDefault:function(){this.defaultPrevented=!0;var e=this.nativeEvent;e&&(e.preventDefault?e.preventDefault():"unknown"!=typeof e.returnValue&&(e.returnValue=!1),this.isDefaultPrevented=se)},stopPropagation:function(){var e=this.nativeEvent;e&&(e.stopPropagation?e.stopPropagation():"unknown"!=typeof e.cancelBubble&&(e.cancelBubble=!0),this.isPropagationStopped=se)},persist:function(){this.isPersistent=se},isPersistent:le,destructor:function(){var e,t=this.constructor.Interface;for(e in t)this[e]=null;this.nativeEvent=this._targetInst=this.dispatchConfig=null,this.isPropagationStopped=this.isDefaultPrevented=le,this._dispatchInstances=this._dispatchListeners=null}}),ue.Interface={type:null,target:null,currentTarget:function(){return null},eventPhase:null,bubbles:null,cancelable:null,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:null,isTrusted:null},ue.extend=function(e){function t(){}function n(){return o.apply(this,arguments)}var o=this;t.prototype=o.prototype;var i=new t;return r(i,n.prototype),n.prototype=i,n.prototype.constructor=n,n.Interface=r({},o.Interface,e),n.extend=o.extend,pe(n),n},pe(ue);var fe=ue.extend({data:null}),he=ue.extend({data:null}),me=[9,13,27,32],ge=G&&"CompositionEvent"in window,ve=null;G&&"documentMode"in document&&(ve=document.documentMode);var ye=G&&"TextEvent"in window&&!ve,be=G&&(!ge||ve&&8=ve),_e=String.fromCharCode(32),ke={beforeInput:{phasedRegistrationNames:{bubbled:"onBeforeInput",captured:"onBeforeInputCapture"},dependencies:["compositionend","keypress","textInput","paste"]},compositionEnd:{phasedRegistrationNames:{bubbled:"onCompositionEnd",captured:"onCompositionEndCapture"},dependencies:"blur compositionend keydown keypress keyup mousedown".split(" ")},compositionStart:{phasedRegistrationNames:{bubbled:"onCompositionStart",captured:"onCompositionStartCapture"},dependencies:"blur compositionstart keydown keypress keyup mousedown".split(" ")},compositionUpdate:{phasedRegistrationNames:{bubbled:"onCompositionUpdate",captured:"onCompositionUpdateCapture"},dependencies:"blur compositionupdate keydown keypress keyup mousedown".split(" ")}},xe=!1;function Ce(e,t){switch(e){case"keyup":return-1!==me.indexOf(t.keyCode);case"keydown":return 229!==t.keyCode;case"keypress":case"mousedown":case"blur":return!0;default:return!1}}function we(e){return"object"==typeof(e=e.detail)&&"data"in e?e.data:null}var Se=!1;var Ee={eventTypes:ke,extractEvents:function(e,t,n,o){var r=void 0,i=void 0;if(ge)e:{switch(e){case"compositionstart":r=ke.compositionStart;break e;case"compositionend":r=ke.compositionEnd;break e;case"compositionupdate":r=ke.compositionUpdate;break e}r=void 0}else Se?Ce(e,n)&&(r=ke.compositionEnd):"keydown"===e&&229===n.keyCode&&(r=ke.compositionStart);return r?(be&&"ko"!==n.locale&&(Se||r!==ke.compositionStart?r===ke.compositionEnd&&Se&&(i=ae()):(re="value"in(oe=o)?oe.value:oe.textContent,Se=!0)),r=fe.getPooled(r,t,n,o),i?r.data=i:null!==(i=we(n))&&(r.data=i),V(r),i=r):i=null,(e=ye?function(e,t){switch(e){case"compositionend":return we(t);case"keypress":return 32!==t.which?null:(xe=!0,_e);case"textInput":return(e=t.data)===_e&&xe?null:e;default:return null}}(e,n):function(e,t){if(Se)return"compositionend"===e||!ge&&Ce(e,t)?(e=ae(),ie=re=oe=null,Se=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1