【问题标题】:Trying to access system running processes试图访问系统运行的进程
【发布时间】:2014-05-08 18:43:21
【问题描述】:

我正在尝试使用此代码访问正在运行的系统进程,它运行良好并显示所有正在运行的进程,但是当我从我的 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 文件...

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”页面来停止任何正在运行的进程。

【问题讨论】:

  • ajax 调用实际上是在访问服务器吗?
  • 在 firefox 中运行控制台时,它会显示......主线程上的同步 XMLHttpRequest 已被弃用,因为它会对最终用户的体验产生不利影响。更多帮助xhr.spec.whatwg.orguser.htm:10 TypeError: xmlDoc is null

标签: c# asp.net web-services


【解决方案1】:

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

【讨论】:

猜你喜欢
  • 2011-05-13
  • 1970-01-01
  • 2012-08-20
  • 1970-01-01
  • 2017-09-10
  • 2016-07-22
  • 1970-01-01
  • 1970-01-01
  • 2018-10-21
相关资源
最近更新 更多