I'm using a script that, upon logging in, loads Remote Desktop Protocol (RDP) and pushes the user to a Virtual Desktop Environment (VDI), along with their credentials. The script does not allow the next command 'Shutdown /l' to run until it is finished running.
The problem I'm having is that once in the VDI, RDP tries to load up again. How do I prevent this from happening? Thank you in advanced.
start /wait \\ph-vda\C$\VDI_Users_RDP\%username%.rdp /multimon /noConsentPrompt
Shutdown /l
I think what you're describing is that the same script is running when the user logs in, even when they log into the VDI. You don't want the script to run in the VDI. If that's right, here's one idea.
#echo off
if exist "%userprofile%\in_vdi" goto :eof
type nul >"%userprofile%\in_vdi"
start /wait \\ph-vda\C$\VDI_Users_RDP\%username%.rdp /multimon /noConsentPrompt
del "%userprofile%\in_vdi"
Shutdown /l
I need to restart explorer.exe after my application is installed. I'm currently using:
taskkill /f /im explorer.exe
start explorer.exe
That works ok on windows 7, with administrator or standard user, but when I try this on windows 8 as a standard user, the command just kills the explorer and doesn't restart it.
This happens because the command line is called as administrator, even with the standard user. Then the explorer doesn't restart.
Any thoughts about how to solve this?
The code should work but since I'm not using win8 (no thanks) can not diagnose.
But some I can offer.
This may work (time needed to unload some handlers) And double tried with or without start (yes it differs in some software, don't know win8)
taskkill /f /im explorer.exe
timeout 7
start "" explorer.exe
timeout 2
explorer.exe
explorer.exe keeps many handlers, shell stuff etc. One of those can cause trouble. Try also to disable them and test again
If not you can also try reexplorer tool to do the same. Maybe they considered this kind of situations while coding.
All bests
I am looking for a way to kill a windows services using its service name rather than the process name, or PID. The two obvious choices are pskill or taskkill, but I cannot seem to find a way of using either of these methods to kill the service by name.
Is it possible to do it by the service name? If so, is anyone able to provide a quick example?
You can use taskkill to filter by service name and kill the service you're looking for.
taskkill /F /FI "SERVICES eq yourservice"
Do you actually want to KILL the process (e.g. if it is frozen) or do you want to STOP the service?
If you want to kill it stick to SomethingDark's answer (taskkill /F /FI "SERVICES eq yourservice").
If you want to stop it use SC STOP "servicename".
In case you have multiple services with the same image name, using the SERVICES filter may not be sufficient. In this case, you need to use more filters like IMAGENAME, PID, STATUS or more.
See my related answer here
with taskkill loop (be careful with closing system processes) (save winservices.bat and run as admin)
call :winservices "service_name1"
call :winservices "service_name2"
:: funcion winservices
#echo off
goto:eof
:winservices
set winservices=%1
taskkill /f /im "%winservices%" /t
goto:eof
source: https://serverfault.com/questions/1005487/how-to-stop-start-and-delete-a-windows-service-with-a-reference-to-the-service
When I start up an Experimental instance of VS from VS for debugging and stop debugging (sometimes directly from the parent VS), a zombile devenv.exe process remains running which I am unable to kill. It holds on to many of my dlls.
As I am logged onto this 64bit Win7 machine as Administrator, I would expect to be able to kill any process I wish to.
I tried (from Administrator command prompt):
End Task from Task Manager.
TASKKILL /F /IM devenv.exe
PSKILL devenv.exe
None return any error and TASKKILL and PSKILL returned success messages of terminating/killing the process. But devenv.exe still runs, it is not re-spawned as the PID remains constant. It goes away only on restart of the system which is not a great solution.
Note. LockHunter shows devenv has got a lock on itself. And it cannot unlock it.
The above screenshot is the output of Process Monitor showing devenv to be in some kind of 'Process Profiling' loop (Right click on it and click open image in new tab to see it properly).
Any ideas how to kill such a process on Windows?
you must kill child process too if any spawned to kill successfully your process
taskkill /IM "process_name" /T /F
/T = kills child process
/F = forceful termination of your process
The taskkill and powershell (kill) methods didn't work for me; it still said "Access Denied".
I had better luck with this:
wmic process where "name='myprocessname.exe'" delete
Reboot is the only solution that worked for me (so far).
The ever excellent Mark Russonovich has a good explanation for unkillable processes.
To summarise, it's quite possible it is due to unprocessed I/O requests that hasn't been handled properly (by a device driver your program has possibly accessed)
https://techcommunity.microsoft.com/t5/windows-blog-archive/unkillable-processes/ba-p/723389
Just had the same issue on Windows Server 2008 R2 and nothing helped, not taskmanager or taskkill. But, windows powershell run as administrator worked with "kill -id pid"
I know it's late but taskkill /im devenv.exe /t /f should work. the /t kills child processes too.
In my case, after several days of fighting with this problem (it was happening to VirtualBox and µTorrent processes), I discovered it was caused by a network driver issue, provoked by Windows Update patch KB4338818 (Windows 7 x64). After uninstalling that patch everything went back to normal. I just thought it could be useful for others.
I could solve my issue rearding this problem by killing explorer.exe which in turn was addicted to the process I wanted to kill. I guess this may also happen if processes open interfaces via hook which may be locked.
Native tskill <pid> (or tskill.exe <pid> ) worked for me on Windows 10 where no other native answer did.
In my case, I had some chrome.exe processes for which task manager's 'End Task' was working, but neither taskkill /F /T /PID <pid> nor powershell's kill -id <pid> worked (even with both shells run as admin).
This is very strange as taskkill is purported to be a better-api-and-does-more version of tskill.
In my case to kill all instances of a certain task I used FOR /F "usebackq tokens=2 skip=2" %i IN (`TASKLIST /FI "IMAGENAME eq name_of_task.exe"`) DO tskill %i
I've seen this a few times and my only solution was a re-boot.
You could try using PowerShell:
Get-Process devenv | kill
But if the other methods failed, this probably will too. :-(
I am going to suggest something here because I recently faced the same issue and I tried every possible thing in the answers but nothing worked. I was getting errors like
ERROR: The process with PID 23908 could not be terminated.
Reason: There is no running instance of the task.
using command prompt. Power shell wasn't helpful either. it would simply execute the commands and no response with process still running.
Until I decided to delete the associated '.exe' file. Since the file was active, windows would not allow the deletion, but in that warning window it gave me the name of the process which was holding up the task I wanted to kill.
I was able to kill the original task and thus the buggy process.
It is definitely worth a try if none of the solutions works out.
I was getting the following results with taskkill
>taskkill /im "MyApp.exe" /t /f
ERROR: The process with PID 32040 (child process of PID 54176) could not be terminated.
Reason: There is no running instance of the task.
>taskkill /pid 54176 /t /f
ERROR: The process "54176" not found.
What worked for me was sysinternal's pskill
>pskill.exe -t 32040
PsKill v1.15 - Terminates processes on local or remote systems
Copyright (C) 1999-2012 Mark Russinovich
Sysinternals - www.sysinternals.com
Process 32040 killed.
You can get pskill from the sysinternal's live site
If taskkill /F /T /PID <pid> does not work.
Try opening your terminal elevated using Run as Administrator.
Search cmd in your windows menu, and right click Run as Administrator,
then run the command again. This worked for me.
Some of the Exe files Dependents on Some services,
So you need find the respective service and stop first.
The same problem happened to me in VirtualBox with respect to Java processes.
In my case, it was due to a bug in Windows Update patch KB4338818 (Windows 7 x64).
I solved it by doing the following:
Uninstall Windows Update patch KB4338818
Install Windows Update patch KB4338821
Running as an admin works for me:
1.search cmd in windows
2.right click on cmd select as "Run as administrator"
3.netstat -ano | findstr :8080
4.taskkill/pid (your number) /F
For me, the way it worked is I have to kill the parent process. Figure the parent process out and kill it
taskkill /IM "parent_process_name.exe" /T /F
In my case none of the solutions here worked. I eventually found that the program in question was frozen trying to poll USB audio interfaces. So I unplugged a USB DAC I had connected, and to my surprise the application quit instantly. Francis' answer mentions that it could be a result of "unprocessed I/O requests that hasn't been handled properly (by a device driver your program has possibly accessed)", which might explain why this fixed it.
I suppose it really depends on what the program was doing when it froze, but if none of the other solutions are working, try disconnecting all USB devices to see if one of them could be the cause.
taskkill /f /im "process.exe"
running cmd or .bat file as administrator worked for me
I have the Problem with debugged processes with gdb in Code::Blocks.
As soon it is hanging while accidentally stepping into instructions out of scope of your sources (as libs without sources or system functions) you cannot quit the debugging neither from Code::Blocks nor from Task-Manager.
I think it is an error in the implementation of gdb in Code::Blocks, but could also be in gdb ;)
My Solution:
taskkill /F /IM process.exe /T
This shows the PID of the parent process. Now kill the parent:
taskkill /PID yyyy
Both are gone.
Done.
NirSoft's NirCmd did the job for me:
nircmd killprocess "process name.exe"
killprocess man page is here.
I had the exact same issue, found this fix on another site:
powershell.exe "Get-Process processname| Stop-Process"
it worked for me and I was in the same boat where I had to restart, the /T would not work.
If you download the free sysinternals suite, it has a pskill.exe application which works well for these types of tasks: pskill.exe "process_name"
It works on these processes even without using its -t option.
I did the following, on an elevated powershell:
PS C:\Windows\system32> wmic.exe /interactive:off process where "name like `'java%'`" call terminate
command Output:
Executing (\\SRV\ROOT\CIMV2:Win32_Process.Handle="3064")->terminate()
Method execution successful.
Out Parameters:
instance of __PARAMETERS
{ReturnValue = 0; };
I got some syntax information on : https://community.spiceworks.com/topic/871561-wmic-error-like-invalid-alias-verb
As Francis mentioned some process can not be terminated because of
"unprocessed I/O requests"
In my experience i was dealing with buggy graphic driver that would cause my game to crash and not be able to close it, as last resort i disabled the graphic driver and the process finally went away.
If your application is waiting for a resource from driver like wifi or graphic try disabling them in device manager, you need to dig a little deep to see where they hanged.
This is of course not recommended but sometimes you have nothing to lose anymore.
I had the same problem and as many others here have said none of the normal Kill commands worked. My problem file was an executable that was being run from a network share by a user on a Remote Desktop Server. With multiple shared users not an easy thing to restart in during a work day. Even when the user logged off the exe was still listed in Task Manager. I sent to the server where the folder was shared and from Computer Management -> Sessions found the user with the session still open from that RDP server even though he was logged off. Right Click -> Close Session and the file lock was released.
Beats me why I couldn't end the taks. The error message I was originally getting when I try and delete the file was "The action can't be completed because the file is open in System"
Hope this helps someone else.
while taskkill didn't work
taskkill /f /t /pid 14492
ERROR: The process with PID 14492 (child process of PID 7992) could not be terminated.
Reason: There is no running instance of the task.
the simpler tskill has worked fine for me
tskill 14492
I faced the same issue where I started a node app in port 3000 and it didn't close correctly and the process kept running even after restart.
None of the taskkill or powershell commands running in Administrator mode worked for me.
I used MS Process Expoler > Properties > Image > Current directory (which was supposed to be the my project directory).
Finally, I had to reboot in SafeMode and rename the project folder and restart. The Node processes which were consuming port 3000 killed itself.
For killing PID Tasks running in windows:
TASKKILL /PID "Taskname" /F
using wmic:
show all running process where name of process is cmd.exe
wmic process where name="cmd.exe" GET ProcessId, CommandLine,CreationClassName
then terminate the specific instance of process by processId (PID)
WMIC PROCESS WHERE "ProcessID=13800" CALL TERMINATE
Run CMD as Admin will fix the problem
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Every time I turn on my company-owned development machine, I have to kill 10+ processes using the Task Manager or any other process management app just to get decent performance out of my IDE. Yes, these are processes from programs that my company installs on my machine for security and compliance. What I'd like to do is have a .bat file or script of some kind with which I can kill the processes in question.
Does anybody know how to do this?
You can do this with 'taskkill'.
With the /IM parameter, you can specify image names.
Example:
taskkill /im somecorporateprocess.exe
You can also do this to 'force' kill:
Example:
taskkill /f /im somecorporateprocess.exe
Just add one line per process you want to kill, save it as a .bat file, and add in your startup directory. Problem solved!
If this is a legacy system, PsKill will do the same.
taskkill /f /im "devenv.exe"
this will forcibly kill the pid with the exe name "devenv.exe"
equivalent to -9 on the nix'y kill command
As TASKKILL might be unavailable on some Home/basic editions of windows here some alternatives:
TSKILL processName
or
TSKILL PID
Have on mind that processName should not have the .exe suffix and is limited to 18 characters.
Another option is WMIC :
wmic Path win32_process Where "Caption Like 'MyProcess%.exe'" Call Terminate
wmic offer even more flexibility than taskkill with its SQL-like matchers .With wmic Path win32_process get you can see the available fileds you can filter (and % can be used as a wildcard).
I'm assuming as a developer, you have some degree of administrative control over your machine. If so, from the command line, run msconfig.exe. You can remove many processes from even starting, thereby eliminating the need to kill them with the above mentioned solutions.
Get Autoruns from Mark Russinovich, the Sysinternals guy that discovered the Sony Rootkit... Best software I've ever used for cleaning up things that get started automatically.
Download PSKill. Write a batch file that calls it for each process you want dead, passing in the name of the process for each.
Use Powershell! Built in cmdlets for managing processes. Examples here (hard way), here(built in) and here (more).
Please find the below logic where it works on the condition.
If we simply call taskkill /im applicationname.exe, it will kill only if this process is running. If this process is not running, it will throw an error.
So as to check before takskill is called, a check can be done to make sure execute taskkill will be executed only if the process is running, so that it won't throw error.
tasklist /fi "imagename eq applicationname.exe" |find ":" > nul
if errorlevel 1 taskkill /f /im "applicationname.exe"
Here I wrote an example command that you can paste in your cmd command line prompt and is written for chrome.exe.
FOR /F "tokens=2 delims= " %P IN ('tasklist /FO Table /M "chrome*" /NH') DO (TASKKILL /PID %P)
The for just takes all the PIDs listed on the below tasklist command and executes TASKKILL /PID on every PID
tasklist /FO Table /M "chrome*" /NH
If you use the for in a batch file just use %%P instead of %P