More changes

This commit is contained in:
2025-10-18 11:38:05 +02:00
parent c32a6f9122
commit ceea1fca6b
9 changed files with 352 additions and 61 deletions

View File

@@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2F175C96-FDBA-49D8-BE83-1998C1F75FA2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Perfect11.Inbox.ManageTelemetry</RootNamespace>
<AssemblyName>Perfect11.Inbox.ManageTelemetry</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Management" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Tweak.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Perfect11.TweaksInterface\Perfect11.TweaksInterface.csproj">
<Project>{b3f8761a-b4b2-4378-9fe8-06bbfc39fce6}</Project>
<Name>Perfect11.TweaksInterface</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@@ -0,0 +1,33 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Perfect11 Inbox Tweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Vichingo455")]
[assembly: AssemblyProduct("Perfect11")]
[assembly: AssemblyCopyright("Copyright © 2025 Vichingo455")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("2f175c96-fdba-49d8-be83-1998c1f75fa2")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,179 @@
using Microsoft.Win32;
using Perfect11.TweaksInterface;
using System.ServiceProcess;
using System;
using System.Management;
using System.Diagnostics;
using System.IO;
namespace Perfect11.Inbox.ManageTelemetry
{
public class Tweak : IPlugin
{
public string Name => "Enable/Disable Telemetry";
public string Description => "Enable or Disable Telemetry components.";
public string Category => "Privacy";
public string Execute()
{
void ControlService(string serviceName, string action)
{
try
{
using (ServiceController sc = new ServiceController(serviceName))
{
Console.WriteLine($"Service '{serviceName}' current status: {sc.Status}");
switch (action.ToLower())
{
case "start":
if (sc.Status == ServiceControllerStatus.Stopped)
{
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(10));
Console.WriteLine("Service started successfully.");
}
else Console.WriteLine("Service is already running.");
break;
case "stop":
if (sc.Status == ServiceControllerStatus.Running)
{
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(10));
Console.WriteLine("Service stopped successfully.");
}
else Console.WriteLine("Service is not running.");
break;
case "restart":
if (sc.Status == ServiceControllerStatus.Running)
{
sc.Stop();
sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(10));
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(10));
Console.WriteLine("Service restarted successfully.");
}
else
{
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(10));
Console.WriteLine("Service started successfully.");
}
break;
default:
Console.WriteLine("Invalid action. Use start | stop | restart");
break;
}
}
}
catch (InvalidOperationException ex)
{
throw new Exception($"Service '{serviceName}' not found or cannot be controlled: {ex.Message}");
}
catch (System.ServiceProcess.TimeoutException)
{
throw new Exception("Operation timed out.");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
}
void SetServiceStartupType(string serviceName, string startupType)
{
try
{
// startupType can be: "Automatic", "Manual", or "Disabled"
string wmiPath = $"Win32_Service.Name='{serviceName}'";
using (ManagementObject service = new ManagementObject(wmiPath))
{
ManagementBaseObject inParams = service.GetMethodParameters("ChangeStartMode");
inParams["StartMode"] = startupType;
service.InvokeMethod("ChangeStartMode", inParams, null);
Console.WriteLine($"Service '{serviceName}' startup type set to {startupType}.");
}
}
catch (ManagementException ex)
{
throw new Exception(ex.Message);
}
}
bool IsTelemetryActivated()
{
RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Policies\\Microsoft\\Windows\\DataCollection");
int value = (int)rk.GetValue("AllowTelemetry");
rk.Close();
return value != 0;
}
if (IsTelemetryActivated())
{
// Step 1: Registry
RegistryKey rk = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Policies\\Microsoft\\Windows\\DataCollection");
rk.SetValue("AllowTelemetry",0,RegistryValueKind.DWord);
rk.SetValue("MaxTelemetryAllowed", 0, RegistryValueKind.DWord);
rk.Close();
rk = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\DataCollection");
rk.SetValue("AllowTelemetry", 0, RegistryValueKind.DWord);
rk.SetValue("MaxTelemetryAllowed", 0, RegistryValueKind.DWord);
rk.Close();
// Step 2: Stop and Disable Service
ControlService("DiagTrack","stop");
SetServiceStartupType("DiagTrack","Disabled");
// Step 3: Hopefully Disable CompatTelRunner.exe
ProcessStartInfo info = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = @"/c takeown /F C:\Windows\System32\CompatTelRunner.exe && icacls C:\Windows\System32\CompatTelRunner.exe /grant everyone:F",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
};
var proc = Process.Start(info);
proc.WaitForExit();
try
{
File.Move(@"C:\Windows\System32\CompatTelRunner.exe", @"C:\Windows\System32\CompatTelRunner.exe.backup");
} catch
{
throw new Exception("Error while attempting to disable Telemetry file.");
}
return "Windows Telemetry has been disabled successfully!";
}
else
{
// Step 1: Registry
RegistryKey rk = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Policies\\Microsoft\\Windows\\DataCollection");
rk.DeleteValue("AllowTelemetry");
rk.DeleteValue("MaxTelemetryAllowed");
rk.Close();
rk = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\DataCollection");
rk.DeleteValue("AllowTelemetry");
rk.DeleteValue("MaxTelemetryAllowed");
rk.Close();
// Step 2: Enable and Start Service
SetServiceStartupType("DiagTrack", "Automatic");
ControlService("DiagTrack", "start");
// Step 3: Enable back CompatTelRunner.exe
ProcessStartInfo info = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = @"/c takeown /F C:\Windows\System32\CompatTelRunner.exe.backup && icacls C:\Windows\System32\CompatTelRunner.exe.backup /grant everyone:F",
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden
};
var proc = Process.Start(info);
proc.WaitForExit();
try
{
File.Move(@"C:\Windows\System32\CompatTelRunner.exe.backup", @"C:\Windows\System32\CompatTelRunner.exe");
}
catch
{
throw new Exception("Error while attempting to enable back Telemetry file.");
}
return "Windows Telemetry has been enabled successfully!";
}
}
}
}