Skip to content

Commit

Permalink
feat: minimal search indexing script, config paths
Browse files Browse the repository at this point in the history
  • Loading branch information
he3als committed Jul 17, 2024
1 parent 438745e commit b5ef337
Show file tree
Hide file tree
Showing 7 changed files with 219 additions and 34 deletions.
7 changes: 6 additions & 1 deletion src/playbook/Configuration/atlas/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ##
##############################################################################################
Expand All @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ 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' ]

# Windows 11
- !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' ]

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1,24 +1,55 @@
@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" %*
exit /b
)

: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
Original file line number Diff line number Diff line change
@@ -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
93 changes: 93 additions & 0 deletions src/playbook/Executables/AtlasModules/Scripts/indexConf.cmd
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b5ef337

Please sign in to comment.