-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
72 lines (65 loc) · 2.69 KB
/
Program.cs
File metadata and controls
72 lines (65 loc) · 2.69 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
namespace WPUService;
internal static class Program
{
private const string AppTitle = "Workstation Presence Utility";
[STAThread]
private static int Main(string[] args)
{
try { Installer.EnsureAumidRegistration(); } catch { }
try { NativeMethods.SetCurrentProcessExplicitAppUserModelID(AppIdentity.Aumid); } catch { }
ApplicationConfiguration.Initialize();
if (args.Length > 0)
{
var cmd = args[0].TrimStart('/', '-').ToLowerInvariant();
if (cmd is "install")
{
var ok = Installer.Install();
MessageBox.Show(
ok ? $"{AppTitle} installed.\n\nIt is now running in your system tray and will start automatically with Windows."
: $"{AppTitle} could not be installed.",
AppTitle,
MessageBoxButtons.OK,
ok ? MessageBoxIcon.Information : MessageBoxIcon.Error);
return ok ? 0 : 1;
}
if (cmd is "uninstall")
{
var ok = Installer.Uninstall();
MessageBox.Show(
ok ? $"{AppTitle} has been removed from this computer."
: $"{AppTitle} could not be fully removed.",
AppTitle,
MessageBoxButtons.OK,
ok ? MessageBoxIcon.Information : MessageBoxIcon.Error);
return ok ? 0 : 1;
}
}
if (!Installer.IsRunningFromInstallLocation())
{
var choice = MessageBox.Show(
$"Install {AppTitle} to your user profile so it starts with Windows?" +
"\n\nYes – Install and start" +
"\nNo – Run once from the current location" +
"\nCancel – Exit",
AppTitle,
MessageBoxButtons.YesNoCancel,
MessageBoxIcon.Question);
if (choice == DialogResult.Cancel) return 0;
if (choice == DialogResult.Yes)
{
var ok = Installer.Install();
MessageBox.Show(
ok ? $"{AppTitle} installed and started in your system tray."
: $"{AppTitle} could not be installed.",
AppTitle,
MessageBoxButtons.OK,
ok ? MessageBoxIcon.Information : MessageBoxIcon.Error);
return ok ? 0 : 1;
}
}
using var mutex = new Mutex(initiallyOwned: true, name: @"Global\WPUService.SingleInstance", out bool createdNew);
if (!createdNew) return 0;
Application.Run(new TrayContext());
return 0;
}
}