-
Notifications
You must be signed in to change notification settings - Fork 163
/
Launcher.cs
62 lines (56 loc) · 1.8 KB
/
Launcher.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System.Deployment.Application;
using System.Diagnostics;
using System.Reflection;
using System.Security.Principal;
using System.Web;
namespace Boxstarter.WebLaunch
{
public class Launcher
{
public static void Main(string[] args)
{
var psArgs = string.Empty;
if (args.Length > 0)
{
psArgs = args[0];
if (args.Length > 1)
{
psArgs += " -DisableReboots";
}
}
else if (ApplicationDeployment.IsNetworkDeployed && ApplicationDeployment.CurrentDeployment.ActivationUri != null)
{
var queryString = ApplicationDeployment.CurrentDeployment.ActivationUri.Query;
if(queryString != null)
{
psArgs = HttpUtility.ParseQueryString(queryString)["package"];
if(HttpUtility.ParseQueryString(queryString)["noreboot"] != null)
{
psArgs += " -DisableReboots";
}
}
}
var fileToRun = "boxstarter.bat";
if (!IsRunAsAdministrator())
{
fileToRun = Assembly.GetExecutingAssembly().CodeBase;
}
else
{
psArgs += " -KeepWindowOpen";
}
var processInfo = new ProcessStartInfo(fileToRun)
{
Verb = "runas",
Arguments = psArgs
};
Process.Start(processInfo);
}
private static bool IsRunAsAdministrator()
{
var wi = WindowsIdentity.GetCurrent();
var wp = new WindowsPrincipal(wi);
return wp.IsInRole(WindowsBuiltInRole.Administrator);
}
}
}