Jump to content
Maximus

Registry watcher

Recommended Posts

Salut , am gasit acest cod pe net si nu inteleg de ce se inchide executabilul imediat dupa ce il deschid , intentia mea este sa monitorizez HKEY_USERS\SID\Software\Yahoo\pager\profiles\ID\Custom Msgs 1_W.

In fisierul reg_mon.cfg este o singura linie : idul meu.

Folosesc Microsoft Visual Studio 2010

asta este codu :

namespace WmiExample

{

using System;

using System.Management;

using System.Security.Principal;

using System.IO;

public class WmiChangeEventTester

{

public WmiChangeEventTester()

{

try

{

string a;

string b;

a = Environment.UserName;

b = Environment.MachineName;

WindowsIdentity identity = WindowsIdentity.GetCurrent();

string filePath = @"reg_mon.cfg";

string line;

StreamReader file = null;

file = new StreamReader(filePath);

line = file.ReadLine();

WqlEventQuery query = new WqlEventQuery(

"SELECT * FROM RegistryValueChangeEvent WHERE " +

"Hive = 'HKEY_USERS'" +

@"AND KeyPath = '" + identity.User + "\\Software\\Yahoo\\pager\\profiles\\" + line + "\\Custom Msgs' AND ValueName='1_W'");

ManagementEventWatcher watcher = new ManagementEventWatcher(query);

Console.WriteLine("Waiting for an event...");

Console.WriteLine("AND KeyPath = '"+ identity.User +"\\Software\\Yahoo\\pager\\profiles\\"+ line +"\\Custom Msgs' AND ValueName='1_W'");

watcher.EventArrived += new EventArrivedEventHandler(HandleEvent);

watcher.Start();

System.Threading.Thread.Sleep(100000000);

watcher.Stop();

}

catch (ManagementException managementException)

{

Console.WriteLine("An error occurred: " + managementException.Message);

}

}

private void HandleEvent(object sender, EventArrivedEventArgs e)

{

Console.WriteLine("Received an event.");

}

public static void Main()

{

WmiChangeEventTester receiveEvent = new WmiChangeEventTester();

}

}

}

Nu am facut nici un fel de curs,am citit doar ceva pagini de pe net si GOOGLE foarte mult.As fi recunoscator daca m-ar ajuta cineva

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...