Jump to content
Dizzy13

[.NET] Cum pot sterge un registry key care contine ...?

Recommended Posts

Salut!

Sa spunem ca in HKEY_CURRENT_USER\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache am salvat un registru cu numele "C:\test\test.exe" si altul cu numele "C:\Program Files\test\test.exe", cum pot face sa stearga automat orice registru care contine "test.exe"?

 

registryKey = My.Computer.Registry.CurrentUser.OpenSubKey("SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache", True)
            registryKey.DeleteValue(String.Concat("*test.exe*"), True) ' ceva de genul
            registryKey.Close()

Sau daca aveti idee de o alta metoda cu care as putea sterge automat orice log din programul LastActivityView.

Multumesc anticipat!

Edited by Dizzy13

Share this post


Link to post
Share on other sites
// asa stergi toate event logurile 
// te descurci probabil sa faci ceva regex sa stergi ce vrei tu
foreach (var log in EventLog.GetEventLogs())
{         
     log.Clear();
     log.Dispose();
}

 

Share this post


Link to post
Share on other sites
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RegistryValue
{
    class Program
    {
        static string COMPANY = "";
        static void Main(string[] args)
        {
            
            string path = @"SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache";
            string keyToDelete = "test.exe";
            string appName1 = @"C:\Program Files\test\test.exe";
            string appName2 = @"C:\test\test.exe";
            InsertRegValue(path, appName1, "aaaa");
            InsertRegValue(path, appName2, "bbbbbb");
            foreach (var item in GetRegValue(path))
            {
                if (item.Contains(keyToDelete))
                    DeleteRegValue(path, item);
            }
        }

        static private bool InsertRegValue(String path, String regKey, String regValue)
        {
            // Write  path to the registry 
            RegistryKey key = Registry.CurrentUser.OpenSubKey(path, true);
            if (key.OpenSubKey(path) == null)
                key.CreateSubKey(path);
            try
            {
                key.SetValue(regKey, regValue);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        static private String[] GetRegValue(String path)
        {
            // Write  path to the registry 
            RegistryKey key = Registry.CurrentUser.OpenSubKey(path);
            if (key != null)
            {
                try
                {
                    return (String[])key.GetValueNames();
                }
                catch (Exception)
                {
                    return new String[] { };
                }
            }
            return new String[] { };
        }
        static private void DeleteRegValue(String path, String regKey)
        {
            using (RegistryKey key = Registry.CurrentUser.OpenSubKey(path, true))
            {
                try
                {
                    if (key == null)
                    {
                        // Key doesn't exist. Do whatever you want to handle
                        // this case
                    }
                    else
                    {
                        key.DeleteValue(regKey);
                    }
                }
                catch (Exception ex)
                { }
            }
        }
    }
}

 

mai intai insereaza in in registry 2 valori pentru testexe 1 si testexe2, apoi ia elementele din path si verifica daca au in componenta cheia cautata, daca da sterge registrul.

@MrGrj event logurile nu cred ca au treaba cu registrii.

@Dizzy13 daca ai nevoie si de exe sa imi zici. consola trebuie rulata ca administrator.

Edited by gigiRoman

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...