Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript to get running processes?

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 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.

like image 896
Matt Dalgety Avatar asked Nov 12 '11 00:11

Matt Dalgety


4 Answers

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.

like image 128
jfriend00 Avatar answered Nov 20 '22 01:11

jfriend00


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>
like image 42
Ajaiya K Pandey Avatar answered Nov 20 '22 00:11

Ajaiya K Pandey


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

like image 2
Ben Brocka Avatar answered Nov 20 '22 00:11

Ben Brocka


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.

like image 2
Julien Kronegg Avatar answered Nov 20 '22 02:11

Julien Kronegg