From b5ef337fc9109bd1583b5176e45fb333e9cfa8af Mon Sep 17 00:00:00 2001 From: he3als <65787561+he3als@users.noreply.github.com> Date: Wed, 17 Jul 2024 19:22:42 +0100 Subject: [PATCH] feat: minimal search indexing script, config paths --- src/playbook/Configuration/atlas/services.yml | 7 +- .../tweaks/qol/set-hidden-settings-pages.yml | 4 +- .../Disable Search Indexing (default).cmd | 21 ----- .../Disable Search Indexing.cmd | 34 +++++++ .../Enable Search Indexing.cmd | 51 ++++++++-- .../Minimal Search Indexing (default).cmd | 43 +++++++++ .../AtlasModules/Scripts/indexConf.cmd | 93 +++++++++++++++++++ 7 files changed, 219 insertions(+), 34 deletions(-) delete mode 100644 src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Disable Search Indexing (default).cmd create mode 100644 src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Disable Search Indexing.cmd create mode 100644 src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Minimal Search Indexing (default).cmd create mode 100644 src/playbook/Executables/AtlasModules/Scripts/indexConf.cmd diff --git a/src/playbook/Configuration/atlas/services.yml b/src/playbook/Configuration/atlas/services.yml index 1d7cf59d21..b014be4ee0 100644 --- a/src/playbook/Configuration/atlas/services.yml +++ b/src/playbook/Configuration/atlas/services.yml @@ -33,6 +33,12 @@ actions: exeDir: true wait: true + - !writeStatus: {status: 'Configuring Indexing'} + - !cmd: + command: '"AtlasDesktop\3. General Configuration\Search Indexing\Minimal Search Indexing (default).cmd" /silent' + exeDir: true + wait: true + ############################################################################################## ## SERVICES ## ############################################################################################## @@ -44,7 +50,6 @@ actions: - !service: {name: 'TrkWks', operation: change, startup: 4} - !service: {name: 'PcaSvc', operation: change, startup: 4} - !service: {name: 'DiagTrack', operation: change, startup: 4} - - !service: {name: 'WSearch', operation: change, startup: 4} # ------ Microsoft recommendation - 'Do not disable' ----- - !service: {name: 'diagnosticshub.standardcollector.service', operation: change, startup: 4} diff --git a/src/playbook/Configuration/tweaks/qol/set-hidden-settings-pages.yml b/src/playbook/Configuration/tweaks/qol/set-hidden-settings-pages.yml index 92101bb5f1..4f1b5023a0 100644 --- a/src/playbook/Configuration/tweaks/qol/set-hidden-settings-pages.yml +++ b/src/playbook/Configuration/tweaks/qol/set-hidden-settings-pages.yml @@ -8,7 +8,7 @@ actions: - !registryValue: path: 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer' value: 'SettingsPageVisibility' - data: 'hide:recovery;maps;maps-downloadmaps;privacy;privacy-speechtyping;privacy-speech;privacy-feedback;privacy-activityhistory;search-permissions;privacy-general;sync;cortana-windowssearch;mobile-devices;mobile-devices-addphone;workplace;backup' + data: 'hide:recovery;maps;maps-downloadmaps;privacy;privacy-speechtyping;privacy-speech;privacy-feedback;privacy-activityhistory;search-permissions;privacy-general;sync;mobile-devices;mobile-devices-addphone;workplace;backup' type: REG_SZ builds: [ '<22000' ] @@ -16,6 +16,6 @@ actions: - !registryValue: path: 'HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\Explorer' value: 'SettingsPageVisibility' - data: 'hide:recovery;maps;maps-downloadmaps;privacy;privacy-feedback;privacy-activityhistory;search-permissions;privacy-general;sync;cortana-windowssearch;mobile-devices;mobile-devices-addphone;workplace;family-group;deviceusage;home' + data: 'hide:recovery;maps;maps-downloadmaps;privacy;privacy-feedback;privacy-activityhistory;search-permissions;privacy-general;sync;mobile-devices;mobile-devices-addphone;workplace;family-group;deviceusage;home' type: REG_SZ builds: [ '>=22000' ] diff --git a/src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Disable Search Indexing (default).cmd b/src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Disable Search Indexing (default).cmd deleted file mode 100644 index 0472a83005..0000000000 --- a/src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Disable Search Indexing (default).cmd +++ /dev/null @@ -1,21 +0,0 @@ -@echo off -setlocal EnableDelayedExpansion - -set "___args="%~f0" %*" -fltmc > nul 2>&1 || ( - echo Administrator privileges are required. - powershell -c "Start-Process -Verb RunAs -FilePath 'cmd' -ArgumentList """/c $env:___args"""" 2> nul || ( - echo You must run this script as admin. - if "%*"=="" pause - exit /b 1 - ) - exit /b -) - -sc config WSearch start=disabled > nul -sc stop WSearch > nul 2>&1 -call "%windir%\AtlasModules\Scripts\settingsPages.cmd" /hide cortana-windowssearch - -echo Finished. -pause -exit /b \ No newline at end of file diff --git a/src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Disable Search Indexing.cmd b/src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Disable Search Indexing.cmd new file mode 100644 index 0000000000..eba745911c --- /dev/null +++ b/src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Disable Search Indexing.cmd @@ -0,0 +1,34 @@ +@echo off +setlocal EnableDelayedExpansion +set indexConfPath="%windir%\AtlasModules\Scripts\indexConf.cmd" +if not exist %indexConfPath% ( + echo The 'indexConf.cmd' script wasn't found in AtlasModules. + if "%~1"=="" pause + exit /b 1 +) +set "indexConf=call %indexConfPath%" + +if "%~1" neq "" goto main +set "___args="%~f0" %*" +fltmc > nul 2>&1 || ( + echo Administrator privileges are required. + powershell -c "Start-Process -Verb RunAs -FilePath 'cmd' -ArgumentList """/c $env:___args"""" 2> nul || ( + echo You must run this script as admin. + if "%*"=="" pause + exit /b 1 + ) + exit /b +) + +:main +echo =================================== +echo Disabling search indexing... +echo =================================== +echo] + +%indexConf% /stop + +echo] +echo Finished. +if "%~1" neq "/silent" pause +exit /b \ No newline at end of file diff --git a/src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Enable Search Indexing.cmd b/src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Enable Search Indexing.cmd index e13ba204d1..e63005adb7 100644 --- a/src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Enable Search Indexing.cmd +++ b/src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Enable Search Indexing.cmd @@ -1,7 +1,14 @@ @echo off setlocal EnableDelayedExpansion -if "%~1"=="/silent" goto main +set indexConfPath="%windir%\AtlasModules\Scripts\indexConf.cmd" +if not exist %indexConfPath% ( + echo The 'indexConf.cmd' script wasn't found in AtlasModules. + if "%~1"=="" pause + exit /b 1 +) +set "indexConf=call %indexConfPath%" +if "%~1" neq "" goto main :: TI required for RespectPowerModes whoami /user | find /i "S-1-5-18" > nul 2>&1 || ( call RunAsTI.cmd "%~f0" %* @@ -9,16 +16,40 @@ whoami /user | find /i "S-1-5-18" > nul 2>&1 || ( ) :main -( - sc config WSearch start=auto - sc start WSearch -) > nul -call "%windir%\AtlasModules\Scripts\settingsPages.cmd" /unhide cortana-windowssearch +echo =================================== +echo Enabling search indexing... +echo =================================== +echo] + +%indexConf% /stop + +%indexConf% /cleanpolicies +%indexConf% /include "%programdata%\Microsoft\Windows\Start Menu\Programs" +:: The Atlas folder is so that if the user searches for a Atlas-modified feature, a script shows up in search +%indexConf% /include "%windir%\AtlasDesktop" +%indexConf% /include "%systemdrive%\Users" +:: Add default user exclusions +for /f "usebackq delims=" %%a in (`dir /b /a:d "%SystemDrive%\Users"`) do ( + for %%z in ( + "AppData" + "MicrosoftEdgeBackups" + ) do ( + if exist "%SystemDrive%\Users\%%~a\%%~z" %indexConf% /exclude "%SystemDrive%\Users\%%~a\%%~z" + ) +) + +%indexConf% /start +reg add "HKLM\SOFTWARE\Microsoft\Windows Search" /v SetupCompletedSuccessfully /t REG_DWORD /d 0 /f > nul + +set regCmd=^>nul reg add "HKLM\Software\Microsoft\Windows Search\Gather\Windows\SystemIndex" /v "RespectPowerModes" /t REG_DWORD /d +if "%~1"=="/silent" (%regCmd% "0" /f & exit /b) -:: Respect Power Settings when Search Indexing to prevent performance loss during gaming or other high-performance tasks -reg add "HKLM\Software\Microsoft\Windows Search\Gather\Windows\SystemIndex" /v "RespectPowerModes" /t REG_DWORD /d "1" /f +echo] +:: Respect Power Settings when Search Indexing to prevent performance loss during gaming or battery drain +choice /c:yn /n /m "Would you like to have indexing disable its self when on battery or gaming? [Y/N] " +if %errorlevel%==1 %regCmd% "1" /f +if %errorlevel%==2 %regCmd% "0" /f -if "%~1"=="/silent" exit /b -echo Finished, please reboot your device for changes to apply. +echo Finished, there might be some CPU usage for a period while indexing. pause exit /b \ No newline at end of file diff --git a/src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Minimal Search Indexing (default).cmd b/src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Minimal Search Indexing (default).cmd new file mode 100644 index 0000000000..4ef092257e --- /dev/null +++ b/src/playbook/Executables/AtlasDesktop/3. General Configuration/Search Indexing/Minimal Search Indexing (default).cmd @@ -0,0 +1,43 @@ +@echo off +setlocal EnableDelayedExpansion +set indexConfPath="%windir%\AtlasModules\Scripts\indexConf.cmd" +if not exist %indexConfPath% ( + echo The 'indexConf.cmd' script wasn't found in AtlasModules. + if "%~1"=="" pause + exit /b 1 +) +set "indexConf=call %indexConfPath%" + +if "%~1" neq "" goto main +:: TI required for RespectPowerModes +whoami /user | find /i "S-1-5-18" > nul 2>&1 || ( + call RunAsTI.cmd "%~f0" %* + exit /b +) + +:main +echo =================================== +echo Making search indexing minimal... +echo This means no user folder indexing. +echo =================================== +echo] + +%indexConf% /stop + +%indexConf% /cleanpolicies +:: Add only the Start Menu and AtlasDesktop paths by default +:: The Atlas folder is so that if the user searches for a Atlas-modified feature, a script shows up in search +%indexConf% /include "%programdata%\Microsoft\Windows\Start Menu\Programs" +%indexConf% /include "%windir%\AtlasDesktop" +%indexConf% /exclude "%systemdrive%\Users" + +:: Respect Power Settings when Search Indexing to prevent performance loss during gaming or battery drain +reg add "HKLM\Software\Microsoft\Windows Search\Gather\Windows\SystemIndex" /v "RespectPowerModes" /t REG_DWORD /d 1 /f > nul + +%indexConf% /start +reg add "HKLM\SOFTWARE\Microsoft\Windows Search" /v SetupCompletedSuccessfully /t REG_DWORD /d 0 /f > nul + +echo] +echo Finished, there might be some CPU usage for a very small period while indexing. +if "%~1" neq "/silent" pause +exit /b \ No newline at end of file diff --git a/src/playbook/Executables/AtlasModules/Scripts/indexConf.cmd b/src/playbook/Executables/AtlasModules/Scripts/indexConf.cmd new file mode 100644 index 0000000000..0f6aec85a7 --- /dev/null +++ b/src/playbook/Executables/AtlasModules/Scripts/indexConf.cmd @@ -0,0 +1,93 @@ +@echo off + +fltmc > nul 2>&1 || (echo You must run this script as admin. & exit /b) +set ___settings=call "%windir%\AtlasModules\Scripts\settingsPages.cmd" + + +:: Check args +set ___policy= +if "%~1"=="" goto help +echo %1 | find "clude" > nul && ( + if "%~2"=="" goto help + set ___policy=true +) + +:: /include & /exclude +if defined ___policy ( + call :addIndexPath %~1 "%~2" +) + +if "%~1"=="/cleanpolicies" ( + echo Cleaning policies... + for %%a in ( + "HKLM\Software\Policies\Microsoft\Windows\Windows Search\DefaultExcludedPaths" + "HKLM\Software\Policies\Microsoft\Windows\Windows Search\DefaultIndexedPaths" + "HKLM\Software\Microsoft\Windows Search\CurrentPolicies\DefaultExcludedPaths" + "HKLM\Software\Microsoft\Windows Search\CurrentPolicies\DefaultIndexedPaths" + ) do ( + reg delete %%a /f > nul 2>&1 + reg add %%a /f > nul + ) +) + +if "%~1"=="/start" ( + echo Starting the indexer... + sc config WSearch start=delayed-auto > nul + sc start WSearch > nul + + %___settings% /unhide cortana-windowssearch + + echo Updating policy... ^(this might take a moment^) + gpupdate > nul +) + +if "%~1"=="/stop" ( + echo Stopping the indexer... + + %___settings% /hide cortana-windowssearch + + rem Kill the search index Control Panel pane + powershell -NoP -NonI -C "Stop-Process -Id (gcim Win32_Process | ? { $_.CommandLine -match 'srchadmin.dll' }).ProcessId -Force" + + sc config WSearch start=disabled > nul + sc stop WSearch > nul 2>&1 +) + +exit /b + + + +:help + echo You must use one (not in combination) + echo ------------------------------------- + echo /include [full folder path] + echo /exclude [full folder path] + echo /cleanpolicies + echo /start + echo /stop + exit /b + + +:addIndexPath + echo Configuring indexer path... + set policy=DefaultIndexedPaths + if "%~1"=="/exclude" set policy=DefaultExcludedPaths + + set "searchPath1=%~2" + set "searchPath=file:///%searchPath1%\*" + reg add "HKLM\Software\Policies\Microsoft\Windows\Windows Search\%policy%" /v "%searchPath%" /t REG_SZ /d "%searchPath%" /f > nul + reg add "HKLM\Software\Microsoft\Windows Search\CurrentPolicies\%policy%" /v "%searchPath%" /t REG_SZ /d "%searchPath%" /f > nul + exit /b + + +:cleanPolicies + for %%a in ( + "HKLM\Software\Policies\Microsoft\Windows\Windows Search\DefaultExcludedPaths" + "HKLM\Software\Policies\Microsoft\Windows\Windows Search\DefaultIndexedPaths" + "HKLM\Software\Microsoft\Windows Search\CurrentPolicies\DefaultExcludedPaths" + "HKLM\Software\Microsoft\Windows Search\CurrentPolicies\DefaultIndexedPaths" + ) do ( + reg delete %%a /f > nul 2>&1 + reg add %%a /f > nul 2>&1 + ) + exit /b