Scripting environment setup in windows - windows

When I start my day programming (using windows 7), I have a bunch of windows I'd like open and ready:
command prompt in my code directory running the DevNull smtp java server
command prompt in the tomcat\bin directory with startup.bat running after rmdir /S /Q'ing work and test webapp directories
IntelliJ running
after tomcat loads (fine with just having a timer), Firefox with my webapp loaded
after tomcat loads, Chrome with my webapp loaded
Those are pretty core... then it depends on what exactly I'm working on as far as other apps I need open.
So how do I write a script I can double click on and have all the above ready for me, saving me a couple minutes each day and a little less annoying getting started? I know about .bat files, is it easy to do the above with a .bat file? Is there a nice app that can easily do the above for me?

It is pretty straight-forward to put all of that in a bat file, something like this:
#echo off
rmdir /S /Q testdir
rmdir /S /Q workdir
start cmd /K c:\foo\bar.bat
start cmd /K c:\foo\bas.bat
start firefox.exe "http://www.stackoverflow.com/"

You can put all that into a batch file, and use the sleep command from the Windows Server 2003 Resource Kit Tools.

Related

Getting a Windows batch file to execute an application in background and then execute the next statement

I am having issue trying to get my Windows batch file to launch the Jetty web server in the background and then launch IE. The current behavior is that after it started my Jetty web server, it doesn't return to launch IE. It simply stuck there until I terminate the web server and then batch script will then proceed and launch IE.
Here's my batch script
SET JAVA_HOME=".\openjdk-1.8.0.141"
SET JETTY_HOME=".\jetty-distribution-9.4.6.v20170531"
start /B cd /d "%~dp0" & %JAVA_HOME%\bin\javaw -DSTOP.PORT=8081 -DSTOP.KEY=stop_jetty -Djetty.base=%JETTY_HOME% -jar %JETTY_HOME%\start.jar
"C:\Program Files\Internet Explorer\iexplore.exe" http://localhost:8080/foo-tools
Can you spot anything obvious here? I already used the 'start /B' to attempt to launch it in the background. I have to change directory back to the current working directory, otherwise the variable that I set will not work.
Thanks in advance!
Why not simplify things and stipulate the script path with the START's /D <Path> parameter?
SET "JAVA_HOME=openjdk-1.8.0.141"
SET "JETTY_HOME=jetty-distribution-9.4.6.v20170531"
START "" /D "%~dp0" "%JAVA_HOME%\bin\javaw" -DSTOP.PORT=8081 -DSTOP.KEY=stop_jetty -Djetty.base="%JETTY_HOME%" -jar "%JETTY_HOME%\start.jar"
START "" "%PROGRAMFILES%\Internet Explorer\iexplore.exe" http://localhost:8080/foo-tools
I missed off START's /B parameter because it was my understanding that javaw.exe doesn't open a CMD window anyhow. If my understanding is incorrect then please add it back just before "%JAVA_HOME%.
The START command for IE is only really necessary if you need the script again or don't want the cmd window to remain open.

How to hide command prompt windows using ExecDos command

I want to execute three bat files in my script, the problem is when i run these .bat files directly using execwait, command windows gets open, I want to hide these command windows but its not working. My code is of just 3 lines.
ExecDos::exec '"catalina_start.bat"'
ExecDos::exec '"mysql_start.bat"'
ExecDos::exec '"apache_start.bat"'
I also tried this nsExec command but still no solution:
nsExec::Exec "cmd /C catalina_start.bat"
nsExec::Exec "cmd /C mysql_start.bat"
nsExec::Exec "cmd /C apache_start.bat"
A little background on these .bat files, Actually these are files of xampp setup, xampp internally uses these files to start tomcat, mysql, and apache.
The problem I am facing is that only first bat file gets executed, i. e. tomcat gets started (I can see that in xampp console), but then script dosen't move ahead, sql and apache is not getting started.
Does the batch-file contain pause or something else that prevents it from completing?
You should start off just by using something like ExecWait '"cmd.exe" /k "$InstDir\catalina_start.bat"' (or /c) so you can see the text written to the console including any errors. Once it works correctly you can switch to one of the exec plugins that hides the console...
You can change command windows from cmd /C catalina_start.bat to start /Min cmd /c catalina_start.bat it will hide command windows

