110,580
社区成员
发帖
与我相关
我的任务
分享
public static string BHOKEYNAME = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects";
[ComRegisterFunction]
public static void RegisterBHO(Type type)
{
System.Windows.Forms.MessageBox.Show("BHO TESTING.2..");
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);
if (registryKey == null)
registryKey = Registry.LocalMachine.CreateSubKey(BHOKEYNAME);
string guid = type.GUID.ToString("B");
RegistryKey ourKey = registryKey.OpenSubKey(guid);
if (ourKey == null)
ourKey = registryKey.CreateSubKey(guid);
ourKey.SetValue("Alright", 1);
registryKey.Close();
ourKey.Close();
}
[ComUnregisterFunction]
public static void UnregisterBHO(Type type)
{
System.Windows.Forms.MessageBox.Show("BHO TESTING..3.");
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);
string guid = type.GUID.ToString("B");
if (registryKey != null)
registryKey.DeleteSubKey(guid, false);
}
public class BHO : IObjectWithSite
{
WebBrowser browser;
HTMLDocument document;
public void OnDocumentComplete(object pDisp, ref object URL)
{
System.Windows.Forms.MessageBox.Show("BHO TESTING...");
}
public int SetSite(object site)
{
if (site != null)
{
browser = (WebBrowser)site;
browser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
}
else
{
browser.DocumentComplete -= new DWebBrowserEvents2_DocumentCompleteEventHandler(this.OnDocumentComplete);
browser = null;
}
return 0;
}
public int GetSite(ref Guid guid, out IntPtr ppvSite)
{
IntPtr punk = Marshal.GetIUnknownForObject(browser);
int hr = Marshal.QueryInterface(punk, ref guid, out ppvSite);
Marshal.Release(punk);
return hr;
}
.....
public static string BHOKEYNAME = "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects";
[ComRegisterFunction]
public static void RegisterBHO(Type type)
{
System.Windows.Forms.MessageBox.Show("BHO TESTING.2..");
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);
if (registryKey == null)
{
System.Windows.Forms.MessageBox.Show("BHO TESTING.4..");
registryKey = Registry.LocalMachine.CreateSubKey(BHOKEYNAME);
}
System.Windows.Forms.MessageBox.Show("BHO TESTING.6.." + BHOKEYNAME);
string guid = type.GUID.ToString("B");
RegistryKey ourKey = registryKey.OpenSubKey(guid);
System.Windows.Forms.MessageBox.Show("BHO TESTING.8.." + guid);
if (ourKey == null)
{
System.Windows.Forms.MessageBox.Show("BHO TESTING.10.." + guid);
ourKey = registryKey.CreateSubKey(guid);
System.Windows.Forms.MessageBox.Show("BHO TESTING.11.." + ourKey);
}
ourKey.SetValue("Alright", 1);
System.Windows.Forms.MessageBox.Show("BHO TESTING.12.." + ourKey);
registryKey.Close();
ourKey.Close();
System.Windows.Forms.MessageBox.Show("BHO TESTING.13..");
}
[ComUnregisterFunction]
public static void UnregisterBHO(Type type)
{
System.Windows.Forms.MessageBox.Show("BHO TESTING..3.");
RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(BHOKEYNAME, true);
string guid = type.GUID.ToString("B");
System.Windows.Forms.MessageBox.Show("BHO TESTING.5.." + guid);
if (registryKey != null)
{
registryKey.DeleteSubKey(guid, false);
System.Windows.Forms.MessageBox.Show("BHO TESTING.7.." + guid);
}
System.Windows.Forms.MessageBox.Show("BHO TESTING.9.." + guid);
}