-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.vb
56 lines (51 loc) · 1.85 KB
/
Program.vb
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
''' <summary>Launch the shortcut's target PowerShell script with the markdown.</summary>
''' <version>0.0.1.5</version>
Imports System.Diagnostics
Imports System.Management
Namespace cvmd2html
Module Program
Sub Main
' The application execution.
If MarkdownPathParam IsNot Nothing Then
Const CMD_EXE As String = "C:\Windows\System32\cmd.exe"
Const CMD_LINE_FORMAT As String = "/d /c """"{0}"" 2> ""{1}"""""
IconLink.Create(MarkdownPathParam)
If WaitForExit(Process.Start(New ProcessStartInfo With {
.FileName = CMD_EXE,
.Arguments = String.Format(CMD_LINE_FORMAT, IconLink.Path, ErrorLog.Path),
.WindowStyle = ProcessWindowStyle.Hidden
}).Id) Then
ErrorLog.Read
ErrorLog.Delete
End If
IconLink.Delete
Quit(0)
End If
' Configuration and settings.
If SetConfigParam Xor UnsetConfigParam Then
If SetConfigParam Then
SetShortcut
If CBool(NoIconConfigParam) Then
RemoveIcon
Else
AddIcon
End If
ElseIf UnsetConfigParam Then
UnsetShortcut
End If
Quit(0)
End If
Quit(1)
End Sub
''' <summary>Wait for the process exit.</summary>
''' <param name="processId">The process identifier.</param>
''' <returns>The exit status of the process.</returns>
Private _
Function WaitForExit(processId As Integer) As UInteger
' The process termination event query. Win32_ProcessStopTrace requires admin rights to be used.
Dim wqlQuery As String = "SELECT * FROM Win32_ProcessStopTrace WHERE ProcessName='cmd.exe' AND ProcessId=" & processId
' Wait for the process to exit.
Return (New ManagementEventWatcher(wqlQuery)).WaitForNextEvent()("ExitStatus")
End Function
End Module
End Namespace