试图访问系统运行进程

时间:2014-05-08 18:43:21

标签: c# asp.net web-services

我正在尝试使用此代码访问正在运行的系统进程,它工作得非常好并显示所有正在运行的进程但是当我从我的visual studio 2012发布它之后它不会显示进程但是一个空白页面,我已禁用Windows和防病毒防火墙,但后来也无法正常工作....

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Processes</title>
<script language="javascript" type="text/javascript">
    window.onload = BoomBoom;
    function BoomBoom() {
        //var prodId = 1;
        var Soap_a = "<?xml version=\"1.0\" encoding=\"utf-8\"?><soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><HelloWorld xmlns=\"http://tempuri.org/\"></HelloWorld></soap:Body></soap:Envelope>";

        var xhr = new XMLHttpRequest();
        xhr.open("POST", "WebService.asmx", false);
        xhr.setRequestHeader("Content-Type", "text/xml;charset=utf-8");
        xhr.setRequestHeader("Content-Length", Soap_a.length.toString());
        xhr.setRequestHeader("SOAPAction", "\"http://tempuri.org/HelloWorld\"");
        xhr.send(Soap_a);
        var xmlDoc = xhr.responseXML;

        var resultNodee = xmlDoc.getElementsByTagName("HelloWorldResult");
        var result = resultNodee[0].childNodes[0].data;

        document.getElementById("resu").innerHTML = result;
        //alert(result);
        /*.childNodes[0].data;
        alert(result);*/
        return result;
    }

</script>

</head>
<body link="red">
<div id="resu"></div>
</body>
</html>

webservice.asmx文件...     &lt;%@ WebService Language =“C#”CodeBehind =“〜/ App_Code / WebService.cs”Class =“WebService”%&gt;

webservice.cs文件..

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Diagnostics;


/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
String s1;

public WebService () {

    //Uncomment the following line if using designed components 
    //InitializeComponent(); 
}

[WebMethod]
public string HelloWorld() {


    foreach (System.Diagnostics.Process winProc in System.Diagnostics.Process.GetProcesses())
    {

        s1 = s1 + String.Format("<font size=3 face=verdana color=red></br><a href=killprocess.htm?code={0}>{0}</a></font>", winProc.ProcessName.ToString());

    }
    return s1;
}

}

我使用“killprocess.htm”页面停止任何正在运行的进程。

1 个答案:

答案 0 :(得分:0)

Web应用程序需要完全信任才能使用System.Diagnostics.Process.GetProcesses()。