久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 RegistryKey 值更改時收到通知

Receive notification when RegistryKey Value was changed(在 RegistryKey 值更改時收到通知)
本文介紹了在 RegistryKey 值更改時收到通知的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想要在 HKEY_CURRENT_USER 中的特定 RegistryKey 更改時收到通知.到目前為止,我通過 WMI 嘗試了這個,但沒有成功:

I want a notification when a specific RegistryKey in HKEY_CURRENT_USER is changed. So far I tried this via WMI with no success:

var query = new WqlEventQuery(string.Format(
"SELECT * FROM RegistryKeyChangeEvent WHERE Hive='{0}' AND KeyPath='{1}' AND ValueName='{2}'",
                hive, keyPath.Replace("\","\\"), valueName));
_watcher = new ManagementEventWatcher(query);
_watcher.Scope.Path.NamespacePath = @"rootdefault";
_watcher.EventArrived += (sender, args) => KeyValueChanged();
_watcher.Start();

(錯誤是未找到")

我的第二種方法是使用 WBEM Scripting COM 組件,目的是移植來自 http://msdn.microsoft.com/en-us/library/aa393042(VS.85).aspx 到 c# 但我沒有找到c# 中 WBEM COM 的任何使用示例

My second approach was using the WBEM Scripting COM component with the intent to port the example from http://msdn.microsoft.com/en-us/library/aa393042(VS.85).aspx to c# but I didn't find any usage samples for the WBEM COM in c#

我發現了這個 http://www.codeproject.com/KB/system/registrymonitor.aspx 類,但它不符合我的需要,因為該類只監視整個鍵,我只想要一個特定值(通過上面示例中的 ValueName 指定)時的通知) 發生變化.

I found this http://www.codeproject.com/KB/system/registrymonitor.aspx class, but it didn't fit my needs as this class only monitors the whole key and I only want a notification when a specific value (specified via the ValueName in the samples above) gets changed.

如果您在 msdn vbscript 示例中將 Hive 更改為 HKEY_CURRENT_USER,它將停止工作.我找不到有關此行為的任何信息,但是 2003 年的鏈接

If you change the Hive to HKEY_CURRENT_USER in the msdn vbscript example, it stops working. I couldn't find anything about this behaviour but a link from 2003

RegistryEvent 或從它派生的類(例如 RegistryValueChangeEvent)不支持對 HKEY_CLASSES_ROOTHKEY_CURRENT_USER 配置單元的更改.(MSDN)

Changes to the HKEY_CLASSES_ROOT and HKEY_CURRENT_USER hives are not supported by RegistryEvent or classes derived from it, such as RegistryValueChangeEvent. (MSDN)

推薦答案

我終于解決了問題,讓 WMI 查詢版本可以工作:

I finally solved the problem and got the WMI query version to work:

var currentUser = WindowsIdentity.GetCurrent();
var query = new WqlEventQuery(string.Format(
"SELECT * FROM RegistryValueChangeEvent WHERE Hive='HKEY_USERS' AND KeyPath='{0}\\{1}' AND ValueName='{2}'",
currentUser.User.Value, keyPath.Replace("\","\\"), valueName));
_watcher = new ManagementEventWatcher(query);
_watcher.EventArrived += (sender, args) => KeyValueChanged();
_watcher.Start();

我在 http://www.codeproject.com/Messages/2844468/監控-HKEY_CURRENT_USER.aspx

這篇關于在 RegistryKey 值更改時收到通知的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

LINQ to SQL and Concurrency Issues(LINQ to SQL 和并發問題)
Yield return from a try/catch block(try/catch 塊的收益回報)
Should I call Parameters.Clear when reusing a SqlCommand with a transation?(重用帶有事務的 SqlCommand 時,我應該調用 Parameters.Clear 嗎?)
what does a using statement without variable do when disposing?(處理時不帶變量的 using 語句有什么作用?)
Why doesn#39;t TransactionScope work with Entity Framework?(為什么 TransactionScope 不適用于實體框架?)
How to dispose TransactionScope in cancelable async/await?(如何在可取消的 async/await 中處理 TransactionScope?)
主站蜘蛛池模板: 精品伊人 | 成人影| 国产精品自拍视频 | 国产激情在线 | 91免费在线播放 | 国产高清91| 午夜精品一区二区三区免费视频 | 综合久久99| 久久久久久综合 | 亚洲一区电影 | 欧美精品一区在线 | 成人精品一区二区三区中文字幕 | 欧美影院 | 国产97色| 一区二区三区不卡视频 | 麻豆天堂 | 欧美美女一区二区 | 噜噜噜噜狠狠狠7777视频 | 国产欧美一区二区在线观看 | 国产黄色网 | 91毛片在线观看 | 欧美激情国产精品 | 欧美日韩国产一区二区三区 | 综合久久av| 亚洲精选一区二区 | 欧美三区在线观看 | 亚洲一区二区黄 | 日韩精品极品视频在线观看免费 | 国产在线网站 | 欧美精品一区二区三区在线播放 | 欧美日韩专区 | h片在线免费看 | 秋霞影院一区二区 | 久久天堂 | 国产精品乱码一区二三区小蝌蚪 | 香蕉婷婷 | 久久av网站 | 99久久免费精品国产男女高不卡 | 天堂网avav | 精品美女在线观看视频在线观看 | 亚洲男女视频在线观看 |