Whing Dela Cruz
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!
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
If it has to be VBS, look here https://stackoverflow.com/
ASKER
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?
ASKER
I didn't have error message, but the way I applied the code is like this..
Const strComputer = "."
Set WshShell = CreateObject("WScript.Shel l")
Dim objWMIService, colProcessList
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=imper sonate}!\\ " & strComputer & "\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("S ELECT * FROM Win32_Process WHERE Name = 'Calculator.exe'")
For Each objProcess in colProcessList
WshShell.Exec "PSKill " & objProcess.ProcessId
Next
Const strComputer = "."
Set WshShell = CreateObject("WScript.Shel
Dim objWMIService, colProcessList
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=imper
Set colProcessList = objWMIService.ExecQuery("S
For Each objProcess in colProcessList
WshShell.Exec "PSKill " & objProcess.ProcessId
Next
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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....
Which is similar to
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
Which is similar to
taskkill /IM SkyWin.exe /F /S Remotecomputername
ASKER
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/1 197277.asp x?Identify +and+Kill+ Process
Then this might help:
https://forums.asp.net/t/1
ASKER
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)
I'm not an ASP specialist but I really assume its a permission issue.
ASKER
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
ASKER
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
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No answer
Open in new window