0

Okay so I managed to make the batch file start up my completely potato game on my potato laptop (this is just a laptop for coding practice, side projects, surfing the internet etc) upon logging in. Great.

But now how do I make the same batch file execute another command separately, namely that upon quitting the game, I"ll be automatically logged out of my win 10 user account?

I know it"ll be "logoff.exe" I think, but how do I make the script get the order of commands right? ie first launch the game and IF I quit the game it"ll log me out?

2 Answers2

0
@ECHO OFF

START "" "steam://rungameid/40970"
Timeout /T 25 /Nobreak


:LOOP
tasklist | find /i "STRONGHOLD" >nul 2>&1
IF ERRORLEVEL 1 (
  GOTO CONTINUE
) ELSE (
  ECHO STRONGHOLD is still running
  Timeout /T 5 /Nobreak
  GOTO LOOP
)

:CONTINUE
echo exited
SHUTDOWN /l /f
Gantendo
  • 4,615
  • 1
  • 18
  • 30
  • So if my script so far looks like this: at echo off start steam://rungameid/40970 at echo on then how do I do what you said? – ProprietaryCloudGaming Nov 13 '21 at 04:39
  • Stronghold Crusader HD... good game. https://stackoverflow.com/questions/8177695/how-to-wait-for-a-process-to-terminate-to-execute-another-process-in-batch-file/8197920 I edited the answer above. Try that, if it doesn't work we may have to make it more complicated. I don't have Steam installed so I can't test it. – Gantendo Nov 13 '21 at 04:41
  • Okay so I copy pasted exactly what you wrote, the last part and it did launched the game for me but upon exiting the game it wouldn"t force log me out – ProprietaryCloudGaming Nov 13 '21 at 04:47
  • @ProprietaryCloudGaming I added another way. – Gantendo Nov 13 '21 at 04:52
  • It's Stronghold Crusader (32 bits) – ProprietaryCloudGaming Nov 13 '21 at 04:53
  • Try this. Should work. I am assuming the filename of the executable is something like stronghold.exe – Gantendo Nov 13 '21 at 04:53
  • Works perfectly, thank you. Is there a way to make the batch file do exactly what I want but without the cmd prompt window popping up during either of these 2 actions (launching the game on startup + force-logging out the user upon exiting the game)? – ProprietaryCloudGaming Nov 13 '21 at 04:58
  • I haven't tried it but you can try https://github.com/stbrenner/SilentCMD or https://www.battoexeconverter.com/ or you can create a .vbs script that runs the batch file invisibly as explained over at https://superuser.com/a/62646/1482432 – Gantendo Nov 13 '21 at 05:02
  • Why doesn"t the advanced bat to exe converter run the exe file silently without the cmd prompt window popping up? – ProprietaryCloudGaming Nov 13 '21 at 05:42
  • @ProprietaryCloudGaming https://i.imgur.com/Hu2mGby.png You need to select the "Start invisible"-checkbox. After you clicked the Build EXE button. – Gantendo Nov 13 '21 at 05:47
  • @ProprietaryCloudGaming To mark an answer as accepted, click on the check mark beside the answer to toggle it from greyed out to filled in. – Gantendo Nov 13 '21 at 05:48
  • I cant see the Build EXE button, where is it? – ProprietaryCloudGaming Nov 13 '21 at 06:04
  • @ProprietaryCloudGaming https://i.imgur.com/htQj1FY.png – Gantendo Nov 13 '21 at 06:05
  • thank you. What does the Include Admin Manifest button do? – ProprietaryCloudGaming Nov 13 '21 at 06:07
  • @ProprietaryCloudGaming It makes the program require admin privileges. You don't need those in this case. – Gantendo Nov 13 '21 at 06:08
0
@ECHO OFF

:: This batch file start program1, after closing it logs off pc

TITLE my auto progam starter and loggoff on quit(sorry for the typing
errors)

ECHO Please wait... starting program1

ECHO ============================

START /WAIT steam://rungameid/40970

ECHO logging you off now...

TASKKILL steam 

(or what the steam process is called, im not sure, should close both the steam app and the game, if not add additional takkill for the gameprocess)

shutdown -l

Sathyajith Bhat
  • 61,504
  • 38
  • 179
  • 264
  • We tried that, it didn't work in this case. – Gantendo Nov 13 '21 at 05:03
  • wow nice - and you tried it 1 second after i wrote it? :) either way the author can try and check should have no issue - you first echo off all the commands - the sttart /wait is the way to do it without any lagg as it it simply waits for process to end then runs the logoff at the end of the process – Pablo Rotem Nov 13 '21 at 05:09
  • It was in an older version of my answer. OP tried it, it didn't work, hence the current method. – Gantendo Nov 13 '21 at 05:10
  • could be an issue with the game itself - not the commands - perhaps try adding -f and the end to force the loggoff - - but could be that the game process simply takes a while to end - you can force end it on click but no idea what game it is - it might break saving if there is such a thing in that game - i use this for heroes 3 and it sometimes takes 10 min before it loggs me off after i close cause the process keeps lagging for a few minutes till it full closes like any process in windows – Pablo Rotem Nov 13 '21 at 05:14
  • i think /w doesn't work cause the start command runs a steam shortcut, not the .exe directly. Heroes of Might and Magic III was an awesome game. OP is running Stronghold Crusader. – Gantendo Nov 13 '21 at 05:16
  • i see, that means there are 2 processes that neeed to be opened then closed prior to the shutdown -l i reccomend try to observe them via process manager as tehre could be more then two - then add them both - should work , problem is console cant tell spawned process from original process - meaning if it is a steam game that spawns steam app and the game it will treat them as one when opening but wont know they are both closed - try to add the steam.exe and the gmae process speratly one under the other might solve it – Pablo Rotem Nov 13 '21 at 06:52