zoukankan      html  css  js  c++  java
  • C#获取默认浏览器的完整地址并在默认浏览器中打开对应的url地址

    /*  
        使用注册表监视工具发现 \SOFTWARE\Clients\StartMenuInternet\ 记录了默认浏览器名字
        
          [HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\默认浏览器名字\shell\open\command] 记录了物理路径
    */
    1
        /// <summary> 2 /// 获取默认浏览器的路径 3 /// </summary> 4 /// <returns></returns> 5 public String GetDefaultWebBrowserFilePath() 6 { 7 string _BrowserKey1 = @"Software\Clients\StartmenuInternet\"; 8 string _BrowserKey2 = @"\shell\open\command"; 9 10 RegistryKey _RegistryKey = Registry.CurrentUser.OpenSubKey(_BrowserKey1, false); 11 if (_RegistryKey == null) 12 _RegistryKey = Registry.LocalMachine.OpenSubKey(_BrowserKey1, false); 13 String _Result = _RegistryKey.GetValue("").ToString(); 14 _RegistryKey.Close(); 15 16 _RegistryKey = Registry.LocalMachine.OpenSubKey(_BrowserKey1 + _Result + _BrowserKey2); 17 _Result = _RegistryKey.GetValue("").ToString(); 18 _RegistryKey.Close(); 19 20 if (_Result.Contains("\"")) 21 { 22 _Result = _Result.TrimStart('"'); 23 _Result = _Result.Substring(0, _Result.IndexOf('"')); 24 } 25 return _Result; 26 } 27 28 /// <summary> 29 /// 获取当前默认浏览器的完整地址 30 /// </summary> 31 /// <param name="sender"></param> 32 /// <param name="e"></param> 33 private void btn_BrowserPath_Click(object sender, EventArgs e) 34 { 35 string BrowserPath = GetDefaultWebBrowserFilePath(); 36 txt_BrowserPath.Text = BrowserPath; 37 } 38 39 /// <summary> 40 /// 使用默认的浏览器打开指定的url地址 41 /// </summary> 42 /// <param name="sender"></param> 43 /// <param name="e"></param> 44 private void btn_gotoUrl_Click(object sender, EventArgs e) 45 { 46 string BrowserPath = GetDefaultWebBrowserFilePath(); 47 string gotoUrl = txt_url.Text; 48 if (!gotoUrl.StartsWith("http://")) 49 { 50 gotoUrl = "http://" + gotoUrl; 51 } 52 //如果输入的url地址为空,则清空url地址,浏览器默认跳转到默认页面 53 if (gotoUrl=="http://") 54 { 55 gotoUrl = ""; 56 } 57 System.Diagnostics.Process.Start(BrowserPath, gotoUrl); 58 }
  • 相关阅读:
    XSS平台简单使用
    XSS基础笔记 from 《Web安全攻防 渗透测试实战指南》
    《Web安全攻防渗透测试实战指南》 各类型 SQL注入 实验过程整理
    BurpSuite抓取本地包方法
    渗透测试之信息收集(Web安全攻防渗透测试实战指南第1章)
    渗透测试方法论(qf总结)
    Linux Shell脚本简单语法汇总(Deepin下运行)
    写一个方法去掉字符串中的空格
    link 与 @import 区别
    uni-app 开发小工具——uni-toolkit
  • 原文地址:https://www.cnblogs.com/jesn/p/2860367.html
Copyright © 2011-2022 走看看