Problem with starting Games from Epic Games in a Batch Script - batch-file

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.

Related

Open, wait, save, close, and copy a file using Windows batch file commands

With my .bat I would like to:
open the xlsx file,
waiting 2 min,
close the file with save options
copy this file to another folder.
For now I can copy and paste the file, but I don't know how to open it, with a cmd function, and save it.
Thank you for your help.
My code is :
#echo off
cmd "O:\XXXX\*.*"
xcopy/y "O:\XXXX\*.*" "O:\XXX\"
pause
Marie (TooLong;ToRead) in disjointed comments
I suggested, A simpler alternative method to do what you need on this
occasion is to use a simple command line tool see Orlandos Sendkeys
Utility (the example is almost what you want to do)
download sendkeys from cpap.com.br/orlando
see how the demo runs
open excel with a blank sheet and at a CMD> run this demo string
SendKeys.exe 1.5 10 "Microsoft Excel" "Hello!~{PAUSE 2}After 2s.~{PAUSE 2}%(FS)~"
adapt to your own version of excel keys since the %(FS) is ALT File Save in English
you replied
#KJ Thank you, KJ, unfortunately I can't download Orlando with my PC.
So we continue to doing it in a more dirty fashion, but you still need a means to save the file by invoking an autosave which would most easily be done using an extended excel macro in your source .xlsm, anyway
after all these changes your non working file should now be replaced in your question as
#echo off
start "Excel Running" /MIN EXCEL.EXE "\\XXX\Fichier.xlsm"
REM add a delay of **2 minutes !** whilst sheet recalculates before saving a copy
timeout 120
REM copying a file that has NOT been saved using keys at this point will NOT
REM be what you really need to solve your problem unless you use a macro ?
REM see Later
xcopy/y "\\XXX\Dossier_avant*.*" "\\XXX\Dossier_apres\"
REM add a 3 second delay to check above worked but is not really needed
timeout 3
REM temporary for debugging. Later just REM it out
TASKLIST /M |Find /i "exce"
REM this line should be working with either a SUCCESS: or ERROR:
TASKKILL /T /F /IM excel.exe
REM keep this line for seeing errors above, once happy, it can become REM PAUSE
PAUSE
I think that IF you are constrained (by IT policy) to the command line it is best you write your own autosaving macro, however, MY problem is I dont know if you need it for more than one input.xlsm.
So save this as OpenRunSaveExit.vbs in your working folder where your .bat is. There is a reason I did NOT use spaces or & in the name for a later step.
Set WshShell = WScript.CreateObject("WScript.Shell")
' You may need to include the path to excel.exe if it is a portable version like mine
WshShell.Run "EXCEL.EXE "+"\\XXX\Fichier.xlsm", 9
' 120000 milli-seconds = 2 minutes
WScript.Sleep 120000
' These are the English key combinations for ALT+File+Save . SO alter or remove if not needed
WshShell.SendKeys "%FS"
' These are the English key combinations for ALT+File+eXit . SO alter if needed for french excel
WshShell.SendKeys "%FX"
' Lets us wait 2 seconds for clean closure
WScript.Sleep 2000
As Peter has pointed out in his answer you need to /WAIT before xcopy and depending on how your vbs file handling is set-up you may not need Wscript in the start line
NOW replace your .bat with this
#echo off
start /WAIT Wscript OpenRunSaveExit.vbs
xcopy/y "\\XXX\Dossier_avant*.*" "\\XXX\Dossier_apres\"
pause
And check it runs without the need for taskkill.
Finally why use a 2-4 line .bat since a desktop shortcut would potentially be easier to use. So make a shortcut for the .vbs file (right click the .vbs, and in English its Create Shortcut) and wherever it is built move it to your desktop.
Then change the properties like this (where & has a special meaning so the .vbs filename must NOT have spaces or &.)
%comspec% /c "start /wait wscript.exe OpenRunSaveExit.vbs & xcopy/y "\\XXX\Dossier_avant*.*" "\\XXX\Dossier_apres\" & pause"
P.S. I forgot to add Peters start / wait in this image until later
You can't interact with Microsoft Excel (or most of other programs) through Batch unless they provide such an interface. There is however an option to do it with VBS i.e. via an interface Microsoft Excel supports for interacting with that software.
For just opening the program check start command e.g.:
start /B excel.exe <filename>
then you can wait for the user to both edit and save the file for two minutes or also utilize pause if you don't want to introduce a race condition between saving and copying with xcopy.
Alternatively use start like this:
start /WAIT /B excel.exe <filename>
so the opened file blocks the operation and once it closes (no edit or saving by the user guaranteed) then it'll unblock and xcopy would take place without any time-dependent feature.

