forked from gitextensions/gitextensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
OsShellUtil.cs
45 lines (41 loc) · 1.48 KB
/
OsShellUtil.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
using System.Diagnostics;
using System.Text.RegularExpressions;
using Microsoft.Win32;
namespace GitUI
{
public static class OsShellUtil
{
public static void OpenAs(string file)
{
Process.Start(new ProcessStartInfo
{
UseShellExecute = false,
RedirectStandardOutput = true,
FileName = "rundll32.exe",
Arguments = "shell32.dll,OpenAs_RunDLL " + file
});
}
public static void SelectPathInFileExplorer(string filePath)
{
Process.Start("explorer.exe", "/select, " + filePath);
}
public static void OpenWithFileExplorer(string filePath)
{
Process.Start("explorer.exe", filePath);
}
/// <summary>
/// opens urls even with anchor
/// </summary>
public static void OpenUrlInDefaultBrowser(string url)
{
// Process.Start(url); / does not work with anchors: http://stackoverflow.com/questions/2404449/process-starturl-with-anchor-in-the-url
var openSubKey = Registry.ClassesRoot.OpenSubKey(@"\http\shell\open\command\");
if (openSubKey != null)
{
var browserRegistryString = openSubKey.GetValue("").ToString();
var defaultBrowserPath = Regex.Match(browserRegistryString, @"(\"".*?\"")").Captures[0].ToString();
Process.Start(defaultBrowserPath, url);
}
}
}
}