C#Yahoo Messenger注册表监视程序 [英] C# Yahoo Messenger registry watcher

查看:70
本文介绍了C#Yahoo Messenger注册表监视程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我叫Nicusor,
我在网上找到了此代码,首先我将HKEY_LOCAL_MACHINE更改为HKEY_CURRENT_USER,只是为了发现HKEY_CURRENT_USER不支持ChangeEvent.
我正在尝试向此应用程序(consoleapplication16.exe)添加两个参数.
因此听起来像:consoleapplication16.exe S-1-5-21-4054269417-2950973813-1693298518-1000 snoop_creep
其中S-1-5-21-4054269417-2950973813-1693298518-1000是SID,而snoop_creep是yahoo id
我是C#的初学者,我还在学习.
如果有人可以帮助我,那就太好了.
我正在使用Microsoft Visual Studio2010.
在此先感谢您,并感谢我的英语.
这是代码:

Hi, my name is Nicusor,
I have found this code on the net, first I changed the HKEY_LOCAL_MACHINE to HKEY_CURRENT_USER just to find out that you can''t ChangeEvent is not supported for HKEY_CURRENT_USER.
I am trying to add two arguments to this application (consoleapplication16.exe)
so it will sound like : consoleapplication16.exe S-1-5-21-4054269417-2950973813-1693298518-1000 snoop_creep
where S-1-5-21-4054269417-2950973813-1693298518-1000 is the SID and snoop_creep is the yahoo id
I am a beginer in C# I''m still learning.
It will be nice if someone could help me.
I am using Microsoft Visual Studio 2010.
Thank you in advance and sorry for my English.
This is the code:

namespace WmiExample
{
    using System;
    using System.Management;
    using System.Diagnostics;
    using System.ComponentModel;

    /// <summary>
    /// </summary>
    public class WmiChangeEventTester
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="WmiChangeEventTester" /> class.
        /// </summary>
        public WmiChangeEventTester()
        {
            try
            {
                // Your query goes below; "KeyPath" is the key in the registry that you
                // want to monitor for changes. Make sure you escape the \ character.
                WqlEventQuery query = new WqlEventQuery(
                     "SELECT * FROM RegistryValueChangeEvent WHERE " +
                     "Hive = 'HKEY_USERS'" +
                     @"AND KeyPath = 'args[1]\\Software\\Yahoo\\pager\\profiles\\args[2]\\Custom Msgs' AND ValueName='1_W'");

                ManagementEventWatcher watcher = new ManagementEventWatcher(query);
                Console.WriteLine("Waiting for Yahoo! Messenger to change status...");

                // Set up the delegate that will handle the change event.
                watcher.EventArrived += new EventArrivedEventHandler(HandleEvent);

                // Start listening for events.
                watcher.Start();

                // Do something while waiting for events. In your application,
                // this would just be continuing business as usual.
                System.Threading.Thread.Sleep(100000000);

                // Stop listening for events.
                watcher.Stop();
            }
            catch (ManagementException managementException)
            {
                Console.WriteLine("An error occurred: " + managementException.Message);
            }
        }

        /// <summary>
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void HandleEvent(object sender, EventArrivedEventArgs e)
        {
            Console.WriteLine("Yahoo! Messenger status change detected.");
            Process myProcess = new Process();
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.FileName = "PimpToolStatusExtractor.exe";
            myProcess.StartInfo.CreateNoWindow = false;
            myProcess.Start();
        }

        /// <summary>
        /// </summary>
        static void Main(string[] args)
        {
            // In my opinion here is where i have to set the args but will al the respect i don't know how

            WmiChangeEventTester receiveEvent = new WmiChangeEventTester();
        }
    }
}

推荐答案

