I have a bat file i called it test.bat and inside i added one line:
This is what i tried so far : The problem is that the file never created.
start /wait msinfo32.exe /s C:\TEMP\test.nfo
When im running the bat file i see the cmd window for second then i see the msinfo32.exe program . But the file test.nfo never created in C:\TEMP
How can i create the test.nfo automatic and how do i make that after the file is created so the msinfo32.exe program will be exit/closed ?
I Googled command line options and tested this:
start /wait msinfo32.exe /nfo c:\temp\test.nfo
See here: http://ss64.com/nt/msinfo32.html
Related
I'm new in using cmd and batch script. Here is what I was trying to do with a .bat file.
go to a folder
open that folder in file explorer
open that folder in vscode
start Firefox browser
Sequence doesn't matter here. Doing these tasks in any sequence is fine.
Here are the commands that I initially wrote
cd/
E:
cd folder1/folder2/folder3
code .
start .
start firefox
But with these commands the result I got is
Only vscode started with the folder I wanted to open with vscode
File explorer and Firefox was not starting
cmd.exe continued to run. But it seems like it only executed upto code . command
When I closed vscode, cmd.exe would be closed with it too
Then I changed the sequence of the commands as below
cd/
E:
cd folder1/folder2/folder3
start .
start firefox
code .
This time everything worked as expected. I've looked up documentation for start command but didn't find anything(or maybe I didn't understand) about start . command.
Can anyone explain me why the result changed when I changed the sequence of the commands?
As already mentioned in the comments, code is really a batch file, code.cmd.
If your VSCode installer added a location to your %PATH%, take a look there and you should see code.cmd in that \bin directory.
When you run a batch file from another, if you want control to pass back to the initial script upon completion, you need to run it using the call command.
#CD /D "E:\folder1\folder2\folder3" 2>NUL || Exit /B
#Call "%ProgramFiles%\Microsoft VS Code\bin\code.cmd" .
#Start "" "%SystemRoot%\explorer.exe" .
#Start "" "%ProgramFiles%\Mozilla Firefox\firefox.exe"
If you do not want robust code, and wish to assume file extensions and environment settings, the above could be simplified to this:
#CD /D E:\folder1\folder2\folder3
#Call code .
#Start explorer .
#Start firefox
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! =)
I have a program with a separate setup for 32 and 64 bits. My goal is to create a single executable that can run the appropriate setup. So I created a folder and placed the two setups inside, then wrote the following script:
#echo off
if %PROCESSOR_ARCHITECTURE%==AMD64 goto :x64
if %PROCESSOR_ARCHITEW6432%==AMD64 goto :x64
:x86
"%cd%"\setup.exe
exit
:x64
"%cd%"\setup-x64.exe
exit
Afterwards, I created the SFX file with this folder in WinRAR, pointing to the BAT file. But when I run it, a command line window pops up and shuts down instantly and nothing happens. I go to the temporary folder and double click the BAT file and the setup starts. The same happens in the original folder. What is happening and how can I fix it? Thanks!
%cd% reffers to the directory of the call of the batch-file.
For example a batch-file is in %USERPROFILE%\Desktop\Folder\bat.bat:
echo %cd%
pause
and you start it for example from the command-line like this:
C:\>%USERPROFILE%\Desktop\Folder\bat.bat
it should echo C:\ as that is where you called it from.
Two ways from the comments to solve the problem:
Push the directory of the batch-file using pushd "%~dp0" -> will result in a change of the variable value of %cd%
or
do not use "%cd%" but "%~dp0"
Both ways use the fact that the zeroth argument of a batch-file is its path.
You can prevent the command-line window from closing if you are debugging the file from the command-prompt itself if possible. With that you should have seen an error that state something like ...\setup.exe not found. After that nothing had to be done from the batch-file so it closed.
I created a test.bat program to copy a file from one directory to another. At first it ran well, but after I tested it few times it started to fail to copy! Is there something wrong with my .bat file?
The test.bat is in D:\ and the
command in test.bat:
copy book_store_log.ldf C:\test
It is encoding problem, I should change it to ANSI
i need to create a file as if i was the browser for a qa test. I figure if i copy and rename cmd.exe i can execute commands and the process will be the browser and complete my criteria for the test. i need to do this via a batch script. Below is my attempt at getting something to run as if it was from the browser.
my issue is the command is not creating the file in the directory like it should be. The dir command shows the directory as being empty even though as far as i can tell, everything worked correctly. There are no error logs or alerts. why can i not copy this file?
thanks!
copy C:\Windows\System32\cmd.exe %userprofile%\AppData\Roaming\firefox.exe
md %userprofile%\AppData\Local\test12
start %userprofile%\AppData\Roaming\firefox.exe \C copy C:\Windows\System32\cmd.exe %userprofile%\AppData\Local\test12\Test12.exe
dir %userprofile%\AppData\Local\test12\
If you try to use /K in stead of \C (the slash is wrong here) the cmd.exe (firefox.exe) will show you any errors that occured :
This works fine here:
start /WAIT %userprofile%\AppData\Roaming\firefox.exe /K copy C:\Windows\System32\cmd.exe %userprofile%\AppData\Local\test12\Test12.exe