Make this batch file that uses NirCMD close also folder properties windows - windows

the batch file code is below It closes all open explorer windows without Stopping copy or move operations and I like that But I would also like if it would close windows explorer properties windows like the below one if those are open too thanks for in advance for any help on this
#echo
cls
nircmd.exe win close class "CabinetWClass"
" I looked on nircmd documentation but couldn't find anything"

Related

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

Open folder on portable device with batch file

General goal: create a desktop shortcut to a folder buried the file structure of my phone's SD card (connected via USB). Note, this is on a work computer, so I can't do anything to crazy.
I tried using normal shortcuts to no avail, so I decided to try using a batch if I can't use a shortcut. If using a shortcut is possible or there is a better option than a batch let me know.
Specific question: How can I open a folder using a batch file? I can manually open explorer, paste the address into the bar and go there, so there should be a way to mimic this, but so far my attempts have been unsuccessful.
Attempts:
%SystemRoot%\explorer.exe "Computer\My S4\Phone\Android\data\com.dropbox.android\files\scratch\"
explorer Computer/My S4/Phone/Android/data/com.dropbox.android/files/scratch
start "" "Computer\My S4\Phone\Android\data\com.dropbox.android\files\scratch\"
start Computer\My S4\Phone\Android\data\com.dropbox.android\files\scratch
This is an addition to Andry's answer:
It can be very complicated to get the whole path to an MTP folder like
::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_03de&pid_21e7&mi_00#6&a5ebb37&1&0000#{6ac27878-a6fc-2155-ea85-f98f491d4f33}\{E4FC4EA5-FFFF-FFFF-0000-000000000000}
To get the path do the following:
In Windows Explorer select the folder on the MTP device you want to get the path of.
Open it's context menu and select Copy
Open in Explorer a folder on your PC, open the context menu on a free area and select Paste Shortcut
Now we need a too that can read .lnk files. I have used the tool LECmd. Execute LECmd.exe -f <path to the .lnk file created in step 3>.
You will get a lot of content printed to the console. The interesting part is the Parsing Path next to the end.
In my case it was ::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_03de&pid_21e7&mi_00#6&a5ebb37&1&0000#{6ac27878-a6fc-2155-ea85-f98f491d4f33}\SID-{10001,,21003612160}\{E4FC4EA5-FFFF-FFFF-0000-000000000000}
Now we are close, unfortunately the path shown above can not be used because it contains an invalid part: \SID-{10001,,21003612160}. Remove that part and you can open the explorer in that MTP folder using
start "" "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_03de&pid_21e7&mi_00#6&a5ebb37&1&0000#{6ac27878-a6fc-2155-ea85-f98f491d4f33}\{E4FC4EA5-FFFF-FFFF-0000-000000000000}"
There is a way to open an MTP device folder directly in the Windows Explorer window on Windows 7 x64.
Here is steps:
Open Windows Explorer with the My Computer folder, for example:
start "" "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
start "" "shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
explorer "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
explorer "shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}"
The complete list of GUIDs you can find on the internet, for example: https://www.tenforums.com/tutorials/3123-clsid-key-guid-shortcuts-list-windows-10-a.html
Attach the MTP device and enable File Transfer mode in the device. It must be shown in the My Computer window as a portable device entry.
Drag and Drop the MTP device entry icon to the Desktop.
Open any notepad, for the instance, Windows notepad: Win+R -> notepad
Drag and drop the desktop icon into notepad window.
At the end of the notepad text would be something like:
::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_0e8d&pid_201d&mi_00#7&1084e14&0&0000#{6ac27878-a6fa-4155-ba85-f98f491d4f33} (spaces removed).
You can cleanup the spaces between characters by copy the string into another instance of the notepad and replace them through the Ctrl+H to nothing.
Now you can open the MTP device folder directly:
start "" "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_0e8d&pid_201d&mi_00#7&1084e14&0&0000#{6ac27878-a6fa-4155-ba85-f98f491d4f33}\<your-local-path-to-folder>"
There is a wait timeout, so the Windows Explorer window might not open immediately.
To generate a shortcut to target folder you can use make_shortcut.vbs script from here: https://github.com/andry81/contools/tree/HEAD/Scripts/Tools/ToolAdaptors/vbs/
For example:
>
make_shortcut.vbs myphonecamera.lnk "shell:::{20D04FE0-3AEA-1069-A2D8-08002B30309D}\\\?\usb#vid_0e8d&pid_201d&mi_00#7&1084e14&0&0000#{6ac27878-a6fa-4155-ba85-f98f491d4f33}\SD-card Samsung\DCIM\Camera
Now you can click myphonecamera.lnk to open the folder or use the Windows Explorer:
>
explorer myphonecamera.lnk
Instead of using Computer which is not a device name, try to use \\?\ or \\.\ which both refer to the local computer.

Explorer not starting after logon script ran

I set a batch script to run at logon using GPO that runs an exe. The exe runs, but Explorer doesn't start until after I stop the exe
For example, say this is my batch file:
notepad.exe
This will open notepad on a black background; no task bar, no desktop. When I close notepad, the task bar and desktop icons come up. If I change the batch file to this:
notepad.exe
explorer
at logon, notepad opens up and the task bar and desktop icons appear.
I've checked GPO settings to make sure logon scripts are being run asynchronously so I'm not sure what's going on. Can anyone help me with this?
For clarification, I'm not trying to run notepad at startup, I'm trying to run a synchronization program that doesn't have a UI so when I start it using the batch script, I just get a black screen because I guess the logon process is waiting for the exe to 'finish' or close to start explorer.
Try
start "" notepad.exe
You can place a window-title between the " if you like.

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