我直到reg_mon.cfg有1行:我的Yahoo id
但是它的打开和关闭速度很快:(不知道为什么.请帮助

< pre>
//------------------------------------------------ -------------------------------------------------- -------------------
//< copyright file ="Program.cs" company =">
//
//</copyright>
//< summary>
//定义WmiChangeEventTester类型.
//</summary>
//------------------------------------------------ -------------------------------------------------- -------------------
命名空间WmiExample
{
使用系统;
使用System.Management;
使用System.Security.Principal;
使用System.IO;

///< summary>
///</summary>
公共类WmiChangeEventTester
{
///< summary>
///初始化< see cref ="WmiChangeEventTester"/>的新实例.课.
///</summary>
公共WmiChangeEventTester()
{
试试
{
//您的查询如下; "KeyPath"是您在注册表中的注册表项
//要监视更改.确保您转义\字符.
字符串a;
字符串b;
一个= Environment.UserName;
b = Environment.MachineName;
WindowsIdentity身份= WindowsIdentity.GetCurrent();
字符串filePath = @"reg_mon.cfg";
字符串行;
StreamReader文件= null;
file =新的StreamReader(filePath);
行= file.ReadLine();
WqlEventQuery查询=新的WqlEventQuery(
"SELECT * FROM RegistryValueChangeEvent在哪里" +
蜂巢=" HKEY_USERS" +
@"AND KeyPath =""+ identity.User +" \\ Software \\ Yahoo \\ pager \\ profiles \\"+ line +" \\ Custom Msgs"AND ValueName =" 1_W"));

ManagementEventWatcher watcher =新的ManagementEventWatcher(query);
Console.WriteLine(正在等待事件...");
Console.WriteLine("AND KeyPath =""+ identity.User +" \\ Software \\ Yahoo \\ pager \\ profiles \\"+ line +" \\ Custom Msgs"AND ValueName =" 1_W");
//设置将处理更改事件的委托.
watcher.EventArrived + =新的EventArrivedEventHandler(HandleEvent);

//开始监听事件.
watcher.Start();

//等待事件时做一些事情.在您的应用程序中,
//这将像往常一样继续进行业务.
System.Threading.Thread.Sleep(100000000);

//停止监听事件.
watcher.Stop();
}
捕获(ManagementException managementException)
{
Console.WriteLine(发生错误:" + managementException.Message);
}
}

///< summary>
///</summary>
///< param name ="sender">
///发件人.
///</param>
///< param name ="e">
///e.
///</param>
私有void HandleEvent(对象发送者,EventArrivedEventArgs e)
{
Console.WriteLine(收到事件.");
//RegistryKeyChangeEvent发生在这里;做点什么.
}

///< summary>
///</summary>
公共静态void Main()
{
//只需调用上面的类来检查事件...
WmiChangeEventTester receiveEvent =新的WmiChangeEventTester();
}
}
}


</pre>
i got till this point where reg_mon.cfg has 1 line : my Yahoo id
but it is opening and closing fast :( don;t know why. help please

<pre>
// ---------------------------------------------------------------------------------------------------------------------
// <copyright file="Program.cs" company="">
//
// </copyright>
// <summary>
// Defines the WmiChangeEventTester type.
// </summary>
// ---------------------------------------------------------------------------------------------------------------------
namespace WmiExample
{
using System;
using System.Management;
using System.Security.Principal;
using System.IO;

/// <summary>
/// </summary>
public class WmiChangeEventTester
{
/// <summary>
/// Initializes a new instance of the <see cref="WmiChangeEventTester"/> class.
/// </summary>
public WmiChangeEventTester()
{
try
{
// Your query goes below; "KeyPath" is the key in the registry that you
// want to monitor for changes. Make sure you escape the \ character.
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''");
// Set up the delegate that will handle the change event.
watcher.EventArrived += new EventArrivedEventHandler(HandleEvent);

// Start listening for events.
watcher.Start();

// Do something while waiting for events. In your application,
// this would just be continuing business as usual.
System.Threading.Thread.Sleep(100000000);

// Stop listening for events.
watcher.Stop();
}
catch (ManagementException managementException)
{
Console.WriteLine("An error occurred: " + managementException.Message);
}
}

/// <summary>
/// </summary>
/// <param name="sender">
/// The sender.
/// </param>
/// <param name="e">
/// The e.
/// </param>
private void HandleEvent(object sender, EventArrivedEventArgs e)
{
Console.WriteLine("Received an event.");
// RegistryKeyChangeEvent occurs here; do something.
}

/// <summary>
/// </summary>
public static void Main()
{
// Just calls the class above to check for events...
WmiChangeEventTester receiveEvent = new WmiChangeEventTester();
}
}
}


</pre>


这篇关于C#Yahoo Messenger注册表监视程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