0

I am looking to make a short javascript code that Kills a process running on my windows machine (i am developing the program on 7 but it must be run when in production on server 2003). I have started with the following code:

w = new ActiveXObject("WScript.Shell");
w.run("taskkill.exe /im iexpore.exe");
return true;

I need to make the process that is killed something that i pass in though. There are many different things to kill and i have another program that determines what one is killed.

I have the following code now but it still doesnt work:

Dim prcid
Dim check
Dim Inp
Set Inp = WScript.Arguments
check=0
Set objService = GetObject("winmgmts:")

For Each Process In objService.InstancesOf("Win32_process")
  If process.name= "Inp" Then
    prcid=process.processid
    check=1
    Exit For
  End If
Next

If check =0 Then
  WScript.Quit [ExitCode]
End if

For Each process In objService.InstancesOf("Win32_process")
  If process.name= "Inp" Then
    If process.processid=prcid Then
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:" _ 
          & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
        Set colProcessList = objWMIService.ExecQuery _
          ("SELECT * FROM Win32_Process WHERE Name = 'Inp'")
        For Each objProcess in colProcessList
            objProcess.Terminate()
        Next
    End If

    Exit For
  End If
Next
user1512885
  • 3
  • 1
  • 5

2 Answers2

0

I assume you are using Windows Script Host.

You can access the arguments to your script like this :

objArgs = WScript.Arguments;
for (i = 0; i < objArgs.length; i++)
{
   WScript.Echo(objArgs(i));
}

I assume you will want to pass the process you want to kill as a parameter to the script.

T.

tomdemuyt
  • 4,572
  • 2
  • 31
  • 60
  • with the program i have to integrate this with (Automation Anywhere) i only get to access 1 .js file and pass in parameters. So how does what you have said fit in with that? Sorry, im just not very familiar with js – user1512885 Jul 09 '12 at 19:28
  • This example code will loop over the parameters you give to the .js file and write them out. In your case you will not just want to write them out but use them to construct the right string for w.run() – tomdemuyt Jul 09 '12 at 19:29
-1

You've mentioned javascript but your code is VB Script, so should have a .vbs extention. Could that be your problem?

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108