SCCM – PowerShell – Remove Reg Keys on Remote Computers

email me

I wrote this to remove GPRequestedSiteAssignmentCode and AssignedSiteCode registry values under the HKLM\SOFTWARE\Microsoft\SMS\Mobile Client registry key. Just add the computer names into the computers.txt file and run. Note, WINRM will need to be enabled on the remote computers/servers.

Clear-Host
$user = Read-Host "Enter Domain\Username"
$credential = Get-Credential -Credential "$user"
$Computers = Get-Content "c:\PowerShell\computers.txt"
try
{
Invoke-Command -ComputerName $Computers -Credential $credential -ScriptBlock {Remove-ItemProperty -Path HKLM:"\SOFTWARE\Microsoft\SMS\Mobile Client" -name AssignedSiteCode}
Invoke-Command -ComputerName $Computers -Credential $credential -ScriptBlock {Remove-ItemProperty -Path HKLM:"\SOFTWARE\Microsoft\SMS\Mobile Client" -name GPRequestedSiteAssignmentCode}
}
catch
{
$output = $_
$output
}

Windows – Fix Boot Issues

email me

Common boot issues can be fixed by doing the following:

Method 1

Using a Windows boot disc, go to Startup Repair (do this 3-4 times, if necessary).

 

Method 2

If that doesn’t work try the Repair Option and this time choose Command Prompt, type:

BOOTREC /FIXMBR {enter} 
BOOTREC /FIXBOOT{enter}
BOOTREC /SCANOS {enter}
BOOTREC /REBUILDBCD {enter}

 

Method 3

If it’s not successful or you receive No operating system found or Element not found messages, use diskpart and enter these commands:

DISKPART {enter}
LIST DISK {enter}
SELECT DISK N {enter}
LIST PARTITION {enter}
SELECT PARTITION N {enter}
ACTIVE {enter}
EXIT {enter}
Startup repair  – Reboot

If there are still issues, try one more Startup repair and reboot.

PowerShell – Install Fonts – Updated for 1809

email me

For Windows 10 build 1809, see notes.

Older builds, use this:

$ErrorActionPreference = "SilentlyContinue"

$path = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts"

Remove-ItemProperty -Path HKLM:$path -Name "OpenSans (TrueType)"
Remove-ItemProperty -Path HKLM:$path -Name "Open Sans Bold (TrueType)"
Remove-ItemProperty -Path HKLM:$path -Name "Open Sans Bold Italic (TrueType)"
Remove-ItemProperty -Path HKLM:$path -Name "Open Sans Extrabold (TrueType)"
Remove-ItemProperty -Path HKLM:$path -Name "Open Sans Extrabold Italic (TrueType)"
Remove-ItemProperty -Path HKLM:$path -Name "Open Sans Italic (TrueType)"
Remove-ItemProperty -Path HKLM:$path -Name "Open Sans Light (TrueType)"
Remove-ItemProperty -Path HKLM:$path -Name "Open Sans Light Italic (TrueType)"
Remove-ItemProperty -Path HKLM:$path -Name "Open Sans Semibold (TrueType)"
Remove-ItemProperty -Path HKLM:$path -Name "Open Sans (TrueType)"
Remove-ItemProperty -Path HKLM:$path -Name "Open Sans Semibold Italic (TrueType)"
start-sleep 10

dir *.ttf | %{
(New-Object -ComObject Shell.Application).Namespace(0x14).CopyHere($_.fullname)
}

 

Notes

{ Updated 3/26/2019 }

Since build 1809, the shell variable 0x14 is being overloaded and redirected to the user’s profile (if using SCCM and admin mode, the systemprofile is used). Not great. Microsoft, please fix it. Basically, this causes font issues, where the fonts appear to be installed, but are not. The workaround is to not use 0x14.

Windows 1809 breaks PowerShell script to install font

Can no longer install fonts via script in Windows 10 1809


Font Key Reg Location

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]


Font File Folder Location

C:\Windows\Fonts

If fonts don’t show up in C:\Windows\Fonts, delete the fonts from the user profile and the user’s registry—using the admin profile (or a different profile)

C:\Users\%username%\AppData\Local\Microsoft\Windows\Fonts

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts


Rebuild Font cache in Windows 10

