@@ -11,7 +11,7 @@ public static class SearchWeb
11
11
/// Opens search in a new browser. If no browser path is passed in then Chrome is used.
12
12
/// Leave browser path blank to use Chrome.
13
13
/// </summary>
14
- public static void NewBrowserWindow ( this string url , string browserPath )
14
+ public static void NewBrowserWindow ( this string url , string browserPath = "" )
15
15
{
16
16
var browserExecutableName = browserPath ?
17
17
. Split ( new [ ] { Path . DirectorySeparatorChar } , StringSplitOptions . None )
@@ -22,41 +22,47 @@ public static void NewBrowserWindow(this string url, string browserPath)
22
22
// Internet Explorer will open url in new browser window, and does not take the --new-window parameter
23
23
var browserArguements = browserExecutableName == "iexplore.exe" ? url : "--new-window " + url ;
24
24
25
+ var psi = new ProcessStartInfo
26
+ {
27
+ FileName = browser ,
28
+ Arguments = browserArguements ,
29
+ UseShellExecute = true
30
+ } ;
31
+
25
32
try
26
33
{
27
- Process . Start ( browser , browserArguements ) ;
34
+ Process . Start ( psi ) ;
28
35
}
29
36
catch ( System . ComponentModel . Win32Exception )
30
37
{
31
- var psi = new ProcessStartInfo
32
- {
33
- FileName = url ,
34
- UseShellExecute = true
35
- } ;
36
- Process . Start ( psi ) ;
38
+ Process . Start ( new ProcessStartInfo { FileName = url , UseShellExecute = true } ) ;
37
39
}
38
40
}
39
41
40
42
/// <summary>
41
43
/// Opens search as a tab in the default browser chosen in Windows settings.
42
44
/// </summary>
43
- public static void NewTabInBrowser ( this string url , string browserPath )
45
+ public static void NewTabInBrowser ( this string url , string browserPath = "" )
44
46
{
47
+ var psi = new ProcessStartInfo ( ) { UseShellExecute = true } ;
45
48
try
46
49
{
47
50
if ( ! string . IsNullOrEmpty ( browserPath ) )
48
51
{
49
- Process . Start ( browserPath , url ) ;
52
+ psi . FileName = browserPath ;
53
+ psi . Arguments = url ;
50
54
}
51
55
else
52
56
{
53
- Process . Start ( url ) ;
57
+ psi . FileName = url ;
54
58
}
59
+
60
+ Process . Start ( psi ) ;
55
61
}
56
- // This error may be thrown for Process.Start(browserPath, url)
62
+ // This error may be thrown if browser path is incorrect
57
63
catch ( System . ComponentModel . Win32Exception )
58
64
{
59
- Process . Start ( url ) ;
65
+ Process . Start ( new ProcessStartInfo { FileName = url , UseShellExecute = true } ) ;
60
66
}
61
67
}
62
68
}
0 commit comments