Running Multiple Installations with System-Reboot Inbetween them - windows

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

Related

Start a command and if it doesn't work start another

I want to start acrobat from my software.
At this moment I'm using the following command:
cmd /c start AcroRd32.exe /t filename
But now acrobat sometimes updates to 64 bit version and then AcroRd32.exe doesn't exists anymore.
So we have to start acrobat.exe instead:
cmd /c start acrobat.exe /t filename
But we are working with a lot of clients with different computers and maybe different versions of acrobat. That is also why we don't specify an install path.
So is there a way to say in one command line entry (not a script) to start AcroRd32.exe and if this doesn't work start immediately acrobat.exe instead?
So something like:
cmd /c start AcroRd32.exe /t filename | if not 1 is ok then cmd /c start acrobat.exe /t filename
#ECHO OFF
SETLOCAL
FOR /f "delims=" %%b IN ('where autoruns64.exe autorunsc64.exe 2^>nul') DO CMD /c START "" "%%b" &GOTO done
ECHO NOT found!
:done
GOTO :eof
Note: START command : extra pair of quotes. This sets the title of the STARTed session, otherwise the first "quoted string" is used.
"%%b" is used in case the path to the executable (I used autoruns) contains a space.
The first argument to where is the preferred target.
where examines the path for filenames matching its arguments and lists them. The for /f reads the list and on the first match found, executes the START. If no match is found,an error message is produced by WHERE, which is suppressed by the 2^>nul.
Edit: one-line version
FOR /f "delims=" %b IN ('where autoruns64.exe autorunsc64.exe 2^>nul') DO CMD /c START "" "%b" &exit
Posted as a batch file because it's easier to re-run during testing.
WHERE locates files on the PATH and lists them
START locates files on the PATH and executes the first one found.
The PATH is the list of directories that will be examined by START, in the order in which they will be searched for the required executable, so WHERE examines that list of directories for the target executable, it does not search all of the drives in the hope of finding it.
Traditionally even on 64bit it was still Acrord32 for the free reader to avoid such dual name problems / complication and the 32bit or 64bit full product was start Acrobat.exe
However Adobe did not help by using version specifics within the registry so a query there would generally produce differing results ! Microsoft start adding enhancements as to where or how simple launchers may be deployed so the location now gets cloudier (pun :-)
However the traditional ask the registry works best except for my portable
version (where /r h:\ acrord32.exe is very slow on a TB drive and it was not on that one anyway, it was on a network drive!).
Simplest way I can think of via cmd to find an installed copy is:-
cmd /v:on /c "where acro*.exe>temp.txt&&set /p acroexe=<temp.txt&&if exist !acroexe! (!acroexe! /t %filename%)"
there is little use of errorlevel since the fail will simply report
> INFO: Could not find files for the given pattern(s).
Priority will be the first match within %path%
You also need to consider where temp.txt will be written perhaps "%tmp%\delme.txt"
Potential "Gotcha" is if first match finds something like AcrobatUpdater.exe
To avoid random acro's best use
cmd /v:on /c "where /f acrord32.exe acrobat.exe>temp.txt&&set /p acroexe=<temp.txt&&if exist !acroexe! (!acroexe! /t %filename%)"
actually since all you desire is start one or the other then
start "Reader" acrord32.exe /t "filename.pdf" "printer name"||start "Editor" acrobat.exe /t "filename.pdf" "printer name"
The downside to this last method is Windows will raise a GUI error if acrord32 cannot "start" Thus gui warning needs to be dismissed before the second option can be run and start. In that case START cannot be told to be silent on error.
Finally make your choice from above or use a hybrid approach
where /f acrord32.exe... || start acrobat.exe.. will not warn user on first fail but only on second if both missing.

How to write a batch file to delete multiple specific files from different paths?