sc stop "FontCache"
ping -n 10 127.0.0.1>nul
sc config "FontCache" start= disabled
ping -n 4 127.0.0.1>nul
sc stop "FontCache3.0.0.0"
ping -n 10 127.0.0.1>nul
sc config "FontCache3.0.0.0" start= disabled
ping -n 4 127.0.0.1>nul

reg DELETE "HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /f

del /f /a /q "C:\Windows\ServiceProfiles\LocalService\AppData\Local\*FontCache*"
del /f /a /q "C:\Windows\System32\FNTCACHE.DAT"
del /q "C:\Users\%username%\AppData\Local\Microsoft\Windows\Fonts\*.*"

sc config "FontCache" start= auto
ping -n 4 127.0.0.1>nul
sc start "FontCache"
ping -n 10 127.0.0.1>nul
sc config "FontCache3.0.0.0" start= auto
ping -n 4 127.0.0.1>nul
sc start "FontCache3.0.0.0"
ping -n 10 127.0.0.1>nul


Fonts and SCCM

Yes, there are other areas Font data is stored in 1809, if using SCCM and System Account:

HKEY_USERS\.DEFAULT\Software\Microsoft\Windows NT\CurrentVersion\Fonts

“C:\Windows\System32\config\systemprofile\AppData\Local\Microsoft\Windows\Fonts\”


Scripting

For scripting, resort to something simple (no 0x14) (simple…is working for me)

copy /y C:\fonts\*.ttf C:\Windows\Fonts\
regedit /s C:\fonts\OpenSansFont.reg

 

OpenSansFont.reg

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts]
“Open Sans Extrabold (TrueType)”=”OpenSans-ExtraBold.ttf”
“Open Sans Extrabold Italic (TrueType)”=”OpenSans-ExtraBoldItalic.ttf”
“Open Sans Italic (TrueType)”=”OpenSans-Italic.ttf”
“Open Sans Light (TrueType)”=”OpenSans-Light.ttf”
“Open Sans Light Italic (TrueType)”=”OpenSans-LightItalic.ttf”
“Open Sans (TrueType)”=”OpenSans-Regular.ttf”
“Open Sans Semibold (TrueType)”=”OpenSans-Semibold.ttf”
“Open Sans Semibold Italic (TrueType)”=”OpenSans-SemiboldItalic.ttf”
“Open Sans Bold (TrueType)”=”OpenSans-Bold.ttf”
“Open Sans Bold Italic (TrueType)”=”OpenSans-BoldItalic.ttf”
“OpenSans (TrueType)”=”OpenSans-Bold.ttf”


Franklin Gothic Demi Reg Keys

“Franklin Gothic Demi (TrueType)”=”ITCFranklinGothicStd-Demi.otf”
“Franklin Gothic Demi Cond (TrueType)”=”ITCFranklinGothicStd-Demi.otf”
“Franklin Gothic Demi Italic (TrueType)”=”ITCFranklinGothicStd-Demi.otf”

 

Found Online (not tested)

Command line in SCCM Task Sequence

%SCRIPTROOT%\nircmd.exe elevate \\Server\d$\MDTBuildLab\Fonter\AddFonts.cmd \\server\d$\MDTBuildLab\Fonter\fonts\


AddFonts.cmd

@ECHO OFF
TITLE Adding Fonts
color 0a
cls
:: Filename: ADD_Fonts.cmd
:: Script to ADD TrueType and OpenType Fonts for Windows

:: How to use:
:: Place the batch file inside the folder of the font files OR:
:: Optional Add source folder as parameter with ending backslash and don't use quotes, spaces are allowed
:: example "ADD_fonts.cmd" C:\Folder 1\Folder 2\

IF NOT "%*"=="" SET SRC=%*
ECHO Adding Fonts...
ECHO.
FOR /F %%i in ('dir /b "%SRC%*.*tf"') DO CALL :FONT %%i
ECHO Done!
:: PAUSE
EXIT


:FONT
ECHO.
ECHO FILE=%~f1
SET FFILE=%~n1%~x1
SET FNAME=%~n1
SET FNAME=%FNAME:-= %
IF "%~x1"==".otf" SET FTYPE=(OpenType)
IF "%~x1"==".ttf" SET FTYPE=(TrueType)

