mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-11-23 19:49:17 +08:00
Clean Up tool (#5994)
* Initial commit * Code review changes * Added PowerShell script to clean up PowerToys * Removed commented code * Added about and comments to script, fixed deleting of DontShowThisAgain directory inside registry * Added type to var's, changed positions of comments * Changed RegDeleteKey to RegDeleteTree
This commit is contained in:
parent
07dfa6f296
commit
40a4a6a1a8
25
tools/CleanUp_tool/CleanUp_tool.sln
Normal file
25
tools/CleanUp_tool/CleanUp_tool.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30225.117
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CleanUp_tool", "CleanUp_tool.vcxproj", "{0995F59A-5074-42E4-AFE4-6335A0368E8E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Release|x64 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{0995F59A-5074-42E4-AFE4-6335A0368E8E}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{0995F59A-5074-42E4-AFE4-6335A0368E8E}.Debug|x64.Build.0 = Debug|x64
|
||||
{0995F59A-5074-42E4-AFE4-6335A0368E8E}.Release|x64.ActiveCfg = Release|x64
|
||||
{0995F59A-5074-42E4-AFE4-6335A0368E8E}.Release|x64.Build.0 = Release|x64
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {B025F9FC-0262-4669-BADD-BBD61121FBD3}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
88
tools/CleanUp_tool/CleanUp_tool.vcxproj
Normal file
88
tools/CleanUp_tool/CleanUp_tool.vcxproj
Normal file
@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{0995f59a-5074-42e4-afe4-6335a0368e8e}</ProjectGuid>
|
||||
<RootNamespace>CleanUptool</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>shlwapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
22
tools/CleanUp_tool/CleanUp_tool.vcxproj.filters
Normal file
22
tools/CleanUp_tool/CleanUp_tool.vcxproj.filters
Normal file
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
169
tools/CleanUp_tool/main.cpp
Normal file
169
tools/CleanUp_tool/main.cpp
Normal file
@ -0,0 +1,169 @@
|
||||
#include <windows.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <shlwapi.h>
|
||||
#include <shlobj.h>
|
||||
|
||||
static wchar_t szWindowClass[] = L"CleanUp tool";
|
||||
static wchar_t szTitle[] = L"Tool to clean up FancyZones installation";
|
||||
|
||||
HINSTANCE hInst;
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
void CleanUp();
|
||||
void RemoveSettingsFolder();
|
||||
void ClearRegistry();
|
||||
|
||||
int CALLBACK WinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow)
|
||||
{
|
||||
WNDCLASSEX wcex;
|
||||
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wcex.lpfnWndProc = WndProc;
|
||||
wcex.cbClsExtra = 0;
|
||||
wcex.cbWndExtra = 0;
|
||||
wcex.hInstance = hInstance;
|
||||
wcex.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
|
||||
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
||||
wcex.lpszMenuName = nullptr;
|
||||
wcex.lpszClassName = szWindowClass;
|
||||
wcex.hIconSm = LoadIcon(wcex.hInstance, IDI_APPLICATION);
|
||||
|
||||
if (!RegisterClassEx(&wcex))
|
||||
{
|
||||
MessageBox(nullptr, L"Call to RegisterClassEx failed!", szTitle, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
hInst = hInstance;
|
||||
|
||||
HWND hWnd = CreateWindow(
|
||||
szWindowClass,
|
||||
szTitle,
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
200, 200,
|
||||
nullptr,
|
||||
nullptr,
|
||||
hInstance,
|
||||
nullptr
|
||||
);
|
||||
|
||||
if (!hWnd)
|
||||
{
|
||||
MessageBox(nullptr, L"Call to CreateWindow failed!", szTitle, NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
ShowWindow(hWnd, nCmdShow);
|
||||
UpdateWindow(hWnd);
|
||||
|
||||
HWND hwndButton = CreateWindow(
|
||||
L"BUTTON", // Predefined class; Unicode assumed
|
||||
L"Clear", // Button text
|
||||
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON, // Styles
|
||||
50, // x position
|
||||
50, // y position
|
||||
100, // Button width
|
||||
100, // Button height
|
||||
hWnd, // Parent window
|
||||
(HMENU) 1, // No menu.
|
||||
(HINSTANCE)GetWindowLongPtr(hWnd, GWLP_HINSTANCE),
|
||||
nullptr); // Pointer not needed.
|
||||
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, nullptr, 0, 0))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
return (int)msg.wParam;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc;
|
||||
|
||||
switch (message)
|
||||
{
|
||||
case WM_PAINT:
|
||||
hdc = BeginPaint(hWnd, &ps);
|
||||
EndPaint(hWnd, &ps);
|
||||
break;
|
||||
case WM_COMMAND:
|
||||
if (wParam == 1)
|
||||
{
|
||||
CleanUp();
|
||||
}
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void CleanUp()
|
||||
{
|
||||
RemoveSettingsFolder();
|
||||
ClearRegistry();
|
||||
}
|
||||
|
||||
void RemoveSettingsFolder()
|
||||
{
|
||||
wchar_t settingsPath[MAX_PATH];
|
||||
if (SUCCEEDED(SHGetFolderPath(nullptr, ssfLOCALAPPDATA, nullptr, 0, settingsPath)))
|
||||
{
|
||||
PathAppend(settingsPath, L"\\Microsoft\\PowerToys");
|
||||
}
|
||||
|
||||
HRESULT hr = CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IFileOperation* pfo;
|
||||
hr = CoCreateInstance(CLSID_FileOperation, nullptr, CLSCTX_ALL, IID_PPV_ARGS(&pfo));
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
hr = pfo->SetOperationFlags(FOF_NO_UI);
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
IShellItem* psiFrom = nullptr;
|
||||
hr = SHCreateItemFromParsingName(settingsPath, nullptr, IID_PPV_ARGS(&psiFrom));
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = pfo->DeleteItem(psiFrom, nullptr);
|
||||
}
|
||||
psiFrom->Release();
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = pfo->PerformOperations();
|
||||
}
|
||||
}
|
||||
pfo->Release();
|
||||
}
|
||||
|
||||
void ClearRegistry()
|
||||
{
|
||||
RegDeleteTreeW(HKEY_CURRENT_USER, L"Software\\SuperFancyZones");
|
||||
RegDeleteTreeW(HKEY_CURRENT_USER, L"Software\\Microsoft\\PowerRename");
|
||||
RegDeleteTreeW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\DontShowMeThisDialogAgain\\{e16ea82f-6d94-4f30-bb02-d6d911588afd}");
|
||||
RegDeleteTreeW(HKEY_CURRENT_USER, L"Software\\Microsoft\\ImageResizer");
|
||||
}
|
48
tools/CleanUp_tool_powershell_script/CleanUp_tool.ps1
Normal file
48
tools/CleanUp_tool_powershell_script/CleanUp_tool.ps1
Normal file
@ -0,0 +1,48 @@
|
||||
#CleanUp tool 1.0
|
||||
#Copyright (C) 2020 Microsoft Corporation
|
||||
#Tool to clean PowerToys settings inside AppData folder and registry
|
||||
|
||||
#Deleting json settings files in %AppData%/Local/Microsoft/PowerToys.
|
||||
|
||||
[String]$SettingsPath = $Env:LOCALAPPDATA + '\Microsoft\PowerToys'
|
||||
|
||||
if (Test-Path -Path $SettingsPath -PathType Any)
|
||||
{
|
||||
Remove-Item –Path $SettingsPath –Recurse
|
||||
}
|
||||
|
||||
#Deleting SuperFancyZones registry key
|
||||
|
||||
[String]$SuperFancyZones = "HKCU:\Software\SuperFancyZones"
|
||||
|
||||
if (Test-Path -Path $SuperFancyZones -PathType Any)
|
||||
{
|
||||
Remove-Item –Path $SuperFancyZones –Recurse
|
||||
}
|
||||
|
||||
#Deleting PowerRename registry key
|
||||
|
||||
[String]$PowerRename = "HKCU:\Software\Microsoft\PowerRename"
|
||||
|
||||
if (Test-Path -Path $PowerRename -PathType Any)
|
||||
{
|
||||
Remove-Item –Path $PowerRename –Recurse
|
||||
}
|
||||
|
||||
#Deleting ImageResizer registry key
|
||||
|
||||
[String]$ImageResizer = "HKCU:\Software\Microsoft\ImageResizer"
|
||||
|
||||
if (Test-Path -Path $ImageResizer -PathType Any)
|
||||
{
|
||||
Remove-Item –Path $ImageResizer –Recurse
|
||||
}
|
||||
|
||||
#Deleting DontShowThisDialogAgain registry key
|
||||
|
||||
[String]$DontShowThisDialogAgain = "HKCU:\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain\{e16ea82f-6d94-4f30-bb02-d6d911588afd}"
|
||||
|
||||
if (Test-Path -Path $DontShowThisDialogAgain -PathType Any)
|
||||
{
|
||||
Remove-Item –Path $DontShowThisDialogAgain
|
||||
}
|
Loading…
Reference in New Issue
Block a user