Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
fou1100ouacus authored May 1, 2024
1 parent b970b70 commit 192790b
Show file tree
Hide file tree
Showing 22 changed files with 208 additions and 4 deletions.
6 changes: 6 additions & 0 deletions Delete value from Registry - Example/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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>{E85AF823-164C-4F42-AD54-689E6B849D68}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Delete_value_from_Registry___Example</RootNamespace>
<AssemblyName>Delete value from Registry - Example</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<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' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</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.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="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34601.278
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Delete value from Registry - Example", "Delete value from Registry - Example.csproj", "{E85AF823-164C-4F42-AD54-689E6B849D68}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E85AF823-164C-4F42-AD54-689E6B849D68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E85AF823-164C-4F42-AD54-689E6B849D68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E85AF823-164C-4F42-AD54-689E6B849D68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E85AF823-164C-4F42-AD54-689E6B849D68}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {48C6FEF5-CC77-4264-ABB9-5333539DEFB1}
EndGlobalSection
EndGlobal
55 changes: 55 additions & 0 deletions Delete value from Registry - Example/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Delete_value_from_Registry___Example
{
internal class Program
{
static void Main(string[] args)
{

// Specify the registry key path and value name
string keyPath = @"SOFTWARE\YourSoftware";
string valueName = "YourValueName";


try
{
// Open the registry key in read/write mode with explicit registry view
using (RegistryKey baseKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64))
{
using (RegistryKey key = baseKey.OpenSubKey(keyPath, true))
{
if (key != null)
{
// Delete the specified value
key.DeleteValue(valueName);


Console.WriteLine($"Successfully deleted value '{valueName}' from registry key '{keyPath}'");
}
else
{
Console.WriteLine($"Registry key '{keyPath}' not found");
}
}
}
}
catch (UnauthorizedAccessException)
{
Console.WriteLine("UnauthorizedAccessException: Run the program with administrative privileges.");
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
}


Console.ReadKey();
}
}
}
36 changes: 36 additions & 0 deletions Delete value from Registry - Example/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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("Delete value from Registry - Example")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Delete value from Registry - Example")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[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("e85af823-164c-4f42-ad54-689e6b849d68")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5bb56c9ef8259863da41b9966ff000324a4ac45ce033dd510671b53b9ecdc07a
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
D:\USED\Delete value from Registry - Example\bin\Debug\Delete value from Registry - Example.exe.config
D:\USED\Delete value from Registry - Example\bin\Debug\Delete value from Registry - Example.exe
D:\USED\Delete value from Registry - Example\bin\Debug\Delete value from Registry - Example.pdb
D:\USED\Delete value from Registry - Example\obj\Debug\Delete value from Registry - Example.csproj.AssemblyReference.cache
D:\USED\Delete value from Registry - Example\obj\Debug\Delete value from Registry - Example.csproj.CoreCompileInputs.cache
D:\USED\Delete value from Registry - Example\obj\Debug\Delete value from Registry - Example.exe
D:\USED\Delete value from Registry - Example\obj\Debug\Delete value from Registry - Example.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -48,6 +51,7 @@
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="app.manifest" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
8 changes: 4 additions & 4 deletions Permission to Write to Registry/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ internal class Program
static void Main(string[] args)
{// Specify the Registry key and path
string keyPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\YourSoftware";
string valueName = "YourValueName";
string valueData = "YourValueData";
string valueName2 = "YourValueName";
string valueData = "YourValueDataPermissinon";


try
{
// Write the value to the Registry
Registry.SetValue(keyPath, valueName, valueData, RegistryValueKind.String);
Registry.SetValue(keyPath, valueName2, valueData, RegistryValueKind.String);


Console.WriteLine($"Value {valueName} successfully written to the Registry.");
Console.WriteLine($"Value {valueName2} successfully written to the Registry.");
}
catch (Exception ex)
{
Expand Down
11 changes: 11 additions & 0 deletions Permission to Write to Registry/app.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" processorArchitecture="X86" name="YourAppName" type="win32" />
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 192790b

Please sign in to comment.