Javascript 来获取正在运行的进程?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8101364/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 02:17:32  来源:igfitidea点击:

Javascript to get running processes?

javascriptprocess

提问by Matt Dalgety

I'm wondering if it's possible to use Javascript in a web browser (most likely IE) to retrieve a list of currently running processes?

我想知道是否可以在 Web 浏览器(最有可能是 IE)中使用 Javascript 来检索当前正在运行的进程列表?

I'm not trying to start any processes or close them or anything like that. Just a list that I can check through then say for example do something else if a certain process is running.

我不是要启动任何进程或关闭它们或类似的东西。只是一个我可以检查的列表,然后说例如,如果某个进程正在运行,请执行其他操作。

采纳答案by jfriend00

No, you cannot get any information about OS processes from browser-based javascript running at normal privileges.

不,您无法从以正常权限运行的基于浏览器的 javascript 获取有关操作系统进程的任何信息。

The browser javascript environment is very carefully protected and isolated from your system for privacy and security reasons. If one could do what you were just asking for then any web page on the internet could see exactly what programs you were running and could send that info back to their own servers.

出于隐私和安全原因,浏览器 javascript 环境受到非常谨慎的保护并与您的系统隔离。如果一个人可以做您所要求的事情,那么互联网上的任何网页都可以准确地看到您正在运行的程序,并且可以将该信息发送回他们自己的服务器。

If you are willing to loosen up your security settings, some versions of IE contain some ability to access OS information (see herefor an example), but you should realize that if you do loosen up your security settings, then unknown web pages may be able to access this info or take actions in your OS also. Other browsers don't even contain this capability for regular web pages. With only one browser supporting this and only when security restrictions are relaxed, this is not a general purpose browser capability in any way.

如果您愿意放宽安全设置,某些版本的 IE 包含一些访问操作系统信息的能力(参见此处的示例),但您应该意识到,如果您放宽安全设置,则可能会出现未知网页也可以访问此信息或在您的操作系统中执行操作。其他浏览器甚至不包含用于常规网页的此功能。只有一个浏览器支持这一点,并且只有在安全限制放宽时,这在任何方面都不是通用的浏览器功能。

回答by Ajaiya K Pandey

Here is JSP page-

<html>
<head>
<title>Find running processes</title>
<script type="text/jscript">
function getProcessList()
{
  var procs = GetObject("WinMgmts:").InstancesOf("Win32_Process");
  var mainRes = "";
  procEnum = new Enumerator(procs);
  for ( ; !procEnum.atEnd(); procEnum.moveNext())
  {
    var proc = procEnum.item();   
    mainRes += proc.Name + ": " + proc.ProcessID + "\n";
  } 
  return mainRes;
}

function getSysRunningApps()
{
  var oOutput = document.getElementById("processDisplay");
  oOutput.value = "";
  oOutput.value = getProcessList();
}

</script>
</head>

<body bgcolor="#FFFFFF">
<input type="button" value="Show Processes" onclick="getSysRunningApps();"><br>
<p id="processDisplay" cols="30" rows="40"></p>
</body>
</html>

回答by Julien Kronegg

Yes, you can! The following approach targets only MSIE and may raise security warnings.

是的你可以!以下方法仅针对 MSIE,可能会引发安全警告。

When executed under MSIE, the following code lists all Windows processes in the browser window and shows a javascript alert if McAfee is running:

在 MSIE 下执行时,以下代码会列出浏览器窗口中的所有 Windows 进程,并在 McAfee 正在运行时显示 javascript 警报:

<html>
  <body>
    <div id="list"></div>
  </body>
  <script>
    // create a shell object and exec handle
    var shell = new ActiveXObject('WScript.Shell');
    var handle = shell.Exec("tasklist.exe");

    // loop through the output of tasklist.exe
    while (!handle.StdOut.AtEndOfStream) {
      // grab a line of text
      var p = handle.StdOut.ReadLine();
      document.getElementById("list").innerHTML+=p+"<br>"; // for debugging
      // split on space
      p = p.split(' ');
      if (p[0]=='mcshield.exe') {
        alert("McAfee detected");
      }
    } // end :: while

    // clean up
    handle = null;
    shell=null;
</script>
</html>

Credit: inspired by https://stackoverflow.com/a/6834585/698168

信用:灵感来自https://stackoverflow.com/a/6834585/698168

This code was tested under the following browsers:

此代码在以下浏览器下进行了测试:

  • MSIE 8.0.6001.18702 / Windows XP Pro
  • MSIE 10.0.9200.16521 / Windows 7 ; Standard document mode
  • MSIE 11.0.9600.16428 / Windows 7 ; Edge (aka MSIE11) document mode
  • MSIE 8.0.6001.18702 / Windows XP 专业版
  • MSIE 10.0.9200.16521 / Windows 7 ; 标准文档模式
  • MSIE 11.0.9600.16428 / Windows 7 ; Edge(又名 MSIE11)文档模式

If you got a JavaScript error Automation server can't create objectwhen creating the ActiveXObject, you may need to set MSIE's Security option Initialize and script ActiveX controls not marked as safe for scriptingto either Promptor Enable.

如果您Automation server can't create object在创建 时遇到 JavaScript 错误ActiveXObject,您可能需要将 MSIE 的安全选项Initialize and script ActiveX controls not marked as safe for scripting设置为PromptEnable

Under Firefox, you should use something based on XPCOM's nsIProcess. Note that tasklist.exeis not available under all Windows version: AFAIK it's available since Windows XP Pro.

在 Firefox 下,您应该使用基于XPCOM 的 nsIProcess 的东西。请注意,tasklist.exe并非在所有 Windows 版本下都可用:AFAIK 自 Windows XP Pro 以来可用。

回答by Ben Brocka

Absolutely not, that's well beyond what the Javascript sandbox should be able to do.

绝对不是,这远远超出了 Javascript 沙箱应该能够做的事情。