ECHO FILE=%FFILE%
ECHO NAME=%FNAME%
ECHO TYPE=%FTYPE%

COPY /Y "%SRC%%~n1%~x1" "%SystemRoot%\Fonts\"
reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts" /v "%FNAME% %FTYPE%" /t REG_SZ /d "%FFILE%" /f
GOTO :EOF

Expanding SCCM Right-Click Tools

email me

NOTICE: You’re not going to find this info anywhere on the web, because it’s undocumented. This is experimental, so make backups of your files before editing.

I figured out exactly how the Right-Click Tools work (which is a SCCM add-on), and have added some of my own features and modified some of the original features. In this post, I show you how to expand the Right-Click Tools to include functions you need.

To understand how options are added to the right-click menu, check out the XMLs located here:

C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\XmlStorage\Extensions\Actions

 

If you were to modify those XMLs, options would appear on the menu, though, these options wouldn’t do anything. You would have to add code behind them.


Extra Options

 

There is a logical flow that the tool follows

1 – The XML File (these are the options that can be seen in the SCCM Console)

2 – SilentOpenPS.vbs or OpenPS.vbs (used to show or hide dialog boxes)

3 – Device – Tools.ps1 (any script which performs an action or function)

 

Step 1 – Code 


Let’s Talk About Code

So, in step 1, you’ll need to add code behind each menu option, before you make the option visible on the menu. Starting with something simple, let’s add the code for the ‘Disable Firewall’ option.

1 – Open Device – Tools.ps1 (located where you installed RCT).

2 – Add this code and save:

