cmd Taskkill command not working for certain procces - windows

While I was just messing around with cmd I noticed something strange. When i type:
C:\Users\szymo>tasklist
In the end of results, as a process tasklist gets displayed
So thought: If it's getting displayed as a process, what will happen if I try to taskkill it. And it appears that if I do like this, i get a communicate that:
I tried to do this using PID, but also didn't work.
:
Can someone explain why this happens??.
Thank you in advance

Tasklist WAS the process you ran to display the tasks.
It is ended before you can kill it. So it is no longer there.
You can validate it if you run tasklist twice. Then you will have different PID so it is a new process

Related

Stop running VBScript

I have a simple VBScript, which executes a batch file in the background. It starts correctly and it's working, but I can't stop it.
I already checked all of these answers, but I have no cscript.exe and no wscript.exe running
Any ideas?
You could try adding an "exit" statement at the end of your batch as long as you don't need to visually see the results (you could just write them to a text file). Just saying, in case you're experiencing this problem in the future.

Run Explorer as the Admin Account In the Standard User's Environment

This is more of a pet project, as I like to try my best to batch script whatever I feel like without using a 3rd party app. I understand it would be easier that way, but I want to just try this for the heck of it. I understand the basic issue might just be the way the shell executes explorer, as I know it was NOT intended to run like this.
I have a standard user account and a batch script:
#echo OFF
FOR /F "usebackq" %%i IN (`hostname`) DO SET COMPNAME=%%i
ECHO Computer %COMPNAME%
TASKKILL /F /IM explorer.exe
runas /user:"%COMPNAME%"\ADMIN "C:\Windows\System32\cmd.exe"
Echo.
Echo Press Enter once you are finished
Pause
TASKKILL /F /IM explorer.exe
explorer.exe
Exit
Basically each computer's name is the hostname of the computer, so I created a variable to process that. Then I have it kill explorer, then run CMD as the admin account. (I can replace this with Explorer as well.) Then when CMD opens I type explorer.exe and it opens the admin account with full access. The script runs fine, no issues at all with the script. But in regards to the environment, there are 2 issues I am running into.
Windows 7 everything works fine, every program I open is ADMIN, even the start menu user profile title at the top right of the start menu says ADMIN, until I open Administrative tools, then every application I open from there uses the standard user, such as computer management. I assume explorer processes the command off of the local user environment which is why. I know I can just use compmgmt as an admin to solve that, but I want to know the specific reason why Explorer is swapping, is it as simple as the shell uses the local environment and that is just how it is?
On Windows 10, the script process successfully, but Explorer runs extremely slow. Every other program runs fine, cmd, compmgmt, regedit, Firefox, etc... But Explorer is slow, I'm talking 5 minutes to open the favorites window, and the start menu will not open at all. I checked process explorer and nothing takes it up, except the standard get resolution and other graphic handles. I assume it might be just the way this Shell operates.
Anyway, I understand this is not ideal, and that there are far easier ways to do it, and that Explorer.exe was never intended to be run like this. I just wanted to try for my own personal creativity. Any help would be greatly appreciated.
Thanks,

Batch force windows calculator to close in Windows 10

I have three monitors, and I like to play SMITE in triple surround. To do this the NVIDIA Control Panel wants me to close a few (to me random) applications before it can do its magic. This is all good and well, but the calculator application is a pain to close. I have to use the task manager to force the process to stop, because for some reason it doesn't always by itself.
I want to use a batch script for this, so it will close automatically with only a single double click (along with some other applications that sometimes do and sometimes don't need to be closed)
But since the calculator isn't just a simple .exe, I can't figure out how to shut it down. What I've found for a regular process is taskkill /f /im processname.exe but, the calculator doesn't have a simple .exe I can kill. The default Windows 10 apps have odd names, and are technically file folders according to their properties.
Can somebody help me with how to kill the Windows apps processes via batch (or something else if that's better)?
Windows Calculator's executable is located (for me) at
C:\Program Files\WindowsApps\Microsoft.WindowsCalculator_10.1611.3123.0_x86__8wekyb3d8bbwe
\calculator.exe
that program is launched by calc.exe. You can terminate Windows Calculator with:
taskkill /f /im calculator.exe
Instead use Stop-Process -Name calculator

how do i get console to notify me when it is finished running a script

I am using nant, but this can apply to any thing, I just want to know if there is a way to set windows cmd or console2 or some kind of shell to give me a popup or make a noise when it is "finished" (i.e. when it is waiting and the screen says >C:\User\Random_FILE_PATH>_)
I'm using windows 7.
Valentine
sorry, to clarify, I am not running a script that I created, this is just when running anything in the console. I would like it to be that anytime my console is waiting for me it creates a pop up or a noise. This would ideally be some kind of setting
You may open a message box in the end of your batch file, using WSH with a simple VBScript or JScript. See Show a popup/message box from a Windows batch file for an example.
c:\> my_command & mshta.exe vbscript:Execute("msgbox ""finished"",0,""finished"":close")
this here uses conditional execution - when my_command is finished the mshta.exe will be executed with arguments in the brackets.As the parameter passing here is not so easy the string given to msgbox will not be displayed.
you can add a beep to your prompt:
set prompt=%prompt%^G
Don't type ^G. To get it, keep your alt-key pressed while entering 0 0 7 on your numeric keyboard.

How to bring an Orphaned Background Process back to Foreground?

Well it goes like this, I had to run a program from my home by sshing into the server in my institution. I did not want my program to be terminated when the session closes(I didn't know about screen).
What i did was press Ctrl+Z and then type bg so that it executes in the background.
The session got terminated. Now when I login from my institution machine and type ps -u username, it shows that the program is still running but I'm unable to bring it to foreground.
I tried fg and jobs but these commands don't give me any output.
Please someone help me..
If you have started the process without using "screen" command then you cannot take over that process. Basically you cannot take over a process that was started in a different shell.
When your session is terminated all the bg process will go the detached state. Though you might be able to see the details of such process you cannot fg them to a shell from login afterwards
If a process has been orphaned, you can't "reparent" it to a different shell and use fg, bg, ^Z, ^C, and so forth to control it.
It seems you're asking implicitly how to control an orphaned process. Since you can see the process using the ps command, you have its pid. You can use this pid as the argument to the kill command, which will allow you to stop, continue, or terminate the process. You can't wait for the process to finish, but you can poll to see whether it still exists by using the kill -0 <pid> command.
https://serverfault.com/questions/55880/moving-an-already-running-process-to-screen
Gives an alternative view on this question, The top answer suggests using Reptyr.

Resources