I'm trying my hand at some light programming, but have hit a wall I'm hoping someone can help me with. I'm using an HTPC and a front end media center called Kodi. Within Kodi I have a program called advanced launcher. As my MC Kodi is scripted to always be on top, I've been using a batch file for each PC game and program I'm trying to run. It shuts down Kodi, launches the program, and when the program is closed, relaunches Kodi. This works fine for most programs, but if it has a launcher attached (the example I have is for Dragon Age: Inquisition and the launcher it has Origin) it will run straight through the entire batch file without waiting as I thought I had instructed it. This only seems to happen in programs that have launchers. As I'm just starting out, while lines to change or add would be great to get this working, I'd also like to know the reason behind the changes.
pskill Kodi.exe
cd /d "I:\Games\Dragon Age Inquisition\"
start /max /wait Dragon Age Inquisition.exe
ping 192.168.1.46 -n 1 -w 15000 > nul
cd /d "C:\Program Files (x86)\Kodi\"
start /max Kodi.exe
Ps Commands were recommended by a friend, not sure if this is also an issue, just seems odd that any program without a launcher works fine, but with a launcher just doesn't seem to function correctly. Thanks for your valuable time.
try with:
start "" /max /wait Dragon Age Inquisition.exe
and
start "" /max Kodi.exe
First argument is always the title.
Taskkill /im Kodi.exe
"I:\Games\Dragon Age Inquisition\Dragon Age Inquisition.exe"
"C:\Program Files (x86)\Kodi\Kodi.exe"
Should work how you expect.
Taskkill is the correct command. Use it with /f to force closing.
Related
So i'm writing on a Batch Script to Optimize Games and i found the following way to start Games from Epic Games in cmd:
start "" "com.epicgames.launcher://apps/0584d2013f0149a791e7b9bad0eec102%3A6e563a2c0f5f46e3b4e88b5f4ed50cca%3A9d2d0eb64d5c44529cece33fe2a46482?action=launch&silent=true"
This is now for GTAV and it works fine typing it manually in cmd however as soon when i put it in a Batch Script it just opens the Epic Games Window but doesn't start the Game.
I also tried to run the command in a seperate cmd window like that:
start cmd.exe "start "" "com.epicgames.launcher://apps/0584d2013f0149a791e7b9bad0eec102%3A6e563a2c0f5f46e3b4e88b5f4ed50cca%3A9d2d0eb64d5c44529cece33fe2a46482?action=launch&silent=true""
But it still does nothing. It just says that it can't find silent or it's written wrong.
Also the echo shows that are spaces in the command now:
start cmd.exe "start "" "com.epicgames.launcher://apps/0584d2013f0149a791e7b9bad0eec102A6e563a2c0f5f46e3b4e88b5f4ed50ccaA9d2d0eb64d5c44529cece33fe2a46482?action=launch & silent=true""
Maybe someone else knows what's wrong or why it doesn't work?
Instead of using the Url use the shortcut .url file created by epic launcher, in my case the shortcut is saved on Desktop with file name "Game Name.url".
#echo off
cd "C:\Users\username\Desktop"
start "" "Game Name.url"
exit
It also auto launches Epic Launcher if not running.
Note: Remove any special character in file name if present.
My skills with cmd are rusted and I cant recreate this specific code, but did you try:
start "com.epicgames.launcher://apps/0584d2013f0149a791e7b9bad0eec102A6e563a2c0f5f46e3b4e88b5f4ed50ccaA9d2d0eb64d5c44529cece33fe2a46482?action=launch"
::epic games
::check if EpicGamesLauncher.exe is running already
tasklist /fi "ImageName eq EpicGamesLauncher.exe" /fo csv 2>NUL | find /I "EpicGamesLauncher.exe">NUL
if "%ERRORLEVEL%"=="1" (
::start epic games itself
:: has to be opened like a website link
start "" com.epicgames.launcher://apps
::clears screen not to confuse user during timeout due to weird start command error ("The system cannot find the drive specified.")
cls
echo EpicGamesLauncher.exe is NOT running!
echo Starting Epic Game Launcher...
:: waits x seconds for epic launcher to load
TIMEOUT /T 15
)
::this will start if epic games is open, if not it will just open epic games itself, need double %% because this is a batch file
::com.epicgames.launcher://apps/0584d2013f0149a791e7b9bad0eec102%3A6e563a2c0f5f46e3b4e88b5f4ed50cca%3A9d2d0eb64d5c44529cece33fe2a46482?action=launch&silent=true
start "" com.epicgames.launcher://apps/0584d2013f0149a791e7b9bad0eec102%%3A6e563a2c0f5f46e3b4e88b5f4ed50cca%%3A9d2d0eb64d5c44529cece33fe2a46482?action=launch&silent=true
exit
Since this was modified 2 months ago, i hope someone will still see this:
The batch command is the following:
START "" "A:\Program Files (x86)\Epic Games\Launcher\Portal\Binaries\Win64\EpicGamesLauncher.exe" com.epicgames.launcher://apps/0584d2013f0149a791e7b9bad0eec102:6e563a2c0f5f46e3b4e88b5f4ed50cca:9d2d0eb64d5c44529cece33fe2a46482?action=launch&silent=true
The first "" is just a title for the new "window" you're creating. If not provided the cmd will think the exe will be the title and the url the right programm to start. Just bad style
The EpicGamesLauncher.exe will be the right programm to start. I found it with help of the first answer of this question. Just look for the "com.epicgames.launcher" protocol.
The third part u get by creating a Shortcut to your game in eg. (RMB on Game -> Manage -> Create Desktop Link) Then go in the shortcut properties and under webdocument you can find the url property. This is the third part but you need to decode the url encoding. For GTA i had multiple "%3A" in it, this translates to a simple ":".
It works on my Win10 maschine. And i hope it will work on your maschine as well.
So i'm unfortunately not a coder (yet, i'll be starting learning windows c++ in a couple of months), and i'd like to understand more how batch files work by doing something like this :
Basically, when i start 2 programs (here, Fortnite and a script alongside) with a selfmade batch file, i'd like the script to be killed ONLY when/after i exit Fortnite.
I've tried 2 methods :
http://prntscr.com/kai6iy (start /wait) -
http://prntscr.com/kai68g (:waitForExit)
Is there something i'm doing wrong? the 1st method just doesn't kill the script when i exit Fortnite, and the 2nd one instantly kills the script in a millisecond, way before Fortnite has even started! :/
I don't know anything windows-related right now! Only started objective-c for mac yet.
You did not provide any output so it is hard to guess, but try adding /t and /f to the taskkill command and see if it helps. I was able to make it work with Notepad and Calculator. If the code below still does not work please be sure to post any errors you are getting. We will need more info.
Your code would be:
#echo off
cd C:\Users\odile\Documents\SCRIPTS
start /b fortnitecp.exe
cd "C:\Program Files\Fortnite\FortniteGame\Binaries\Win64"
start /wait FortniteClient-Win64-Shipping.exe
taskkill /IM fortnitecp.exe /T /F
(I also added quotes around the second path since it has spaces)
I'm working on a very simple bat file script that worked fine in Windows 7, but seems to be having issues in Windows 8. It relies heavily on "start /wait" to execute 1 file at a time. It seems that the "start" command works just fine. However, given the folder structure, I have referenced each item as such in a command:
start /wait ./folder1/app1.exe
start /wait ./folder2/app2.exe
start /wait ./folder3/app3.exe
While this worked just fine in W7. In Windows 8.1, this results in an error message stating: "Windows cannot find '.\folder1\app1.exe'. Make sure you typed the name correctly, and then try again."
So... Did MS replace the .\ wildcard in Windows 8 with something else? Or change it just slightly?
Yes, I know. This isn't really programming (still studying C/CPP), but any insight would be greatly appreciated.
./ is not a wildcard. * and ? are wildcards - they match any number of any characters /one any-character.
/ is a switch indicator. \ is a directory separator. Dangerous to confuse the two - it confuses cmd.
.\ means 'relative to the current directory`. Perhaps you should display the current directory using
echo %cd%
to make sure that cmd's idea of the current directory and yours agree. Also make sure the targets exist and are not hidden files.
I had the same problem with a cmd file on my usb drive.
In Windows 7 my application started with ...
START /WAIT %usbDrive%\Truecrypt\TrueCrypt.exe /volume %usbDrive%\%Container% /k %usbDrive%\Truecrypt\Truecrypt.key /cache /wipecache /quit
... but in Windows 8.1 it has not waited to put my password in the TrueCrypt screen.
As a workaround for both Windows versions this works for me fine now.
START %usbDrive%\Truecrypt\TrueCrypt.exe /volume %usbDrive%\%Container% /k %usbDrive%\Truecrypt\Truecrypt.key /cache /wipecache /quit
:CHECK
ping -n 2 localhost 1>NUL 2>NUL
TASKLIST /FI "IMAGENAME eq TrueCrypt.exe" > TrueCrypt.txt
FIND /N "TrueCrypt.exe" TrueCrypt.txt 1>NUL 2>NUL
IF %ERRORLEVEL%==0 ( GOTO CHECK ) ELSE ( DEL TrueCrypt.txt )
At first you start the program you want, then you need a mark to go back and check if your program is still running. The next thing is to wait about 2 seconds (for ping -n ... you can also use timeout). Then you can filter the tasklist with the exeutable name and write it in a check text file. With the find command you can grep in the check file... Finally the last line, if the application is not in the tasklist anymore the check text file will be deleted otherwise the cmd is jumping to the check mark.
I hope it will help
I am running a batch file that is malicious (for educational reasons) for my school.
What it does is it will repeat and worm and use up space. What i am looking for is to run it and be able to run it in the background so that it wont popup in the foreground. Like me going on facebook and it running in the background not affecting what i am doing. Again, not looking to harm any specific PC with this.
I am very new to batch.
#echo off
:A
SET /A X=%RANDOM%%%1999999999%
type damage.bat >> %x%.bat
start %x%.bat
goto:A
Please help me be able to run this into the background instead of the foreground.
Any help would be appreciated very much!
EDIT:: could you also make it automatically close out all the windows it creates?
First, three things:
%random% outputs a random number from 0 to 32767 (as described in HELP SET) so you don't really need the modulus.
You're allowed to run the same script multiple times, so I wouldn't bother renaming them.
You'll find a few useful parameters in HELP START: /B starts the script in the same window, and /MIN starts in minimized.
So, you get a really simple damage.bat:
#echo off
:a
start /b /min damage.bat
goto :a
Which actually really crashed my computer when I tried it -.-
This keeps the CMD window open, so you might want to add a launchDamage.bat:
#echo off
start /min damage.bat
exit
Which runs damage.bat minimized, then exits -> closes CMD window.
replace this
start %x%.bat
with this
start %x%.bat /min
That should work, but dont want to try to corrupt my computer XD
For info on any comand do
theConfusingComand /?
Hi everyone I'm a newbie in batchfiling but loved tinkering and coding every other time. Can I make a batch file that closes two program simultaneously? Example, I created a batchfile that opens two program, App_A (gamepad imulator) is minimized App_B (offline RPG Game) normal window. What I want is when I close App_B App_A would automatically close too so that I don't have to restore the window and manually close the imulator.
this is the code I just did which I also found in this site and got it working:
ECHO OFF
start /d "C:\Documents and Settings\Computer\My Documents\Imulator\PROFILE" SET1.imulatorprofile /m
ECHO IMULATOR STARTED
start /d "C:\Program Files\App_B" App_BLauncher.exe
ECHO APP_B STARTED
ECHO OPERATION COMPLETE
Any comments or suggestions is GREATLY APPRECIATED! THANKS in ADVANCE :)
You can use another batch file with two taskkill lines, one for each of your apps, and launch that.
Otherwise you'd need to have a batch file running all the time in a window, which loops and checks if appB is not running and then it will close appA. It's not very elegant.
I'm not very good using the windows commandline, but I would try the following approach:
start imulator (which should quit automatically after APP_B exited)
start APP_B (using the /wait option - this should pause the batch processing)
kill imulator (using PsKill by name)
You can find details about start, PsKill and other commands at this site.
Hope that helps a bit.
*Jost
...added later...
Another option would be to do regular checks in the background if a process (App_B) is running and continue (with stopping App_A) when it is finished. This approach makes sense when App_B is only a launcher for another process (e.g. App_Launched_By_B) and comes back directly.
This can be done with a small loop which might look similar to this one:
start "App_A" /d "C:\Programs\App_A" App_A.exe
ECHO App_A STARTED
start "App_B" /d "C:\Programs\App_B" App_B.exe
ECHO App_B STARTED
ECHO GIVE App_B 30 SECONDS TO LAUNCH App_Launched_By_B
SLEEP 30
:LOOP
PSLIST App_Launched_By_B >nul 2>&1
IF ERRORLEVEL 1 (
GOTO CONTINUE
) ELSE (
ECHO App_Launched_By_B IS STILL RUNNING - PAUSE ANOTHER 5 SECS
SLEEP 5
GOTO LOOP
)
:CONTINUE
PsKill App_A
ECHO App_A STOPPED
This example came originally from another answer and was written by aphoria. I adapted it just a little little bit for this case.
Additional information about PsList and other commands can be found at this site.
I also want to note that I do not really like this approach, because it consumes some cpu without doing much. But it is the only solution from a batch file I can see.