"DisableFirewall" {
If ($PSExecLocation.length -gt 1 -and (Test-Path $PSExecLocation)) {
if (Test-Connection -computername $CompName -count 1 -quiet){
& cmd /c "$Directory\psexec.exe" -accepteula "\\$CompName" netsh advfirewall set allprofiles state off
$Popup.Popup("Firewall disabled on $CompName!",0,"Alert",64)
}
else {
$Popup.Popup("$CompName is not online",0,"Error",16)
}
}
else {
$Popup.Popup("PsExec not found.",0,"Error",16)
$ArgList = @()
$ArgList += @("`"$Directory\SilentOpenPS.vbs`"")
$ArgList += @("`"$Directory\Configure Tools.ps1`"")
$ArgList += @("`"Interactive Command Prompt`"")
Start-Process wscript.exe -ArgumentList $ArgList
}
End-Script
}

The magic behind RCT is that it uses psexec to transparently execute remote commands on devices. Clever.

 

 

Step 2 – Modify XML


Menu Option

In step 2, once you have completed the coded portion, is to modify relative XML files to make the option visible in SCCM. I modified two XML files.

Main folder

     C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\XmlStorage\Extensions\Actions

Subfolders

     ed9dee86-eadd-4ac8-82a1-7234a4646e62

     3fd01cd1-9e01-461e-92cd-94866b8d1f39

 

Add this XML to each file

* make sure the Right-Click volume and path are correct for your environment

<ActionDescription Class="Executable" DisplayName="Disable Firewall" MnemonicDisplayName="Disable Firewall" Description="Disable Firewall">
<ShowOn>
<string>ContextMenu</string>
</ShowOn>
<Executable>
<FilePath>"wscript.exe"</FilePath>
<Parameters>"D:\Right-Click_Tools\SilentOpenPS.vbs" "D:\Right-Click_Tools\Device - Tools.ps1" ##SUB:ResourceID## ##SUB:__Server## ##SUB:__Namespace## "DisableFirewall"</Parameters>
</Executable>
</ActionDescription>

Close and reopen the SCCM console.

Test the newly added ‘Disable Firewall’ option on a client machine.

 

Notes


My XML with other mods

<ActionDescription Class="Executable" DisplayName="Remote Control" MnemonicDisplayName="Remote Control" Description="Remote Control">
<ShowOn>
<string>ContextMenu</string>
</ShowOn>
<Executable>
<FilePath>"wscript.exe"</FilePath>
<Parameters> "D:\Right-Click_Tools\SilentOpenPS.vbs" "D:\Right-Click_Tools\Device - WOL.ps1" ##SUB:ResourceID## ##SUB:__Server## ##SUB:__Namespace##</Parameters>
</Executable>
</ActionDescription>

<ActionDescription Class="Executable" DisplayName="Remote Registry" MnemonicDisplayName="Remote Registry" Description="Remote Registry">
<ShowOn>
<string>ContextMenu</string>
</ShowOn>
<Executable>
<FilePath>"wscript.exe"</FilePath>
<Parameters>"D:\Right-Click_Tools\SilentOpenPS.vbs" "D:\Right-Click_Tools\Device - Tools.ps1" ##SUB:ResourceID## ##SUB:__Server## ##SUB:__Namespace## "RemoteRegistry"</Parameters>
</Executable>
</ActionDescription>

<ActionDescription Class="Executable" DisplayName="Enable Admin Share" MnemonicDisplayName="Enable Admin Share" Description="Enable Admin Share">
<ShowOn>
<string>ContextMenu</string>
</ShowOn>
<Executable>
<FilePath>"wscript.exe"</FilePath>
<Parameters>"D:\Right-Click_Tools\SilentOpenPS.vbs" "D:\Right-Click_Tools\Device - Tools.ps1" ##SUB:ResourceID## ##SUB:__Server## ##SUB:__Namespace## "EnableShare"</Parameters>
</Executable>
</ActionDescription>

<ActionDescription Class="Executable" DisplayName="Disable Firewall" MnemonicDisplayName="Disable Firewall" Description="Disable Firewall">
<ShowOn>
<string>ContextMenu</string>
</ShowOn>
<Executable>
<FilePath>"wscript.exe"</FilePath>
<Parameters>"D:\Right-Click_Tools\SilentOpenPS.vbs" "D:\Right-Click_Tools\Device - Tools.ps1" ##SUB:ResourceID## ##SUB:__Server## ##SUB:__Namespace## "DisableFirewall"</Parameters>
</Executable>
</ActionDescription>

<ActionDescription Class="Separator">
<ShowOn>
<string>ContextMenu</string>
</ShowOn>
</ActionDescription>

<ActionDescription Class="Executable" DisplayName="Install Adobe Air" MnemonicDisplayName="Install Adobe Air" Description="Install Adobe Air">
<ShowOn>
<string>ContextMenu</string>
</ShowOn>
<Executable>
<FilePath>"wscript.exe"</FilePath>
<Parameters> "D:\Right-Click_Tools\SilentOpenPS.vbs" "D:\Right-Click_Tools\Device - Tools.ps1" "##SUB:ResourceID##" ##SUB:__Server## ##SUB:__Namespace## "AdobeAir"</Parameters>
</Executable>
</ActionDescription>

<ActionDescription Class="Executable" DisplayName="Uninstall LANDesk" MnemonicDisplayName="Uninstall LANDesk" Description="Uninstall LANDesk">
<ShowOn>
<string>ContextMenu</string>
</ShowOn>
<Executable>
<FilePath>"wscript.exe"</FilePath>
<Parameters> "D:\Right-Click_Tools\SilentOpenPS.vbs" "D:\Right-Click_Tools\Device - Tools.ps1" "##SUB:ResourceID##" ##SUB:__Server## ##SUB:__Namespace## "UninstallLANDesk"</Parameters>
</Executable>
</ActionDescription>

<ActionDescription Class="Executable" DisplayName="Update SEP 14x" MnemonicDisplayName="Update SEP 14x" Description="Update SEP 14x">
<ShowOn>
<string>ContextMenu</string>
</ShowOn>
<Executable>
<FilePath>"wscript.exe"</FilePath>
<Parameters> "D:\Right-Click_Tools\SilentOpenPS.vbs" "D:\Right-Click_Tools\Device - Tools.ps1" "##SUB:ResourceID##" ##SUB:__Server## ##SUB:__Namespace## "UpdateSEP"</Parameters>
</Executable>
</ActionDescription>
<ActionDescription Class="Separator">
<ShowOn>
<string>ContextMenu</string>
</ShowOn>
</ActionDescription>

<ActionDescription Class="Executable" DisplayName="Rebuild WMI" MnemonicDisplayName="Rebuild WMI" Description="Rebuild WMI">
<ShowOn>
<string>ContextMenu</string>
</ShowOn>
<Executable>
<FilePath>"wscript.exe"</FilePath>
<Parameters> "D:\Right-Click_Tools\SilentOpenPS.vbs" "D:\Right-Click_Tools\Device - Tools.ps1" "##SUB:ResourceID##" ##SUB:__Server## ##SUB:__Namespace## "RebuildWMI"</Parameters>
</Executable>
</ActionDescription>

<ActionDescription Class="Executable" DisplayName="Repair Windows Updates" MnemonicDisplayName="Repair Windows Updates" Description="Repair Windows Updates">
<ShowOn>
<string>ContextMenu</string>
</ShowOn>
<Executable>
<FilePath>"wscript.exe"</FilePath>
<Parameters> "D:\Right-Click_Tools\SilentOpenPS.vbs" "D:\Right-Click_Tools\Device - Tools.ps1" "##SUB:ResourceID##" ##SUB:__Server## ##SUB:__Namespace## "RepairWinUpdates"</Parameters>
</Executable>
</ActionDescription>

 

Just remember the flow:

XML > SilentOpenPS.vbs > WhateverScript.ps1

 

At this point, you can begin experimenting with your own code.

 

tags: extending, expanding sccm, sccm tools, MrNetTek

C# – Audit Method Added to Jump Tool

email me

I have created a new audit method for my elevated tool to track usage.

static void Audit()
{
// create registry key

// set up strings
string reg1 = "HKEY_LOCAL_MACHINE";
string reg2 = @"SOFTWARE\XXXXX\XXXX";
string regPath = reg1 + @"\" + reg2;
string UName = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
string regVal = appName + " " + UName;

DateTime dt = DateTime.Now;

// create new reg key each time
Registry.SetValue(regPath, dt.ToString(), regVal, RegistryValueKind.String);


// log event

// set up strings 
string sSource;
string sLog;
string sEvent;

sSource = "ABC.exe";
sLog = "Application";

sEvent = appName + " was installed using the Jump tool by " + UName;

if (!EventLog.SourceExists(sSource)) EventLog.CreateEventSource(sSource, sLog);

// create new event each time
EventLog.WriteEntry(sSource, sEvent);

// output to console
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("{{{ Security log has been updated }}}\n");
Console.ForegroundColor = ConsoleColor.White;
}

Windows 10 – Enter Safe Mode

email me

1) Ensure your PC is off.

2) Press the power button to turn on your PC, then hold the power button down until PC shuts down automatically (about 5 seconds) . Repeat this more than 2 times until you see the Preparing Automatic Repair (see below screenshot).

Note: This step is aim to bring up Preparing Automatic Repair screen. When Windows doesn’t boot properly, this screen pops up and Windows attempts to fix the problem by itself. If you’ve seen this screen at the first time when you power up the computer, skip this step.

Then wait for Windows to diagnose your PC.

2) Click Advanced options, then the system will bring up the Windows RE (Recovery environment.) screen.

3) On the Windows RE (Recovery environment) screen, click Troubleshoot.

4)  On the Troubleshoot screen, click Advanced options.

5) Click Startup Settings to continue.

6) Click Restart. The computer restarts and another screen opens showing a list of different startup options.

7) On your keyboard, press the number key to enter Safe Mode without network. (If you need to do some online research after boot into the safe mode, press the number key to enter Safe Mode with network access.)

Notes

c:
bcdedit /set {default} bootmenupolicy legacy
exit

SCCM – Windows Updates in Log Files

email me

Software Updates Client Computer Log Files

CAS.log – Provides information about the process of downloading software updates to the local cache and cache management.

CIAgent.log – Provides information about processing configuration items, including software updates.

LocationServices.log – Provides information about the location of the WSUS server when a scan is initiated on the client.

PatchDownloader.log – Provides information about the process for downloading software updates from the update source to the download destination on the site server. This log is only on the client computer configured as the synchronization host for the Inventory Tool for Microsoft Updates.

PolicyAgent.log – Provides information about the process for downloading, compiling, and deleting policies on client computers.

PolicyEvaluator – Provides information about the process for evaluating policies on client computers, including policies from software updates.

RebootCoordinator.log – Provides information about the process for coordinating system restarts on client computers after software update installations.

ScanAgent.log – Provides information about the scan requests for software updates, what tool is requested for the scan, the WSUS location, and so on.

ScanWrapper – Provides information about the prerequisite checks and the scan process initialization for the Inventory Tool for Microsoft Updates on Systems Management Server (SMS) 2003 clients.

SdmAgent.log – Provides information about the process for verifying and decompressing packages that contain configuration item information for software updates.

ServiceWindowManager.log – Provides information about the process for evaluating configured maintenance windows.

smscliUI.log – Provides information about the Configuration Manager Control Panel user interactions, such as initiating a Software Updates Scan Cycle from the Configuration Manager Properties dialog box, opening the Program Download Monitor, and so on.

SmsWusHandler – Provides information about the scan process for the Inventory Tool for Microsoft Updates on SMS 2003 client computers.

StateMessage.log – Provides information about when software updates state messages are created and sent to the management point.

UpdatesDeployment.log – Provides information about the deployment on the client, including software update activation, evaluation, and enforcement. Verbose logging shows additional information about the interaction with the client user interface.

UpdatesHandler.log – Provides information about software update compliance scanning and about the download and installation of software updates on the client.

UpdatesStore.log – Provides information about the compliance status for the software updates that were assessed during the compliance scan cycle.

WUAHandler.log – Provides information about when the Windows Update Agent on the client searches for software updates.

WUSSyncXML.log – Provides information about the Inventory Tool for the Microsoft Updates synchronization process. This log is only on the client computer configured as the synchronization host for the Inventory Tool for Microsoft Updates.

 

Software Updates Site Server Log Files

ciamgr.log – Provides information about the addition, deletion, and modification of software update configuration items.

distmgr.log – Provides information about the replication of software update deployment packages.

objreplmgr.log – Provides information about the replication of software updates notification files from a parent to child sites.

PatchDownloader.log – Provides information about the process for downloading software updates from the update source specified in the software updates metadata to the download destination on the site server.

replmgr.log – Provides information about the process for replicating files between sites.

smsdbmon.log – Provides information about when software update configuration items are inserted, updated, or deleted from the site server database and creates notification files for software updates components.

SUPSetup – Provides information about the software update point installation. When the software update point installation completes, Installation was successful is written to this log file.

WCM.log – Provides information about the software update point configuration and connecting to the Windows Server Update Services (WSUS) server for subscribed update categories, classifications, and languages.

WSUSCtrl.log – Provides information about the configuration, database connectivity, and health of the WSUS server for the site.

wsyncmgr.log -Provides information about the software updates synchronization process.

SCCM – Windows 10 – Agent Stuck in Provisioning Mode

email me

When you use the W10 Upgrade, the Configuration Manager client may be left in provisioning mode after the upgrade succeeds (or fails, for that matter). If provisioning is left enabled, you won’t be able to see or use packages or updates in Software Center, the ccmexec.exe process will look likes it’s processing data, which it isn’t, and the client certificate will not be installed. A client reinstall will not resolve this. The solution is to toggle the provisioning mode flag from true…to false.

Solution

Powershell.exe Invoke-WmiMethod -Namespace root\CCM -Class SMS_Client -Name SetClientProvisioningMode -ArgumentList $false

 

Notes

Reg Key

Path: HKEY_LOCAL_MACHINE\Software\Microsoft\CCM\CcmExec
Value: ProvisioningMode
Data: True


If the client needs remediation

Powershell.exe Start-Process $env:WinDir\ccmsetup\ccmsetup.exe -ArgumentList “/remediate:client” -Wait -NoNewWindow -PassThru -WindowStyle Hidden

Windows 10 – Clean up Locked Setup Files

email me

Sometimes the Windows 10 setup files remain after installation—and in rare cases—the files become locked, or…just won’t allow you to delete them because of permission issues.

Try this from an admin prompt

takeown /F C:\$Windows.~BT\* /R /A
icacls C:\$Windows.~BT\*.* /T /grant administrators:F
rmdir /S /Q C:\$Windows.~BT\

takeown /F C:\$Windows.~WS\* /R /A
icacls C:\$Windows.~WS\*.* /T /grant administrators:F
rmdir /S /Q C:\$Windows.~WS\

You can also rename the folder, if you need to begin a new setup, while keeping the original setup files.