Skip to content

Commit 8b20519

Browse files
committed
feat: added StoreFixed.exe to playbook
1 parent 229d6ac commit 8b20519

3 files changed

Lines changed: 18 additions & 350 deletions

File tree

src/playbook/Configuration/atlas/revert.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ privilege: TrustedInstaller
55
onUpgrade: true
66
actions:
77
- !writeStatus: { status: "Reverting old changes" }
8-
- !powerShell:
9-
command: |
10-
$windir = [Environment]::GetFolderPath('Windows')
11-
Start-Process -FilePath """$windir\AtlasDesktop\9. Troubleshooting\Fix MS Store Issues.cmd"""-ArgumentList "/silent" -WindowStyle Hidden
8+
- !run:
9+
exe: "%windir%\\AtlasModules\\Tools\\StoreFixer.exe"
10+
args: "silent"
1211
weight: 2
1312
wait: true
1413
exeDir: true
Lines changed: 15 additions & 346 deletions
Original file line numberDiff line numberDiff line change
@@ -1,348 +1,17 @@
1-
<# : batch section
2-
@echo off & setlocal enabledelayedexpansion
3-
4-
:: Check if running as TrustedInstaller
5-
whoami /user | find /i "S-1-5-18" > nul 2>&1 && goto :main
6-
7-
sc query GamingServices >nul 2>&1
8-
if %errorlevel% equ 0 (
9-
echo === Checking Gaming Services ===
10-
echo Gaming Services is installed, removing...
11-
winget uninstall 9MWPM2CQNLHN --silent
12-
echo Gaming Services removed.
1+
@echo off
2+
cd /d "%~dp0"
3+
echo Current directory: %cd%
4+
echo Looking for: %cd%StoreFixer.exe
5+
6+
if not exist "StoreFixer.exe" (
7+
echo ERROR: StoreFixer.exe not found!
8+
echo Please ensure StoreFixer.exe is in the same directory as this script.
9+
pause
10+
exit /b 1
11+
)
12+
if "%~1"=="/silent" (
13+
call RunAsTI.cmd "%windir%\AtlasModules\Tools\StoreFixer.exe" silent -wait
14+
exit 0
1315
)
1416

15-
call %SYSTEMROOT%\AtlasModules\Scripts\RunAsTI.cmd "%~f0" %*
16-
exit /b
17-
18-
:main
19-
start /wait "Fix Store Issues" powershell -NoProfile -ExecutionPolicy Bypass -Command "iex((gc '%~f0' -Raw))"
20-
exit /b
21-
#>
22-
23-
# ======================== PowerShell ========================
24-
Add-Type -MemberDefinition @"
25-
[DllImport("kernel32.dll", SetLastError = true)]
26-
public static extern IntPtr GetStdHandle(int nStdHandle);
27-
[DllImport("kernel32.dll", SetLastError = true)]
28-
public static extern bool GetConsoleMode(IntPtr hConsoleHandle, out uint lpMode);
29-
[DllImport("kernel32.dll", SetLastError = true)]
30-
public static extern bool SetConsoleMode(IntPtr hConsoleHandle, uint dwMode);
31-
"@ -Name "Console" -Namespace "Win32" -PassThru | Out-Null
32-
33-
$handle = [Win32.Console]::GetStdHandle(-10) # STD_INPUT_HANDLE
34-
$mode = 0
35-
[void][Win32.Console]::GetConsoleMode($handle, [ref]$mode)
36-
$mode = $mode -band (-bnot 0x0040) # Remove ENABLE_QUICK_EDIT_MODE
37-
[void][Win32.Console]::SetConsoleMode($handle, $mode)
38-
39-
$Desktop = (Get-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' -Name 'Common Desktop').'Common Desktop'
40-
$LogFile = "$Desktop\fixStoreIssues.txt"
41-
Start-Transcript -Path $LogFile -Force | Out-Null
42-
43-
$Silent = $env:SILENT -eq '1'
44-
45-
$TargetFile = 'C:\ProgramData\Microsoft\Windows\AppRepository\StateRepository-Deployment.srd'
46-
$RootServices = @('ClipSVC', 'AppXSvc', 'StateRepository')
47-
$MaxRetries = 5
48-
$FileDeleted = $false
49-
50-
function Get-AllDependents {
51-
param([string]$ServiceName)
52-
53-
$result = [System.Collections.Generic.HashSet[string]]::new(
54-
[StringComparer]::OrdinalIgnoreCase
55-
)
56-
57-
$queue = [System.Collections.Generic.Queue[string]]::new()
58-
$queue.Enqueue($ServiceName)
59-
60-
while ($queue.Count -gt 0) {
61-
$current = $queue.Dequeue()
62-
$deps = Get-Service -Name $current -ErrorAction SilentlyContinue |
63-
Select-Object -ExpandProperty DependentServices
64-
65-
foreach ($dep in $deps) {
66-
if ($result.Add($dep.Name)) {
67-
$queue.Enqueue($dep.Name)
68-
}
69-
}
70-
}
71-
72-
return $result
73-
}
74-
75-
# ============================================================
76-
# Retry loop: Attempt file deletion up to 5 times
77-
# ============================================================
78-
for ($attempt = 1; $attempt -le $MaxRetries; $attempt++) {
79-
if ($attempt -gt 1) {
80-
Write-Host "`n=== RETRY ATTEMPT $attempt of $MaxRetries ===" -ForegroundColor Yellow
81-
Write-Host "Waiting 5 seconds before retry..." -ForegroundColor Yellow
82-
Start-Sleep -Seconds 5
83-
}
84-
else {
85-
Write-Host "`n=== ATTEMPT $attempt of $MaxRetries ===" -ForegroundColor Cyan
86-
}
87-
88-
# ============================================================
89-
# 1. Collect every service and save original start types
90-
# ============================================================
91-
Write-Host "`n=== Collecting services and saving original start types ===" -ForegroundColor Cyan
92-
Write-Host "DO NOT CLOSE THIS SCRIPT!!!!" -ForegroundColor Red
93-
94-
$allServiceNames = [System.Collections.Generic.HashSet[string]]::new(
95-
[StringComparer]::OrdinalIgnoreCase
96-
)
97-
98-
try {
99-
foreach ($root in $RootServices) {
100-
$rootService = Get-Service -Name $root -ErrorAction Stop
101-
[void]$allServiceNames.Add($root)
102-
foreach ($dep in (Get-AllDependents $root)) {
103-
[void]$allServiceNames.Add($dep)
104-
}
105-
}
106-
}
107-
catch {
108-
Write-Host "ERROR: Failed to enumerate services: $($_.Exception.Message)" -ForegroundColor Red
109-
if ($attempt -lt $MaxRetries) { continue }
110-
}
111-
112-
$originalStartTypes = @{}
113-
try {
114-
foreach ($svc in $allServiceNames) {
115-
$startType = (Get-Service -Name $svc -ErrorAction Stop).StartType
116-
$originalStartTypes[$svc] = $startType
117-
Write-Host " $svc -> StartType = $startType"
118-
}
119-
}
120-
catch {
121-
Write-Host "ERROR: Failed to get service start types: $($_.Exception.Message)" -ForegroundColor Red
122-
if ($attempt -lt $MaxRetries) { continue }
123-
}
124-
125-
$hasFailed = $false
126-
127-
try {
128-
129-
# ========================================================
130-
# 2. Disable every service
131-
# ========================================================
132-
Write-Host "`n=== Disabling all services ===" -ForegroundColor Cyan
133-
134-
$setSvc = "$env:SYSTEMROOT\AtlasModules\Scripts\setSvc.cmd"
135-
136-
foreach ($svc in $allServiceNames) {
137-
try {
138-
& $setSvc $svc 4 2>&1 | Out-Null
139-
if ($LASTEXITCODE -ne 0) { throw "setSvc.cmd returned exit code $LASTEXITCODE" }
140-
Write-Host " Disabled: $svc"
141-
}
142-
catch {
143-
Write-Host " Warning: Failed to disable $svc - $($_.Exception.Message)" -ForegroundColor Yellow
144-
}
145-
}
146-
147-
# ========================================================
148-
# 3. Stop every service — dependents first, then roots
149-
# ========================================================
150-
Write-Host "`n=== Stopping all services ===" -ForegroundColor Cyan
151-
152-
$dependentsOnly = $allServiceNames | Where-Object { $_ -notin $RootServices }
153-
154-
foreach ($name in $dependentsOnly) {
155-
$s = Get-Service -Name $name -ErrorAction SilentlyContinue
156-
if ($null -eq $s -or $s.Status -eq 'Stopped') { continue }
157-
Write-Host " Stopping dependent: $name ..."
158-
try {
159-
$s.Stop()
160-
$s.WaitForStatus('Stopped', [TimeSpan]::FromSeconds(3))
161-
Write-Host " STOPPED: $name"
162-
} catch {
163-
Write-Host " Warning: Could not stop $name" -ForegroundColor Yellow
164-
}
165-
}
166-
167-
foreach ($name in $RootServices) {
168-
$s = Get-Service -Name $name -ErrorAction SilentlyContinue
169-
if ($null -eq $s -or $s.Status -eq 'Stopped') { continue }
170-
Write-Host " Stopping root service: $name ..."
171-
try {
172-
$s.Stop()
173-
$s.WaitForStatus('Stopped', [TimeSpan]::FromSeconds(3))
174-
Write-Host " STOPPED: $name"
175-
} catch {
176-
Write-Host " Warning: Could not stop $name" -ForegroundColor Yellow
177-
}
178-
}
179-
180-
Write-Host " Waiting for services to stabilize ..."
181-
Start-Sleep -Seconds 2
182-
183-
# ========================================================
184-
# 4. Delete the target file
185-
# ========================================================
186-
Write-Host "`n=== Attempting file deletion ===" -ForegroundColor Cyan
187-
188-
if (Test-Path -LiteralPath $TargetFile) {
189-
try {
190-
Remove-Item -LiteralPath $TargetFile -Force -ErrorAction Stop
191-
Write-Host " Deleted: $TargetFile" -ForegroundColor Green
192-
$FileDeleted = $true
193-
}
194-
catch {
195-
Write-Host " ERROR: Could not delete file - $($_.Exception.Message)" -ForegroundColor Red
196-
throw $_
197-
}
198-
}
199-
else {
200-
Write-Host " File not found (already absent): $TargetFile" -ForegroundColor Yellow
201-
$FileDeleted = $true
202-
}
203-
204-
}
205-
catch {
206-
Write-Host "`nERROR: $($_.Exception.Message)" -ForegroundColor Red
207-
$hasFailed = $true
208-
}
209-
finally {
210-
211-
# ========================================================
212-
# 5. ALWAYS restore original start types
213-
# ========================================================
214-
Write-Host "`n=== Restoring original start types ===" -ForegroundColor Cyan
215-
216-
$startTypeMap = @{
217-
'Automatic' = 2
218-
'Manual' = 3
219-
'Disabled' = 4
220-
'Boot' = 0
221-
'System' = 1
222-
}
223-
224-
$setSvc = "$env:SYSTEMROOT\AtlasModules\Scripts\setSvc.cmd"
225-
226-
foreach ($svc in $allServiceNames) {
227-
try {
228-
$origValue = $originalStartTypes[$svc]
229-
$startValue = $startTypeMap[$origValue.ToString()]
230-
if ($null -eq $startValue) {
231-
Write-Host " Warning: Unknown start type for ${svc}: '$origValue'" -ForegroundColor Yellow
232-
continue
233-
}
234-
& $setSvc $svc $startValue 2>&1 | Out-Null
235-
if ($LASTEXITCODE -eq 0) {
236-
Write-Host " Restored: $svc -> $origValue"
237-
}
238-
}
239-
catch {
240-
Write-Host " Warning: Failed to restore $svc" -ForegroundColor Yellow
241-
}
242-
}
243-
244-
# ========================================================
245-
# 6. Start StateRepository back up
246-
# ========================================================
247-
Write-Host "`n=== Starting StateRepository ===" -ForegroundColor Cyan
248-
try {
249-
$sr = Get-Service -Name 'StateRepository' -ErrorAction Stop
250-
if ($sr.Status -eq 'Stopped') {
251-
$sr.Start()
252-
$sr.WaitForStatus('Running', [TimeSpan]::FromSeconds(5))
253-
}
254-
Write-Host " StateRepository is running." -ForegroundColor Green
255-
}
256-
catch {
257-
Write-Host " Warning: Could not start StateRepository" -ForegroundColor Yellow
258-
}
259-
}
260-
261-
if ($FileDeleted) {
262-
Write-Host "`n=== File successfully deleted on attempt $attempt ===" -ForegroundColor Green
263-
break
264-
} elseif ($attempt -lt $MaxRetries) {
265-
Write-Host "`n!!! Will retry (attempt $attempt of $MaxRetries)..." -ForegroundColor Yellow
266-
}
267-
}
268-
269-
if ($FileDeleted) {
270-
# ========================================================
271-
# 7. Run wsreset.exe to reinstall Store
272-
# ========================================================
273-
Write-Host "`n=== Running wsreset.exe -i (this may take a moment) ===" -ForegroundColor Cyan
274-
try {
275-
$wsresetProcess = Start-Process -FilePath 'wsreset.exe' -ArgumentList '-i' -PassThru -Wait -ErrorAction Stop
276-
if ($wsresetProcess.ExitCode -ne 0) {
277-
Write-Host " wsreset.exe -i exited with code $($wsresetProcess.ExitCode)" -ForegroundColor Yellow
278-
} else {
279-
Write-Host " wsreset.exe -i completed successfully." -ForegroundColor Green
280-
}
281-
}
282-
catch {
283-
Write-Host " Warning: Could not run wsreset.exe" -ForegroundColor Yellow
284-
}
285-
286-
Write-Host "`n=== Done. ===" -ForegroundColor Green
287-
}
288-
else {
289-
Write-Host "`n=== REGISTRY FALLBACK: Attempting Store repair via Registry ===" -ForegroundColor Yellow
290-
291-
try {
292-
# Reset the Store app package state
293-
Write-Host "Clearing Store package cache and resetting settings..." -ForegroundColor Cyan
294-
295-
$regPaths = @(
296-
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModel\StateRepository',
297-
'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\CloudStore\Store\Cache'
298-
)
299-
300-
foreach ($regPath in $regPaths) {
301-
if (Test-Path -Path $regPath) {
302-
try {
303-
Remove-Item -Path $regPath -Recurse -Force -ErrorAction SilentlyContinue
304-
Write-Host " Cleared: $regPath"
305-
}
306-
catch {
307-
Write-Host " Could not clear $regPath (non-critical)" -ForegroundColor Yellow
308-
}
309-
}
310-
}
311-
312-
# Restart Store related services
313-
Write-Host "`nRestarting Store services..." -ForegroundColor Cyan
314-
foreach ($svc in @('AppXSvc', 'ClipSVC', 'StateRepository')) {
315-
try {
316-
$s = Get-Service -Name $svc -ErrorAction SilentlyContinue
317-
if ($null -ne $s) {
318-
if ($s.Status -eq 'Running') {
319-
$s.Stop()
320-
$s.WaitForStatus('Stopped', [TimeSpan]::FromSeconds(3))
321-
}
322-
$s.Start()
323-
$s.WaitForStatus('Running', [TimeSpan]::FromSeconds(3))
324-
Write-Host " Restarted: $svc"
325-
}
326-
}
327-
catch {
328-
Write-Host " Could not restart $svc" -ForegroundColor Yellow
329-
}
330-
}
331-
332-
Write-Host "`n=== Registry fallback completed. Store should regenerate. ===" -ForegroundColor Green
333-
}
334-
catch {
335-
Write-Host "ERROR during registry fallback: $($_.Exception.Message)" -ForegroundColor Red
336-
}
337-
finally {
338-
Write-Host "`n=== Finished (file deletion ultimately failed after $MaxRetries attempts) ===" -ForegroundColor Yellow
339-
}
340-
}
341-
342-
Stop-Transcript | Out-Null
343-
Write-Host " Log saved to: $LogFile"
344-
345-
if (-not $Silent) {
346-
Write-Host ""
347-
pause
348-
}
17+
call RunAsTI.cmd "%windir%\AtlasModules\Tools\StoreFixer.exe" -wait
71.2 MB
Binary file not shown.

0 commit comments

Comments
 (0)