Link to home
Start Free TrialLog in
Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla

asked on

Kill the process using vbscript

Hi experts, I wish to stop or kill the running exe on  my computer using vbscript. I have a program running on my pc named, SkyWin.exe. This exe is found in c:\xFolder\SkyWin.exe and  I'm using Windows 10. Any help please!
Avatar of Michael Pfister
Michael Pfister
Flag of Germany image

Why use a VBscript? Use taskkill.exe;
taskkill /IM SkyWin.exe /F 

Open in new window

Avatar of Whing Dela Cruz

ASKER

Hi, Michael, I need to use it since I would execute the process remotely and I'm using vb script command. Thanks!
taskkill /IM SkyWin.exe /F /S RemoteSystemName 

Open in new window


If it has to be VBS, look here https://stackoverflow.com/questions/893237/how-to-terminate-process-using-vbscript
Hi, Michael, sample above is not working to my project. I'm using Windows 10 maybe this is not compatible...
Do you get an error message?
I didn't have error message, but the way I applied the code is like this..

Const strComputer = "."
Set WshShell = CreateObject("WScript.Shell")
Dim objWMIService, colProcessList
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'Calculator.exe'")
For Each objProcess in colProcessList
  WshShell.Exec "PSKill " & objProcess.ProcessId
Next
ASKER CERTIFIED SOLUTION
Avatar of Michael Pfister
Michael Pfister
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I've downloaded it all and have pasted it on my folder asp but still didn't work sir. Is there another way to achieve the goal? Thanks!
Maybe you should explain the "remote" requirement a bit.
Where is the process SkyWin.exe running? On a remote computer?
And you want to kill that process remotely? Maybe this helps....

Const strComputer = "Remotecomputername" 
  Dim objWMIService, colProcessList
  Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'Calculator.exe'")
  For Each objProcess in colProcessList 
    objProcess.Terminate() 
  Next  

Open in new window


Which is similar to
taskkill /IM SkyWin.exe /F /S Remotecomputername

Open in new window

Hi, Michael, I've tried to open Calculator.exe on my server computer and tried to execute the command vbscript on other computer thru ASP but still I've got the same result. My goal here is to kill or stop the exe  from running on my server computer using vbscript or .asp at server side.  I've tried the code suggested above but still didn't get my target. Thanks!
Does it work when executed on a command prompt bypassing ASP? This could be a permissions issue.
Is the ASP page on the remote computer where the process to kill runs?
Then this might help:
https://forums.asp.net/t/1197277.aspx?Identify+and+Kill+Process
Hi Michael, The code below is able to response the number of Calculator.exe running on my pc but not able to terminate the process.

strComputer = "SkyWin"
strProcessToKill = "Calculator.exe" 

SET objWMIService = GETOBJECT("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" _ 
	& strComputer & "\root\cimv2") 

SET colProcess = objWMIService.ExecQuery _
	("Select * from Win32_Process Where Name = '" & strProcessToKill & "'")

count = 0
FOR EACH objProcess in colProcess
	objProcess.Terminate()
	count = count + 1
NEXT 


response.Write("Killed " & count & " instances of " & _
	strProcessToKill & " on " & strComputer)

Open in new window

I'm not an ASP specialist but I really assume its a permission issue.
As I tried to open the calculator, the code above is responding "Killed 1 instances of Calculator.exe on SkyWin" this means that the asp and vbscript is working. My problem is why is it the code cannot terminate the process (calculator)?
Found that for ASP, can't verify here if it works.

Dim proc As System.Diagnostics.Process
For Each proc In System.Diagnostics.Process.GetProcessesByName("Calculator")
proc.Kill()
Next

Open in new window

Hi, Michael and Experts, I tried to run this code on command prompt and found a successful result, "taskkill /IM SkyWin9.exe /F /S MyServer" but when I applied the code below on VBScript it's no longer work or not able to kill the process. Which part of the code needs to modify? Any help, please!

 
Const strComputer = "MyServer" 
  Dim objWMIService, colProcessList
  Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'SkyWin9.exe'")
  
  count = 0
  For Each objProcess in colProcessList 
    objProcess.Terminate() 
  Next 

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No answer