Using batch to close open image file or word doc

I am coding a choose your own adventure game. Im at the point where a player would have a choice to look at a poster or a document on a desk and the game would open a .jpg file with the poster art or document on the desk i then want the game to close the .jpg file after 5 seconds. I have found so many questions about how to close programs and .exe with batch using exit/b and taskill but there is nothing about closing specific open files viewed by a program like an image viewer. In my case, the .jpg is being opened using windows photo viewer. the title of the window is "BADGE.jpg - Windows Photo Viewer" if i could and when the game is played on another computer there might be a different default image viewer, so i need a way just to close the file regardless of what program has it open.
below is a snippet of my code. :Test1 is where my problem lies
#ECHO OFF
: START
CLS
ECHO THIS IS A TEST PROGRAM TO SHOW THE USER AN IMAGE
ECHO OR FILE AND THEN CLOSE AFTER 5 SECONDS
PAUSE >NUL
GOTO TEST1
: TEST1
ECHO PRESS ENTER TO OPEN IMAGE
ECHO.
PAUSE
START "" "%~dp0\BADGE.jpg"
PING -n 2 0.0.0.0 1>NUL
exit "%~dp0\BADGE.jpg"
:: TASKKILL /F /IM BADGE.jpg
PAUSE
goto end
: end
echo.
echo IF THE IMAGE CLOSED AFTER 5 SECONDS THEN THIS TEST WAS A SUCCESSFUL
PAUSE
GOTO START
use the /fi switch (Filter), where wildcards are allowed:
taskkill /fi "windowtitle eq BADGE.jpg"
Doesn't matter, if * is - Windows Photo Viewer or - IrfanView or something different - as long, as the window title starts with the given file name.
Downside: it will kill every process with the given window title (although it's not very likely, there are more than one)
Note: start starts another cmd window - this is not needed, use just "%~dp0\BADGE.jpg" instead, which will open the jpg wtih it's default application. Also exit doesn't work, as you seem to think. You can't exit another process, you will always exit your batch file.
I've tested below script that I believe will work for you;
#echo off
start file9876.jpg
timeout 5
for /F "tokens=2 delims= " %%i in ('tasklist /v /fo table ^| findstr /i file9876') do set pid=%%i
taskkill /PID %pid%
It's best if the file you want to open/display has a very unique name so you can put it in the findstr command. In my case its file9876. Don't put a full file name with the extension - your program might not display it. If it also doesn't display a file name too just open it manually and check window name (that's what the script looks looks for).
And very important - don't move timeout line after the loop because your program might not actually be able to start enough and it won't be included in the task list so it won't find it and it will stay open (also tested on my own skin).
You can improve it to check if the program actually started and then look for the PID, also check if it was closed etc - some basic check to make it more bulletproof.
I tried to make this script as short and neat as possible - hope this helps you :)

Batch command /wait not waiting

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.

CMD Batch command "start /wait" not working in Windows 8.1?

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

How to prevent batch window from closing when error occurs?

I'm trying to write batch script to create a folder if it does not already exist.
Following up the online examples, below is my script.
The problem is; first pause works, then probably due to syntax error the window closes even before reaches to the second pause, so I can't really tell which part of my script is wrong.
Could anyone show me how to prevent closing window so that I can see what's on the window?
#echo off
:copy theme images over
:designer
echo copying theme images over...
pause
if not exist "%K2DIR%\K2 SmartForms Runtime\Styles\Themes\Sharepoint 2013\rich_text"
(
md "%K2DIR%\K2 SmartForms Runtime\Styles\Themes\Sharepoint 2013\rich_text333"
)
pause
You could put this line at the beginning of the batch file:
if not defined in_subprocess (cmd /k set in_subprocess=y ^& %0 %*) & exit )
What this line does is, the first time you run it, it re-launches itself in a subprocess that doesn't exit after it finishes running the batch file.
You need to pass the /K switch to CMD, or just open a Command Window and run the batch from the command line.
Press start and type cmd and press enter, you will launch a command prompt.
Just drag and drop what you need to run (your python script, .exe ...) into the cmd windows, and press enter.
(You might some time to run the cmd as admin: find the cmd in the start menu, right-click on it, choose run as admin).
I recorded the screen (bandicam) for when I couldn't quite read the error message, and then I could replay it; I suppose this is mainly helpful if you already have software on your computer.
using pause at end of batch paused the cmd screen, tanks!
How to prevent batch window from closing when error occurs?
I had the problem when using robocopy. My solution was:
if not %errorlevel% lss 8 pause
For Robocopy every exit code below 8 is a success:
https://ss64.com/nt/robocopy-exit.html

Resources