Each time before I start debugging, I need to delete some specific files from different paths. It's a tiresome process as I do it like a million times in a day. So I want to write a batch file that deletes all those at once without prompting.
The first path is
C:\Users\irem\AppData\Roaming\JDeveloper\systemx\DD\servers\DefaultServer\tmp\
I want everything under this temp folder gone. Without the temp folder itself, of course.
The second path is
C:\Users\irem\AppData\Roaming\JDeveloper\systemx\o.j2ee\drs\
I again want everything under this drs folder gone. Again without the drs folder itself, of course.
The third path is
C:\Users\irem\AppData\Roaming\JDeveloper\systemx\
This time I want to delete only the files with .lok extension under the systemx folder.
I tried to write something like this:
del "C:\Users\irem\AppData\Roaming\JDeveloper\systemx\DD\servers\DefaultServer\tmp\*.*?" /s
& del "C:\Users\irem\AppData\Roaming\JDeveloper\systemx\o.j2ee\drs\*.*?" /s
& del "C:\Users\irem\AppData\Roaming\JDeveloper\systemx\*.lok"
However it doesn't meet my expectations, it doesn't work.
I appreciate all the help. Thank you very much.
Perhaps something like this would do what you want:
#Echo Off
Set "srcPath=%AppData%\JDeveloper\systemx"
Set "tmpPath=DD\servers\DefaultServer\tmp"
Set "drsPath=o.j2ee\drs"
CD /D "%srcPath%" 2>Nul || Exit /B
Del /F /Q /A *.lok
For /D %%A In ("%tmpPath%\*" "%drsPath%\*") Do (RD /S /Q "%%A"
Del /F /Q /A "%%A\*.*")
I have used the paths you provided in your question, if those have changed, you can alter them by editing lines 2, 3 and 4 as necessary.

How to run all exe file from one folder/subdolders one by one

I am currently using the following command from this thread:
for /r "\VC++ Redist" %%a in (*.exe) do start "" "%%~fa"
and tried this command from this thread
for %%f in (*.exe) do start /wait %%f
but whenever I use the command, the error pops up.
Windows cannot find specified folder. Make sure you typed the name
correctly, and then try again.
EDIT:
I just solved my question using this command:
for /r "\VC++ Redist" %%a in (*.exe) do %%~fa
Just to add an answer so people knows the question is solved.
for /r "\VC++ Redist" %%a in (*.exe) do %%~fa
This works, but I'd prefer using start. Using start gives you the following abilities:
Window title
Window size
Process priority
Process affinity
WAIT function
NODE control
Another thing is quote - I'm not sure if your VC++ Redist's exe files come with space or not, so as a precaution, I would do:
"%%~fa"
This ensures safety to files with space(this is not the safest method, yet.)

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

Execute Batch File With Different Process Name

I have 6 different batch scripts that I am running together at the same time. The problem is, it is difficult to differentiate between them in the Windows Task Manager because the process is always just cmd.exe I was wondering if there was a way to change the process name for a batch script to something else so that each script would be more identifiable.
I have done a lot of research on this topic so far, and the only lead that I have is creating a copy of cmd.exe in system32 that has a different name, one of my choosing. The problem is, I am not sure how I would get my bash script to use this new executable with a different name, rather than the default cmd.exe
Requirement: Must use only built in Windows functionality. I do not want to install any other programs if possible.
You can do it with something like the subroutine below. The reason for the first goto is so that you don't fall into the subroutine when you are done. I incorporate another FOR loop to iterate through a list of filenames to check. Let's get this working first.
Your existing bat file goes here
CALL :IsitRunning "SomeFileName"
The rest of your existing bat file goes here
GOTO :eof
:IsitRunning
REM 1=Filename
FOR /F "delims=" %%A in ('WMIC PROCESS WHERE NAME^='CMD.EXE' LIST FULL ^| FINDSTR /I "%~1" ^| FINDSTR /I /V WMIC') DO ECHO(%~1 is running
GOTO :eof
Or you can run this command from a CMD prompt.
wmic process WHERE NAME='cmd.exe' list full | findstr /i "SomeFileName.bat"
You can see command line in Task Manager, turn it on View menu - Choose Columns.
If you want to change process name you have to change the process. So your approach is only way.

Resources