久久久久久久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九色麻豆 | 欧美人成在线视频 | 啪啪免费网站 | 国产精品久久久久久婷婷天堂 | 婷婷色在线 | 国产精品国产自产拍高清 | 国产精品区二区三区日本 | 日本理论片好看理论片 | 国产精品视频网 | 亚洲在线免费观看 | 久久久网| 成人国产网站 | 午夜久久久久久久久久一区二区 | 亚洲久在线 | 亚洲精品一区国产精品 | 国产无套一区二区三区久久 | 日韩中文字幕在线视频 | 成人精品视频在线 | 国产在线精品一区二区三区 | 综合国产| 久久久激情 | www.国产精品 | 国产在线精品一区二区三区 | 亚洲精品区| 在线免费毛片 | 99视频免费在线观看 | 午夜免费在线观看 | 久久久www成人免费精品 | 五月婷婷激情网 | 国产毛片视频 | 99热激情| 国产成人av一区二区三区 | 国产亚洲精品久久久久动 | 偷拍亚洲色图 | 欧美free性| 国产成人99av超碰超爽 | 欧美在线二区 | 成人福利在线 | 黄页网址在线观看 | 免费看91 | 国产美女精品视频免费观看 |