-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (46 loc) · 1.41 KB
/
index.js
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
/**
* @file Launches the shortcut target PowerShell script with the selected markdown as an argument.
* @version 0.0.1.6
*/
/** The application execution. */
if (Param.Markdown) {
var CMD_EXE = 'C:\\Windows\\System32\\cmd.exe';
var CMD_LINE_FORMAT = '/d /c ""{0}" 2> "{1}""';
Package.IconLink.Create(Param.Markdown);
var startInfo = new ProcessStartInfo(CMD_EXE, String.Format(CMD_LINE_FORMAT, Package.IconLink.Path, ErrorLog.Path));
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
if (WaitForExit(Process.Start(ProcessStartInfo(startInfo)).Id)) {
with (ErrorLog) {
Read();
Delete();
}
}
Package.IconLink.Delete();
Quit(0);
}
/** Configuration and settings. */
if (Param.Set ^ Param.Unset) {
if (Param.Set) {
Setup.Set();
if (Param.NoIcon) {
Setup.RemoveIcon();
} else {
Setup.AddIcon();
}
} else if (Param.Unset) {
Setup.Unset();
}
Quit(0);
}
Quit(1);
/**
* Wait for the process exit.
* @param {int} processId is the process identifier.
* @returns {int} the exit status of the process.
*/
function WaitForExit(processId) {
// The process termination event query. Win32_ProcessStopTrace requires admin rights to be used.
var wqlQuery = "SELECT * FROM Win32_ProcessStopTrace WHERE ProcessName='cmd.exe' AND ProcessId=" + processId;
// Wait for the process to exit.
return (new ManagementEventWatcher(wqlQuery)).WaitForNextEvent()['ExitStatus'];
}