forked from paulirwin/JavaToCSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
105 lines (92 loc) · 3.04 KB
/
Copy pathProgram.cs
File metadata and controls
105 lines (92 loc) · 3.04 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace WebPageLauncher
{
class Program
{
static void Main(string[] args)
{
if (args == null || args.Length == 0)
{
Console.WriteLine("Usage: WebPageLauncher.exe [url]");
return;
}
var validuri = Uri.IsWellFormedUriString(args[0], UriKind.Absolute);
if (!validuri)
{
Console.WriteLine("URL given is not a valid URL!");
return;
}
Uri uri = new Uri(args[0], UriKind.Absolute);
if (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps)
{
Console.WriteLine("URL is not HTTP or HTTPS!");
return;
}
try
{
string keyValue = Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Software\Classes\http\shell\open\command", "", null) as string;
if (string.IsNullOrEmpty(keyValue) == false)
{
string browserPath = keyValue.Replace("%1", args[0]);
System.Diagnostics.Process.Start(browserPath);
return;
}
}
catch { }
try
{
System.Diagnostics.Process.Start(args[0]); //browserPath, argUrl);
return;
}
catch { }
try
{
string browserPath = GetWindowsPath("explorer.exe");
string argUrl = "\"" + args[0] + "\"";
System.Diagnostics.Process.Start(browserPath, argUrl);
return;
}
catch { }
}
internal static string GetWindowsPath(string p_fileName)
{
string path = null;
string sysdir;
for (int i = 0; i < 3; i++)
{
try
{
if (i == 0)
{
path = Environment.GetEnvironmentVariable("SystemRoot");
}
else if (i == 1)
{
path = Environment.GetEnvironmentVariable("windir");
}
else if (i == 2)
{
sysdir = Environment.GetFolderPath(Environment.SpecialFolder.System);
path = System.IO.Directory.GetParent(sysdir).FullName;
}
if (path != null)
{
path = System.IO.Path.Combine(path, p_fileName);
if (System.IO.File.Exists(path) == true)
{
return path;
}
}
}
catch { }
}
// not found
return null;
}
}
}