Running executables using Windows batch files - windows

I have an application in which I would like to run many executables using a batch file (in my case a program called AMDIS, http://chemdata.nist.gov/mass-spc/amdis/downloads/).
On the Windows command prompt it works if I type
C:\NIST08\AMDIS32\AMDIS_32.EXE C:\Users\Ento\Documents\GCMS\test_cataglyphis_iberica\queens\CI23_Q_120828_01.CD‌​F /S /E
where AMDIS_32 is the program I want to run and C:\Users\Ento\Documents\GCMS\test_cataglyphis_iberica\queens\CI23_Q_120828_01.CD‌​F the file I want it to analyze and /S /E some opions.
Now I would like to make these calls repeatedly using a batch file in Windows 7.
I tried making a batch file with
START C:\NIST08\AMDIS32\AMDIS_32.EXE C:\Users\Ento\Documents\GCMS\test_cataglyphis_iberica\queens\CI23_Q_120828_01.CD‌​‌​F /S /E
but this doesn't seem to work. Does anyone know how I should do this?
cheers,
Tom
EDIT: based on the info in forum http://social.msdn.microsoft.com/Forums/en-US/sqlexpress/thread/fdb993d9-6a9c-4459-aedb-0283f2d6935d I found that my mistake had to do with saving my batch file in UNICODE rather than ANSI encoding - now it works - thanks to you all!!

:X
C:\NIST08\AMDIS32\AMDIS_32.EXE C:\Users\Ento\Documents\GCMS\test_cataglyphis_iberica\queens\CI23_Q_120828_01.CD‌​F /S /E
goto X

#Echo OFF
Set /A "Interval=3"
PUSHD "C:\NIST08\AMDIS32"
:Loop
Start /B AMDIS_32.EXE "C:\Users\Ento\Documents\GCMS\test_cataglyphis_iberica\queens\CI23_Q_120828_01.CD‌​F" /S /E
Ping -n %INTERVAL% Localhost >NUL
Goto :Loop

Related

How place file with bat command when ran from currenty directory

So I am trying to create a bat/exe installer for regjump. I am using a bat compiler so I can attach the "regjump.exe" to the installer.exe; so when the installer is ran, it will put regjump in the current directory of the installer.exe. I know I can use xcopy to place the file but I need help with the first half of the command. What is "local directory\regjump.exe" syntax?
cd C:\
xcopy "WHEREVER THE INSTALLER IS RAN FROM\regjump.exe" "C:\Windows\System32" /q /y /r
I want the syntax to be able to be ran from anywhere i.e. removable F:
Try this. You will need to execute as admin to write to "C:\Windows\System32", so this checks for that.
openfiles >nul 2>&1 || echo(You must execute this command as Administrator. & pause & goto :eof
set "SourceDir=%CD%
cd C:\
xcopy "%SourceDir%\regjump.exe" "C:\Windows\System32" /q /y /r

How to find an MSI file and launch installation from command line?

Goal: I want to use CMD.EXE to find a single MSI, located in C:\ProgramData - not elsewhere - and then execute it.
My attempt: dir /s /b C:\programdata\*"my program"*.msi | explorer
Problem: Explorer opens but doesn't launch my MSI.
Constraints: I can't write a .BAT. So this must run on the command line.
Although that doesn't surprise me, I apparently don't understand CMD.EXE and piping well enough to do this. Any guidance?
A *.msi file is not an executable. It is a compiled installer script file which needs an interpreter for execution. The interpreter is msiexec.exe.
Searching for a file can be done with command DIR or with command FOR.
The better solution using command FOR:
for /R C:\ProgramData %# in ("my program*.msi") do %SystemRoot%\System32\msiexec.exe /i "%#"
The more complicated solution using the commands DIR and FOR:
for /F "delims=" %# in ('dir /A-D /B /S "C:\ProgramData\my program*.msi" 2^>nul') do %SystemRoot%\System32\msiexec.exe /i "%#"
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
dir /?
for /?
msiexec /?
Note: %%# instead of %# would be needed if one of the two command lines is used within a batch file.

Windows Batch File for loop on user dir

I need to create a batchfile to delete a specific file in the users appdata dir. The batchfile is executed as localsystem.
I did test the following senarios:
Command Prompt as localsystem - this works
Command Prompt as admin - this works
Command Prompt as user - this works for all folders where the user has permissions
As soon as i put the for loop in a batch file, it dosent work anymore.
It also dosent matter in which context (User,admin,localsystem) i start it.
for /D %i in ("C:\Users\*") do del /Q /F "%i\AppData\LocalLow\Sun\Java\Deployment\deployment.properties"
The exit code shows 255, which means to long error.
The error i get is the following:
C:\Windows\Scripts>sync_exeptionsiteslistandconfig_java.bat > output.txt
\Users\*") do del "i\AppData\LocalLow\Sun\Java\Deployment\deployment.properties" /Q /F was unexpected at this time.
Any help why the single line is working and a batchfile with this single line is not working is welcome.
Please also explain why it is not working. (I always run tasks as localsystem)
This may do what you want, but it only processes normal folders, not hidden etc.
Your problem may have been using %i within a batch script.
#echo off
for /D %%i in ("C:\Users\*") do del /Q /F "%%i\AppData\LocalLow\Sun\Java\Deployment\deployment.properties" 2>nul

Running Multiple Installations with System-Reboot Inbetween them

Currently I have a set of software-Installations(and their paths) that i have to install on my Windows Machine.
What I do now is -- Hit RUN every time and type in the software installation path into it..
What I want is to design a Batch file which would install all the applications and REBOOT my system after every successful installation and then continue with the NEXT item in the list..
Is it possible using a .bat file ??
This really isn't something batch was designed for, so this will be a bit hacky. It's not elegant by any means but give it a shot, it might work for you.
for /f %%a in (C:\files.txt) do (
start /wait %%a
exit /b
)
for /f "skip=1" %%b in ("C:\files.txt) do (
echo %%b >>C:\newfiles.txt
)
xcopy C:\newfiles.txt C:\files.txt /y
del C:\newfiles.txt /f /q
shutdown /r /t 0 /f
The idea being that you have a text file with the paths of the executables that you want to install. It will go through and execute the first file in the list, wait for it to complete, then re-write the list without the file it just installed.
This is dependend on the setup file having no user interaction and exiting by itself, or maybe it's just to make things easier - in which case just go through each install yourself, and when it finishes the batch file will do the rest.
On the note of rebooting and continuing you will either need to run the batch file again yourself or put it in the registry to start up itself, the latter command being
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v "MyBatchInstaller" /d "C:\MyBatchFile.bat" /f
Hope this helps

Xcopy complete operation successfully, but the copy does not occur

i'm having a weird problem about copying with Xcopy.
I'm using Windows Server 2008 R2. There is a Batch file (.CMD) - in fact, 2 Batches - which executes many operations. Among them there are 2 Xcopy.
The first Xcopy completes the copy successfully. Then some operations of batch are executed and...the second Xcopy is executed after some time. It shows a successfully status, like "300 files copied" but...the files are not copied !
THE strange behaviour: i put a pause command into the Batch and, after this second weird Xcopy, i run THE SAME command at the Prompt and..it works !!!
I cannot explain this, so i'm asking for help here. The full command is:
xcopy /s /e /h /r /i /y E: D:
As a matter of curiosity/information, the other Xcopy (which worked!) is:
xcopy /s /e /h /r /i /y E: D:
Or....the same command !!! Each one runs in a separated Batch file - the first Batch "calls" the second one.
E: is CD-ROM, so after the first Xcopy, the first Batch asks for another Disc and calls the second Batch, which (supposed) copies entire CD content to D: (HDD).
I'm sorry if the question is silly and i'm not realizing how simple is to correct the erratic behaviour of Xcopy. Thanks in advance...
Thanks very much Bali C !
But i found the problem: the correct syntax is
xcopy /s /e /h /r /i /y E:\ D:\
You can see that the backslashes made all the difference ! The files were being copied to another directory, in fact, the current working directory. With backslashes the copy is fine.
But i appreciate your suggestion...
To copy the entire contents try using
xcopy /e /h /r /i /y /t E:\*.* D:\
I left out the /s as it contradicts the /e switch, I doubt it will be the source of the problem but it's worth a shot. I used the \t switch to copy the directory structure of the source.
I have also used wildcards *.* to copy the contents, rather than just the drive letter, some things work at cmd prompt but not in batch, but try using this.
Another option would be to use robocopy.

Resources