Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Windows.Forms;
- using Microsoft.Win32;
- using System.IO;
- using System.Diagnostics;
- namespace StartupScanner
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- rbackup.Checked = true;
- }
- private void Export(string exportPath, string registryPath)
- {
- string path = "\"" + exportPath + "\"";
- string key = "\"" + registryPath + "\"";
- Process proc = new Process();
- try
- {
- proc.StartInfo.FileName = "regedit.exe";
- proc.StartInfo.UseShellExecute = false;
- proc = Process.Start("regedit.exe", "/e " + path + " " + key);
- proc.WaitForExit();
- }
- catch (Exception)
- {
- proc.Dispose();
- }
- }
- private void Import(string registryPath)
- {
- if (!File.Exists(registryPath))
- {
- MessageBox.Show(registryPath + " does not exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- string key = "\"" + registryPath + "\"";
- Process proc = new Process();
- try
- {
- proc.StartInfo.FileName = "regedit.exe";
- proc.StartInfo.UseShellExecute = false;
- proc = Process.Start("regedit.exe", "/s " + key);
- proc.WaitForExit();
- }
- catch (Exception)
- {
- proc.Dispose();
- }
- }
- private void scanbtn (object sender, EventArgs e)
- {
- listView1.Items.Clear();
- RegistryKey key, key1, keyx86;
- String location = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";//HKCU,HKLM
- string location1 = @"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce";//HKCU
- if (Environment.Is64BitOperatingSystem)
- {
- key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64);
- key1 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
- keyx86 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
- }
- else
- {
- key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32);
- key1 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
- keyx86 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
- }
- string[] valuenames = key.OpenSubKey(location).GetValueNames();
- string[] valuenames1 = key1.OpenSubKey(location).GetValueNames();
- string[] valuename2 = key.OpenSubKey(location1).GetValueNames();
- string[] valuenames3 = keyx86.OpenSubKey(location).GetValueNames();
- /////////////////// HKCU_Run//////////////////////////////////////////
- foreach (string sub in valuenames)
- {
- object data = key.OpenSubKey(location).GetValue(sub);
- ListViewItem lvi = new ListViewItem(sub);
- lvi.SubItems.Add(data.ToString());
- lvi.SubItems.Add("HKCU_Run");
- listView1.Items.Add(lvi);
- }
- //////////////////////////// HKCU_RunOne///////////////////////////
- foreach (string sub in valuename2)
- {
- object data2 = key.OpenSubKey(location1).GetValue(sub);
- ListViewItem lvi = new ListViewItem(sub);
- lvi.SubItems.Add(data2.ToString());
- lvi.SubItems.Add("HKCU_RunOne");
- listView1.Items.Add(lvi);
- }
- ///////////////////// HKLM_Run/////////////////////////////////
- foreach (string sub in valuenames1)
- {
- object data1 = key1.OpenSubKey(location).GetValue(sub);
- ListViewItem lvi = new ListViewItem(sub);
- lvi.SubItems.Add(data1.ToString());
- lvi.SubItems.Add("HKLM_Runx64");
- listView1.Items.Add(lvi);
- }
- foreach (string sub in valuenames3)
- {
- object data3 = keyx86.OpenSubKey(location).GetValue(sub);
- ListViewItem lvi = new ListViewItem(sub);
- lvi.SubItems.Add(data3.ToString());
- lvi.SubItems.Add("HKLM_Runx86");
- listView1.Items.Add(lvi);
- }
- listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
- listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
- count.Text = "Total: " + listView1.Items.Count.ToString() + " rows";
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- listView1.View = View.Details;
- listView1.GridLines = true;
- listView1.FullRowSelect = true;
- listView1.MultiSelect = true;
- }
- private void removebtn (object sender, EventArgs e)
- {
- RegistryKey key,key1,keyx86;
- var selecteditems = listView1.SelectedItems;
- String location = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
- string location1 = @"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce";
- if (Environment.Is64BitOperatingSystem)
- {
- key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry64);
- key1= RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
- keyx86 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
- }
- else
- {
- key = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Registry32);
- key1 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
- keyx86 = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
- }
- foreach (ListViewItem sub in selecteditems)
- {
- if (sub.SubItems[2].Text == "HKCU_Run")
- {
- key.OpenSubKey(location, true).DeleteValue(sub.SubItems[0].Text);
- key.Close();
- listView1.Items.Remove(sub);
- }
- else if(sub.SubItems[2].Text=="HKCU_RunOne")
- {
- key.OpenSubKey(location1, true).DeleteValue(sub.SubItems[0].Text);
- key.Close();
- listView1.Items.Remove(sub);
- }
- else if(sub.SubItems[2].Text=="HKLM_Runx64")
- {
- key1.OpenSubKey(location, true).DeleteValue(sub.SubItems[0].Text);
- key1.Close();
- listView1.Items.Remove(sub);
- }
- else
- {
- keyx86.OpenSubKey(location, true).DeleteValue(sub.SubItems[0].Text);
- keyx86.Close();
- listView1.Items.Remove(sub);
- }
- count.Text = "Total: " + listView1.Items.Count.ToString() + " rows";
- }
- }
- private void button3_Click(object sender, EventArgs e)
- {
- try
- {
- string tree = null;
- ListViewItem selecteditems = listView1.SelectedItems[0];
- string registryLocation = null;
- if (selecteditems.SubItems[2].Text.Substring(0, 4) == "HKLM")
- {
- tree = "HKEY_LOCAL_MACHINE";
- registryLocation = Path.Combine(tree, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
- }
- else
- {
- tree = "HKEY_CURRENT_USER";
- if (selecteditems.SubItems[2].Text.Substring(5,3) == "Run")
- {
- registryLocation = Path.Combine(tree, @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run");
- }
- else
- {
- registryLocation = Path.Combine(tree, @"SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce");
- }
- }
- var registryLastKey = @"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Regedit";
- Registry.SetValue(registryLastKey, "LastKey", registryLocation); // Set LastKey value that regedit will go directly to
- Process.Start("regedit.exe");
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- private void btngo_Click(object sender, EventArgs e)
- {
- String HKCU_Run = @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
- string HKLM_Run= @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
- string HKCU_RunOnce=@"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce";
- string HKLM_RunOnce = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce";
- try
- {
- string folderbk = AppDomain.CurrentDomain.BaseDirectory +"Regbackup";
- if (!Directory.Exists(folderbk))
- {
- Directory.CreateDirectory(folderbk);
- }
- if (rbackup.Checked == true)
- {
- Export(folderbk + @"\HKCU_Run.reg", HKCU_Run);
- Export(folderbk + @"\HKLM_Run.reg", HKLM_Run);
- Export(folderbk + @"\HKCU_RunOnce.reg", HKCU_RunOnce);
- Export(folderbk + @"\HKLM_RunOnce.reg", HKLM_RunOnce);
- MessageBox.Show("Registry backups completed!");
- }
- else
- {
- Import(folderbk + @"\HKCU_Run.reg");
- Import(folderbk + @"\HKLM_Run.reg");
- Import(folderbk + @"\HKCU_RunOnce.reg");
- Import(folderbk + @"\HKLM_RunOnce.reg");
- MessageBox.Show("Registry restores completed!");
- }
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement