Taskkill Internet Explorer child process - windows

I'm struggling to kill internet explorer child process (to close one IE tab) using .bat script or just from cmd line.
I've already tried:
taskkill /pid {pidid} /f /t
or
taskkill /pid {pidid} /t
and it is not working at all. I got the output that {pidid} was terminated but another pid is set up and the tab is not closed.

This is the IE crash detection kicking in, if you just kill one of the tab processes it will try to restore the tab because it thinks something on the page caused it to crash.
You need to switch to another language so you can do UI Automation or use the Shell.Windows scriptable object if you want to interact with Internet Explorer in a documented and clean fashion.

Related

In a batch process, is there a way to close only a document in Acrobat Reader DC?

In a batch process, on Windows 10, I'm using this command:
taskkill /IM AcroRd32.exe & exit /b 0
to close Acrobat Reader DC.
It works perfectly for my needs, but sometimes I want to close only one of the documents open in Acrobat Reader at the moment of the run, not all (as it happens now, obviously, closing Acrobat).
Is there a way to do it?

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

Is there a way to close a single window of a process from a BAT file?

Here's my situation:
I have my Windows 7 computer set up so that every morning, a task runs that plays my alarm and causes my morning routine to open up (in a WordPad window). The thing is, I would like to also have the window automatically close at the time when I leave for work so I don't have it cluttering up my desktop after work. After all, if the window is always open, that kind of ruins its purpose as a reminder.
Ideally, I would like a way to close only the WordPad window containing that any other WordPad windows I have open are not affected. Simply killing the task would close all WordPad windows (probably regardless of whether they have unsaved data or not).
So is there a way to close a specific window (not the whole process) from a Windows batch file? Or from anything else I can run from Task Scheduler, I suppose.
Sure. Use tasklist to find the window based on its title, then taskkill to kill it by PID.
#echo off
setlocal
for /f "skip=3 tokens=2" %%I in (
'tasklist /fi "windowtitle eq Reminders.rtf - WordPad"'
) do taskkill /im "%%I"
Or just
taskkill /fi "windowtitle eq Reminders.rtf - WordPad"

How to close Windows Explorer from CMD

Is it possible to close Windows Explorer from CMD? I have a batch that does this: it will change directory, open explorer in this folder, than run a program. After the user closes the program the batch should close the explorer (or all explorers opened), continue on next folder (cd folder), run the same program in this folder and so on. Till the last folder is processed.
Close the explorer windows by killing the explorer process (note that this may do more than just kill the windows, but it will definitely do that):
for example, use win+r and try this
cmd /c "taskkill /f /im explorer.exe && start explorer"
If you kill explorer without restarting it, use Ctrl+shift+Esc to pull up the taskmanager and start a new task "explorer".
Not from a batch file unless you want to write your own command line application that opens up a windows explorer window, and (this is the key part) somehow knows the window handle of that explorer window, so it can post a WM_CLOSE message to it, which basically simulates someone closing that window.
How you would determine "all the explorer windows that got opened" would be that instead of just starting explorer.exe instances from a command line you would do it from your own application.
I think that determining the window handle (HWND in win32 api terms) and posting a close message would be better than trying to track process handles and terminating explorer process instances, since that could cause some side effects beyond those that you'd want.

Resources