-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
42 lines (39 loc) · 1.58 KB
/
Copy pathProgram.cs
File metadata and controls
42 lines (39 loc) · 1.58 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
using System;
using System.Diagnostics;
namespace Windows10Hotspot
{
class Program
{
static string magicCode = "[Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager, Windows.Networking.NetworkOperators, ContentType=WindowsRuntime]::CreateFromConnectionProfile([Windows.Networking.Connectivity.NetworkInformation, Windows.Networking.Connectivity, ContentType=WindowsRuntime]::GetInternetConnectionProfile())";
static void Main(string[] args)
{
var setToON = String.Join(" ", args).ToUpper() switch
{
"ON" => true,
"OFF" => false,
_ => throw new Exception("Invalid parameter. Please specify ON or OFF")
};
var Process = new Process();
Process.StartInfo = new ProcessStartInfo
{
FileName = "Powershell",
Arguments = $"{magicCode}. {(setToON ? "Start" : "Stop")}TetheringAsync()",
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = false,
};
Process.Start();
Process.WaitForExit();
if (Process.ExitCode == 0)
{
Console.WriteLine($"Hostpot should be {(setToON ? "ON" : "OFF")} now");
}
else
{
Console.WriteLine("Error. Exit code: " + Process.ExitCode);
}
}
}
}