Batch file to start all programmes in the start folder of XP

I need start all folders in a the Windows "Start/Programs/Startup folder" of an XP machine, explorer is disabled to stop top people playing and remove the Start and Task-bar.
I can run a batch file at start-up but how do I write the batch to run ALL programs in the "Start/Programs/Startup folder" the programs in the folder may change but the batch needs to remain the same
I am able to open each file individually using the below code but I really need to be able to open everything in the folder to avoid problems in the future
start "" /b "C:\Documents and Settings\User\Start Menu\Programs\Startup\PROG.appref-ms"
I have tried the code below, that batch starts but nothing starts
%DIR%=C:\Documents and Settings\Pete\Start Menu\Programs\Startup
for %%a in (%DIR%\*) do "%%a"
Running the batch from the desktop also doesn't run the programs in the start folder, the DIR address is taken from windows explorer when I navigated to the folder with the short cuts in
This is an interesting request--one that I would question the motive behind, but since you asked, here's a way you could accomplish it:
#echo off
set DIR=C:\Your\Directory
for %%a in ("%DIR%\*") do "%%a"

My batch file is closing a program too early

Thank you, for those whom took the time to read my question. I am a gamer and would like to execute a few things. First, I would like to Trigger a batch file when I click a program, how do you do that or is it even possible? Basically, activating a game, triggers the batch file.
NOw for the batch file problem, I want to execute Xpadder when I activate games (this is an mmo) and when I close the game I want Xpadder's process/service to close. Ultimately, it's auto trigger,activate,wait,terminate.
That's kind of the process I want it to go if all can be done.
Batch File:
#echo off
start "Blade" "C:\Users\user\Documents\Blade.xpadderprofile" Blade.xpadderprofile
ECHO Blade.xpadderprofile STARTED
start /w "C:\Program Files (x86)\game\games.exe" games.exe
ECHO games STARTED
taskkill /f /im Xpadder.exe
This actually works but the problem is there are two ".exe" files with mmo's. I'll start the game and it would close Xpadder too early because one launcher starts another launcher/client. Xpadder works for the first launcher but the first launcher closes so the game will start. I hope I am explaining myself clear enough.
Reference link: How to automatically close App_A when I close App_B using batchfile
Essentially, this is the same question I have but it's not very clear. What is the batch code to get Xpadder to stay on until the second launcher/client is closed not the first one?
P.S
The game has to open through the launcher then into the second launcher/client or it will not work.
here is the other clients name and path i think:
C:\Program Files (x86)\game\gamer\bin\gam.exe
How about the use of the PsExec, a small MS ulility? Using it, your batch should work:
cmd /c psexec -d "Blade" "C:\Users\user\Documents\Blade.xpadderprofile" Blade.xpadderprofile
start /w "C:\Program Files (x86)\game\games.exe" games.exe
taskkill /f /im Xpadder.exe
The file psexec.exe must be placed in folder enlisted in the system variable WINDIR or PATH, or, otherwise, you should call it with its full path, eg. *C:\Program Files\Others\pstools.exe".
You can add #echo off, salt, pepper or some green Tabasco if you have mon€y for this :D

Hide CMD window after using START to run a network application

I have an application that is run over a network. I need to be able to run this application from a batch file, and had ended up using this:
pushd \\server\folder
start /wait program.exe
Aside from the message saying...
\\server\folder
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
...it works fine, but the CMD window lingers. I know that /wait is the cause, but it appears that I can only get the program to run successfully if I use /wait. If I remove /wait, then I get bizarre errors from the program about not being able to start successfully.
What else might there be that I can try?
If you want to hide the program while it runs, you can also use the /MIN param, to have it start minimized.
Try:
start /b /wait program.exe

Resources