Javascript to get running processes?

后端 未结 4 637
旧时难觅i
旧时难觅i 2020-12-19 06:36

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?

I\'m not trying to start any

相关标签:
4条回答
  • 2020-12-19 07:00

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

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

    <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

    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

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

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

    0 讨论(0)
  • 2020-12-19 07:03
    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>
    
    0 讨论(0)
  • 2020-12-19 07:05

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

    0 讨论(0)
  • 2020-12-19 07:24

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

    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.

    If you are willing to loosen up your security settings, some versions of IE contain some ability to access OS information (see here for 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.

    0 讨论(0)
提交回复
热议问题