1 |
#Region "Microsoft.VisualBasic::73eabd33bd813f254599a3b524614e9e, Microsoft.VisualBasic.Core\ApplicationServices\Terminal\STDIO__\Shell.vb"
|
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 |
#End Region
|
44 |
|
45 |
Imports System.Text.RegularExpressions
|
46 |
Imports System.Runtime.InteropServices
|
47 |
|
48 |
Namespace Terminal.STDIO__
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
To change this template use Tools | Options | Coding | Edit Standard Headers.
|
56 |
|
57 |
|
58 |
Public Module Shell
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
Modify the Application.Run() statement To create the proper startup form, If necessary.
|
65 |
</summary>
|
66 |
<returns></returns>
|
67 |
Public Declare Auto Function AllocConsole Lib "kernel32.dll" () As Boolean
|
68 |
|
69 |
<DllImport("user32.dll")>
|
70 |
Public Function ShowWindow(hWnd As IntPtr, nCmdShow As Integer) As Boolean
|
71 |
End Function
|
72 |
|
73 |
<DllImport("kernel32")>
|
74 |
Public Function GetConsoleWindow() As IntPtr
|
75 |
End Function
|
76 |
|
77 |
<DllImport("Kernel32")>
|
78 |
Private Function SetConsoleCtrlHandler(handler As EventHandler, add As Boolean) As Boolean
|
79 |
End Function
|
80 |
|
81 |
Private ReadOnly hConsole As IntPtr = GetConsoleWindow()
|
82 |
|
83 |
Public Sub HideConsoleWindow()
|
84 |
If IntPtr.Zero <> hConsole Then
|
85 |
Call ShowWindow(hConsole, 0)
|
86 |
End If
|
87 |
End Sub
|
88 |
|
89 |
|
90 |
为WinForm应用程序分配一个终端窗口,这个函数一般是在Debug模式之下进行程序调试所使用的
|
91 |
</summary>
|
92 |
Public Sub ShowConsoleWindows()
|
93 |
If IntPtr.Zero <> hConsole Then
|
94 |
Call ShowWindow(hConsole, 1)
|
95 |
End If
|
96 |
End Sub
|
97 |
|
98 |
|
99 |
|
100 |
</summary>
|
101 |
<param name="CommandLine"></param>
|
102 |
<param name="WindowStyle"></param>
|
103 |
<param name="WaitForExit">If NOT, then the function returns the associated process id value. Else returns the process exit code.</param>
|
104 |
<returns></returns>
|
105 |
<remarks></remarks>
|
106 |
Public Function Shell(CommandLine As String, Optional WindowStyle As System.Diagnostics.ProcessWindowStyle = ProcessWindowStyle.Normal, Optional WaitForExit As Boolean = False) As Integer
|
107 |
Dim Tokens = Regex.Split(CommandLine, Global.Microsoft.VisualBasic.CommandLine.SPLIT_REGX_EXPRESSION)
|
108 |
Dim EXE As String = Tokens.First
|
109 |
Dim Arguments As String = Mid$(CommandLine, Len(EXE) + 1)
|
110 |
Dim Process As System.Diagnostics.Process = New Process
|
111 |
Dim pInfo As System.Diagnostics.ProcessStartInfo = New ProcessStartInfo(EXE, Arguments)
|
112 |
|
113 |
Process.StartInfo = pInfo
|
114 |
Process.StartInfo.WindowStyle = WindowStyle
|
115 |
|
116 |
Call Process.Start()
|
117 |
|
118 |
If Not WaitForExit Then Return Process.Id
|
119 |
|
120 |
Call Process.WaitForExit()
|
121 |
Return Process.ExitCode
|
122 |
End Function
|
123 |
End Module
|
124 |
End Namespace
|