Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * This code needs to be run via the admin account
- * because it does registry read/write operations.
- *
- * Original Code: http://pastebin.com/u/H4x0
- */
- using Microsoft.Win32;
- using System;
- using System.Threading.Tasks;
- namespace WinLoginMessage
- {
- class LoginMessageHelper
- {
- const String REG_PATH =
- @"SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System";
- public class LoginMessage
- {
- String ITitle = String.Empty;
- String IMessa = String.Empty;
- public String Title
- {
- get
- {
- return ITitle;
- }
- set
- {
- ITitle = value;
- }
- }
- public String Text
- {
- get
- {
- return IMessa;
- }
- set
- {
- IMessa = value;
- }
- }
- public LoginMessage(String Caption, String Message)
- {
- ITitle = Caption;
- IMessa = Message;
- }
- }
- public LoginMessageHelper() { }
- public LoginMessage Load()
- {
- LoginMessage ReturnValue = null;
- Task RegTask = Task.Factory.StartNew(() =>
- {
- RegistryKey REG_KEY = Registry.LocalMachine.OpenSubKey(REG_PATH, false);
- ReturnValue = new LoginMessage(
- (String)REG_KEY.GetValue("legalnoticecaption", ""),
- (String)REG_KEY.GetValue("legalnoticetext", "")
- );
- });
- RegTask.Wait();
- return ReturnValue;
- }
- public void Save(LoginMessage Msg)
- {
- Task RegTask = Task.Factory.StartNew(() =>
- {
- String N_TIT = Msg.Title;
- String N_MSG = Msg.Text;
- RegistryKey REG_KEY = Registry.LocalMachine.OpenSubKey(REG_PATH, true);
- REG_KEY.SetValue("legalnoticecaption", N_TIT, RegistryValueKind.String);
- REG_KEY.SetValue("legalnoticetext", N_MSG, RegistryValueKind.String);
- /*
- * Check to make sure the values were saved
- */
- LoginMessage O_Object = Load();
- String O_TIT = O_Object.Title;
- String O_MSG = O_Object.Text;
- if ((O_Object.Title != Msg.Title) || (O_Object.Text != Msg.Text))
- {
- throw new Exception("Values not saved correctly.");
- }
- });
- RegTask.Wait();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment