how to close a particular window using BATCH or CMD? - batch-file

How do I close a particular window using a batch script?
Example: I have many existing windows open, and I open "My Computer" in Windows 7. How can I close this using a batch script?
also try to answer How to copy an .exe or any type of file which is hiiden using BATCH FILE? too!!

Maybe using SendKeys. Save the following as Closer.vbs:
set shell = createobject("wscript.shell")
rcSuccess = shell.AppActivate("title of window to activate")
if rcSuccess = 1 then shell.sendkeys "%{F4}"
Then make a batch file called CloseApp.BAT containing
REM Close some App
cscript /nologo closer.vbs
And run using:
CloseApp

Related

Execute a copy command using a batch file by opening CMD

I'm creating a batch file on my desktop which has a simple code:
%SystemRoot%\system32\cmd.exe
This will open up Command Prompt.
Then I need to copy paste following code into the command prompt.
for /r "Z:\QCQA\Main QCQA Files\QA System Files\Nonconformance\Non-Conformance Reports\" %i in (NCR*.pdf) do copy "%~fi" "Z:\QCQA\Main QCQA Files\QA System Files\Nonconformance\NCR Log Tracking\PDF Destination from DOS\" /Y
The above command simply copies and pastes PDFs from one directory to another directory.
Is there a way to write the entire thing into a batch file?
Desired output is:
A Desktop Icon of a BAT File.
Double clicking on it will do two things: Open up Command Prompt and Executes the Copy command.
Closes the Command Prompt once done
Once that's done, I can simply use Windows Task Scheduler to run this Bat file everyday at 5:00 AM.
All the helps are appreciated. Thank You.
Create a batch file on the desktop and use the following code...
#echo off
for /r "Z:\QCQA\Main QCQA Files\QA System Files\Nonconformance\Non-Conformance Reports\" %%i in (NCR*.pdf) do (
copy "%%i" "Z:\QCQA\Main QCQA Files\QA System Files\Nonconformance\NCR Log Tracking\PDF Destination from DOS\" /Y
)
Double Click on the batch file anytime you want to run it.
That's it! =)

how to open a new cmd window using dosbox?

Is there any way I can open a new cmd window from dosbox?
Cannot use start directly/indirectly.
Mounting c: drive and directly typing the path doesn't work too..
Neither run nor execute commands work.
There is no limitation is that cmd should be opened in new window, etc. Actually i am doing this to enter 2-3 string inputs. (where choice command is not applicable)
Thanks in advance.
Although DOS is a monotask system, multiple instances of DOSbox can coexist on the hosting OS, and they can communicate by shared files with one another.
I tried the following batch STARTDOS.CMD on my Windows10 system (it can run either in CMD window or as a service):
#ECHO OFF
TITLE %0
ECHO >C:\STARTDOS.REQ
:LOOP
SLEEP 3
IF NOT EXIST C:\STARTDOS.REQ GOTO :LOOP
DEL C:\STARTDOS.REQ
ECHO Starting another DOSbox ...
START D:\APL\EMU\DOSBox\DOSBox.exe -userconf -noconsole
GOTO :LOOP
This batch checks the existence of semaphore file C:\STARTDOS.REQ to start another DOSbox instance in a new cmd window.
In DOSbox configuration file I have mount c C:\
Now if I execute ECHO >C:\STARTDOS.REQ withing one DOSbox window, this will launch another DOSbox in its own cmd window.

How do i keep the window size on my batch file after opening it in minimized mode?

I have a VBscript that runs a bunch of programs, one of them being a batch file. In the batch file i use:
Mode 50,8
This makes the window the right size and makes it look nice. However, in the cases where i open the batch file using the VBscript i want it to be minimized, that is done like this:
objShell.Run("path_of_my_batch_file"),7
The problem is that this makes the batch file completely ignore the instructions to stay at "Mode 50,8" and open the batch file in the default CMD size.
So my question is: How can i open my batch file in minimized mode using my VBS-file, but also let it keep the size?
Putting this at the top of the batch file workes:
Pause
Mode 50,8
But that means i have to press a key before it gets the right size and i defenetly dont want that. I need a way to either run the "Mode 50,8" command as soon as the batch file is no longer minimized or a way to let it keep the size after the VBS-file minimizes it.
The problem is that the mode 50,8 command desn't seem to have an effect while in minimized state.
There are
workarounds
with .appac tivate and then using sendkeys but
I'd prefer the 3rd party app NirCMD which enables the batch to minize/restore
itself.
' Q:\Test\2018\07\23\SO_51469493.vbs
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run("Q:\Test\2018\07\23\SO_51469493.cmd")
:: Q:\Test\2018\07\23\SO_51469493.cmd
#Echo off
Title Min5x80
Mode 80,5
Echo now minimizing using:
Echo nircmd win min title Min5x80
Timeout /t 5 & nircmd win min title Min5x80
Timeout /t 5 & nircmd win normal title Min5x80
cls
Echo back again
Pause
This will involve a flicker when running the batch.

Running a batch (.bat) file from a VB macro (.vbs)

I am having issues getting a simple batch file (opening command prompt) to run from a vbs macro, I know this question gets asked a lot and I have tried many different suggested solutions for this without success. I am using notepad ++ to run the scripts/VB code for testing.
I have verified that the .bat file will execute correctly by itself, any suggestion on how to get this to work correctly would be greatly appreciated.
Here is my code for each instance.
VB CODE:
Sub CallBATCH()
Dim argh As Double
argh = Shell.Run "C:\Temp\cmdPrompt.bat"
End Sub
BATCH FILE:
start cmd.exe /k
EDIT: The following is the .bat file that I actually intend on calling up:
#echo OFF
title AutoCAD DWG Duplicator
color 0a
:start
set /P TemplateName=Please enter the template name you wish to copy:
set /P NumberOfCopies=Please enter how many copies you wish to make:
set Pathname="<filepath>"
cd /d %Pathname%
:init
for /L %%f in (1,1,%NumberOfCopies%) do copy %TemplateName%.dwg C:\Temp\%%f%TemplateName%.dwg
You seem to be calling a .BAT file that in turn opens a command prompt with START. I'm unclear on why you need the .BAT at all.
Dim oShell
Set oShell = WScript.CreateObject ("WScript.Shell")
oShell.run "cmd.exe /K"
Set oShell = Nothing
The /K parameter will open the command prompt window and keep it open. You've supplied no parameters for START and no commands to execute when the command prompt opens so this should do what you are looking for. More at: Run Method (Windows Script Host)

How to close cmd window when using a batch file?

New to batch files, first try actually. Trying to make a simple batch file that will open a new instance of notpad++. The batch file works and a new notpad++ window is opened, but the cmd window also stays open as well. How do I close the cmd window within the batch file after the new instance of notepad has been lauched?
#ECHO OFF
CALL cd C:\Program Files (x86)\Notepad++\
CALL notepad++.exe -multiInst
You can use start:
start notepad++
And there should be no need to use an explicit exit from the batch (which is done either via goto :eof or exit /b) as the start call returns immediately.
You can exit from command line only after quiting from notepad++.
1. If you wanna exit from cmd after quiting from notepad++, add EXIT to the end of your batch file.
2. Why don't you use shortcut instead of batch file to start notepad++?

Resources