zoukankan      html  css  js  c++  java
  • 怪事~

       private void Form1_Load(object sender, EventArgs e)
            {
                ConnectionOptions co 
    = new ConnectionOptions();
                co.Impersonation 
    = ImpersonationLevel.Impersonate;
                co.EnablePrivileges 
    = true;
                ManagementScope mgrScope 
    = new ManagementScope(@"\\.\root\default", co);
                WqlEventQuery evQuery 
    = new WqlEventQuery();
                evQuery.WithinInterval 
    = new TimeSpan(000150);
                
    //evQuery.QueryString = @"Select * From RegistryKeyChangeEvent Where Hive='HKEY_USERS' And KeyPath='S-1-5-21-3743974248-512206057-3529231067-1000\\Software\\Microsoft\\Internet Explorer\\Main'";//
                evQuery.QueryString = @"Select * From RegistryKeyChangeEvent Where Hive='HKEY_USERS' And KeyPath='" + GetUserSID() + "\\Software\\Microsoft\\Internet Explorer\\Main'";//

                ManagementEventWatcher RegKeyWacher 
    = new ManagementEventWatcher();
                RegKeyWacher.Query 
    = evQuery;
                RegKeyWacher.EventArrived 
    += new EventArrivedEventHandler(OnRegistryKeyChange);
                RegKeyWacher.Scope 
    = mgrScope;
                RegKeyWacher.Start();

            
            }

            
    private string GetUserSID()
            {
                
    string strUserSID = "";
                ConnectionOptions co 
    = new ConnectionOptions();
                co.Impersonation 
    = ImpersonationLevel.Impersonate;
                co.EnablePrivileges 
    = true;
                ManagementScope mgrScope 
    = new ManagementScope("\\\\.\\root\\cimv2", co);
                ObjectQuery myQuery 
    = new ObjectQuery("SELECT * FROM Win32_UserAccount WHERE Domain=\"" + Environment.UserDomainName + "\"" + " And Name=\"" + Environment.UserName + "\"");
                ManagementObjectSearcher searcher 
    = new ManagementObjectSearcher(mgrScope, myQuery);
                ManagementObjectCollection oReturnCollection 
    = searcher.Get();
                
    foreach (ManagementObject sid in oReturnCollection)
                {
                    strUserSID 
    = sid["SID"].ToString();
                }
                
    return strUserSID;
            }

     

    运行完①②之后,evQuery.QueryString 的值都是一样的,但①可以正常监视,但②RegKeyWacher.Start()的总是时候异常!!怪事!

  • 相关阅读:
    python上传阿里云oss
    python调用百度图片识别api
    python实现sm2和sm4国密(国家商用密码)算法
    python坐标获取经纬度或经纬度获取坐标免费模块--geopy
    剑指 Offer 36. 二叉搜索树与双向链表
    vs code中终端中的命令不能使用的解决方法
    VS Code切换默认终端(cmd、powershell)
    剑指 Offer 35. 复杂链表的复制
    剑指 Offer 33. 二叉搜索树的后序遍历序列
    剑指 Offer 32
  • 原文地址:https://www.cnblogs.com/linmilove/p/1740107.html
Copyright © 2011-2022 走看看