H4x0

Change Windows 7 Login Disclaimer (Legal Notice)

Jul 14th, 2013
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.77 KB | None | 0 0
  1. /*
  2.  * This code needs to be run via the admin account
  3.  * because it does registry read/write operations.
  4.  *
  5.  * Original Code: http://pastebin.com/u/H4x0
  6.  */
  7.  
  8. using Microsoft.Win32;
  9. using System;
  10. using System.Threading.Tasks;
  11.  
  12. namespace WinLoginMessage
  13. {
  14.     class LoginMessageHelper
  15.     {
  16.         const String REG_PATH =
  17.             @"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System";
  18.  
  19.         public class LoginMessage
  20.         {
  21.             String ITitle = String.Empty;
  22.             String IMessa = String.Empty;
  23.  
  24.             public String Title
  25.             {
  26.                 get
  27.                 {
  28.                     return ITitle;
  29.                 }
  30.  
  31.                 set
  32.                 {
  33.                     ITitle = value;
  34.                 }
  35.             }
  36.  
  37.             public String Text
  38.             {
  39.                 get
  40.                 {
  41.                     return IMessa;
  42.                 }
  43.  
  44.                 set
  45.                 {
  46.                     IMessa = value;
  47.                 }
  48.             }
  49.  
  50.             public LoginMessage(String Caption, String Message)
  51.             {
  52.                 ITitle = Caption;
  53.                 IMessa = Message;
  54.             }
  55.         }
  56.  
  57.         public LoginMessageHelper() { }
  58.  
  59.         public LoginMessage Load()
  60.         {
  61.             LoginMessage ReturnValue = null;
  62.  
  63.             Task RegTask = Task.Factory.StartNew(() =>
  64.             {
  65.                 RegistryKey REG_KEY = Registry.LocalMachine.OpenSubKey(REG_PATH, false);
  66.  
  67.                 ReturnValue = new LoginMessage(
  68.                     (String)REG_KEY.GetValue("legalnoticecaption", ""),
  69.                     (String)REG_KEY.GetValue("legalnoticetext", "")
  70.                 );
  71.             });
  72.  
  73.             RegTask.Wait();
  74.             return ReturnValue;
  75.         }
  76.  
  77.         public void Save(LoginMessage Msg)
  78.         {
  79.             Task RegTask = Task.Factory.StartNew(() =>
  80.             {
  81.                 String N_TIT = Msg.Title;
  82.                 String N_MSG = Msg.Text;
  83.  
  84.                 RegistryKey REG_KEY = Registry.LocalMachine.OpenSubKey(REG_PATH, true);
  85.                 REG_KEY.SetValue("legalnoticecaption", N_TIT, RegistryValueKind.String);
  86.                 REG_KEY.SetValue("legalnoticetext", N_MSG, RegistryValueKind.String);
  87.  
  88.                 /*
  89.                  * Check to make sure the values were saved
  90.                  */
  91.                 LoginMessage O_Object = Load();
  92.                 String O_TIT = O_Object.Title;
  93.                 String O_MSG = O_Object.Text;
  94.  
  95.                 if ((O_Object.Title != Msg.Title) || (O_Object.Text != Msg.Text))
  96.                 {
  97.                     throw new Exception("Values not saved correctly.");
  98.                 }
  99.             });
  100.  
  101.             RegTask.Wait();
  102.         }
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment