-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
84 lines (77 loc) · 2.35 KB
/
Program.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/// <summary>Launch the shortcut's target PowerShell script with the markdown.</summary>
/// <version>0.0.1.6</version>
using System;
using System.Diagnostics;
using System.Reflection;
using System.Management;
namespace cvmd2html
{
static class Program
{
static void Main()
{
/** The application execution. */
if (!String.IsNullOrEmpty(Parameters.Markdown))
{
const string CMD_EXE = @"C:\Windows\System32\cmd.exe";
const string CMD_LINE_FORMAT = @"/d /c """"{0}"" 2> ""{1}""""";
Package.IconLink.Create(Parameters.Markdown);
if (WaitForExit(Process.Start(
new ProcessStartInfo
{
FileName = CMD_EXE,
Arguments = String.Format(CMD_LINE_FORMAT, Package.IconLink.Path, ErrorLog.Path),
WindowStyle = ProcessWindowStyle.Hidden
}
).Id) != 0)
{
ErrorLog.Read();
ErrorLog.Delete();
}
Package.IconLink.Delete();
Quit(0);
}
/** Configuration and settings. */
if (Parameters.Set ^ Parameters.Unset)
{
if (Parameters.Set)
{
Setup.Set();
if ((bool)Parameters.NoIcon)
{
Setup.RemoveIcon();
}
else
{
Setup.AddIcon();
}
}
else if (Parameters.Unset)
{
Setup.Unset();
}
Quit(0);
}
Quit(1);
}
/// <summary>The path to the application.</summary>
internal static readonly string Path = Assembly.GetExecutingAssembly().Location;
/// <summary>Wait for the process exit.</summary>
/// <param name="processId">The process identifier.</param>
/// <returns>The exit status of the process.</returns>
static uint WaitForExit(int processId)
{
// The process termination event query. Win32_ProcessStopTrace requires admin rights to be used.
var wmiQuery = "SELECT * FROM Win32_ProcessStopTrace WHERE ProcessName='cmd.exe' AND ProcessId=" + processId;
// Wait for the process to exit.
return (uint)new ManagementEventWatcher(wmiQuery).WaitForNextEvent()["ExitStatus"];
}
/// <summary>Clean up and quit.</summary>
/// <param name="exitCode">The exit code.</param>
internal static void Quit(int exitCode)
{
GC.Collect();
Environment.Exit(exitCode);
}
}
}