Hi hansheung,
Refer the below sample code.
Namespaces
using Microsoft.Win32;
using System.Diagnostics;
using System.Threading;
C#
string browser = string.Empty;
RegistryKey key = null;
try
{
key = Registry.ClassesRoot.OpenSubKey(@"HTTP\shell\open\command");
if (key != null)
{
// Get default Browser
browser = key.GetValue(null).ToString().ToLower().Trim(new[] { '"' });
}
if (!browser.EndsWith("exe"))
{
//Remove all after the ".exe"
browser = browser.Substring(0, browser.LastIndexOf(".exe", StringComparison.InvariantCultureIgnoreCase) + 4);
}
}
finally
{
if (key != null)
{
key.Close();
}
}
// Open the browser.
Process proc = Process.Start(browser, "https://www.aspsnippets.com/");
if (proc != null)
{
Thread.Sleep(5000);
// Close the browser.
proc.Kill();
}
Namespaces
Imports Microsoft.Win32
Imports System.Diagnostics
Imports System.Threading
VB.Net
Dim browser As String = String.Empty
Dim key As RegistryKey = Nothing
Try
key = Registry.ClassesRoot.OpenSubKey("HTTP\shell\open\command")
If key IsNot Nothing Then
' Get default Browser
browser = key.GetValue(Nothing).ToString().ToLower().Trim(New Char() {""""C})
End If
If Not browser.EndsWith("exe") Then
'Remove all after the ".exe"
browser = browser.Substring(0, browser.LastIndexOf(".exe", StringComparison.InvariantCultureIgnoreCase) + 4)
End If
Finally
If key IsNot Nothing Then
key.Close()
End If
End Try
' Open the browser.
Dim proc As Process = Process.Start(browser, "https://www.aspsnippets.com/")
If proc IsNot Nothing Then
Thread.Sleep(5000)
' Close the browser.
proc.Kill()
End If
I have refered the below link for reference.
https://stackoverflow.com/questions/10701599/open-a-chrome-tab-and-close-it