2014-05-08 36 views
0

我试图访问正在运行的系统进程使用这段代码,它工作得很好,并显示所有正在运行的进程,但之后当我从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的语言= “C#” 代码隐藏= “〜/ App_Code/WebService.cs”Class =“WebService”%>

webservice.cs file ..

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

+0

是实际打到服务器的ajax调用? – ManyRootsofAllEvil

+0

在firefox中运行控制台时显示....主线程上的同步XMLHttpRequest已弃用,因为它对最终用户的体验有不利影响。更多帮助http://xhr.spec.whatwg.org/user.htm:10 TypeError:xmlDoc为空 – Deepanshu

回答

0

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

+0

另请参见:http://msdn.microsoft.com/en-us/library/vstudio/wyts434y( v = vs.100).aspx – TrevorBrooks

+0

它显示了这一点,而我在firefox中运行控制台....主线程上的同步XMLHttpRequest已弃用,因为它对最终用户的体验有不利影响。更多帮助http://xhr.spec.whatwg.org/user.htm:10 TypeError:xmlDoc为空 – Deepanshu