BetaArchive Logo
Total Current Archive Size: 4925.26GB in 15820 files
Navigation Home Screenshots Image Uploader Server Info FTP Servers Wiki Forum RSS Feed Rules Please Donate
UP: 6d, 14h, 41m | CPU: 5% | MEM: 4232MB of 12279MB used
{The community for beta collectors}

Forum rules


Before you post, please make sure...

- ...you have first used Google to look for an answer, and you have asked other people you know via other methods (IM, e-mail, etc).
- ...your question has not been asked before. Search the forum first before posting.

If you meet those criteria, go ahead and post your question. Be sure to provide as much information you can about the problem and how to recreate it. Also provide information on hardware and software if applicable.


Post new topic Reply to topic  [ 8 posts ] 
Author Message
 PostPost subject: [Help] Batch scripting help        Posted: Sat Mar 24, 2012 11:20 am 
Amateur Beta Collector
Amateur Beta Collector
Offline

Joined
Fri Aug 12, 2011 10:49 am

Posts
164

Favourite OS
7601 SP1
Does anyone know how to make a batch file that checks to see if a program is in the processes and then closes another
program if the program in the process is closed?

For example: (Basically what I needed this for)
1. Steam opens origin and this batch at the same time (I can deal with this)
2. I run Battlefield 3 with Origin which starts 'bf3.exe'
3. I finish with bf3.exe and end the game
4. I want the batch that I started to notice bf3.exe was started initially and notice it closed now
5. On the batch file's noticing of the closure of bf3.exe I want it to close origin.exe as well

I know this sounds very complicated but does any of you know if this is possible in batch?

Thanks in advanced,
YoshiHDify

_________________
System Configuration:
MBO: MSI MS-7613 (Iona-GL8E)
CPU: Intel i5-750 2.66GHz
SSD: Intel 520 60GB
HDD: Hitatchi 1TB 7200RPM
GPU: MSI N560GTX-Ti Twin Frozr II 880MHz
RAM: 12488MB DDR3 1333MHz x2
PSU: AYWUN Megapower 550w 80 PLUS


Top  Profile
 PostPost subject: Re: [Help] Batch scripting help        Posted: Sat Mar 24, 2012 11:57 am 
Amateur Beta Collector
Amateur Beta Collector
User avatar
Offline

Joined
Sun Jul 20, 2008 12:30 am

Posts
292

Location
Finland

Favourite OS
They all blow
Not sure if I got it right...
This uses a quick&dirty method for parsing text with an separate txt output and findstr. I am sure that there are better options.
First loop checks if bf3 has been started, after that it starts to check if it has been shut off, if true then tskill origin.
I quickly tested this with two exe files and it seemed to work.
This will create a process.txt file to where you run it, it will contain just a filtered output of tasklist.

Hopefully it works ;)

Code:
@echo off

:Loop
timeout 1                            rem sets the interval for checks
tasklist |find "bf3" >process.txt         rem lists tasks and tries to find the process, puts into txt
findstr /m "bf3" process.txt            rem goes trough that txt and tries to find a string
if %errorlevel%==0 (                  rem If found....
rem echo PROCESS FOUND
goto 2ndLoop
)
if %errorlevel%==1 (                  rem If not found...
rem echo PROCESS NOT FOUND
goto loop
)

:2ndLoop
timeout 10                            rem sets the interval for checks
tasklist |find "bf3" >process.txt         rem lists tasks and tries to find the process, puts into txt
findstr /m "bf3" process.txt            rem goes trough that txt and tries to find a string
if %errorlevel%==0 (                  rem If found....
rem echo PROCESS FOUND
goto Loop
)
if %errorlevel%==1 (                  rem If not found...
rem echo PROCESS NOT FOUND
tskill origin.exe
)

:Escape                              
exit


Top  Profile  WWW
 PostPost subject: Re: [Help] Batch scripting help        Posted: Sun Mar 25, 2012 1:03 am 
Amateur Beta Collector
Amateur Beta Collector
Offline

Joined
Fri Aug 12, 2011 10:49 am

Posts
164

Favourite OS
7601 SP1
oasiz wrote:
Not sure if I got it right...
This uses a quick&dirty method for parsing text with an separate txt output and findstr. I am sure that there are better options.
First loop checks if bf3 has been started, after that it starts to check if it has been shut off, if true then tskill origin.
I quickly tested this with two exe files and it seemed to work.
This will create a process.txt file to where you run it, it will contain just a filtered output of tasklist.

Hopefully it works ;)


Thank you so much for trying to help me but it appears to not work for me :(
I launched the script started origin then started battlefield 3 with origin,
i quit battlefield 3 and origin was still open. the script just keeps going wait 1 sec, press to proceed.
try giving me the code without the comments maybe i stuffed it when i removed your comments.

also is there a special place i need to run this?

notes:
process.txt was created but was blank all the time

EDIT:

THANK YOU SO MUCH!
I did a few tweaks to it and it worked. I learnt that it worked case sensitive so for the process to be picked up
the scripted needed to be exactly how its shown in task manager, also I needed to use "TASKKILL /IM" instead of just tskill

Here is my final code tweaked with word and power point as my testers.

Code:
@echo off

:Loop
timeout 1
tasklist |find "WINWORD" >process.txt
findstr /m "WINWORD" process.txt
if %errorlevel%==0 (
rem echo PROCESS FOUND
goto 2ndLoop
)
if %errorlevel%==1 (
rem echo PROCESS NOT FOUND
goto loop
)

:2ndLoop
timeout 10
tasklist |find "WINWORD" >process.txt
findstr /m "WINWORD" process.txt
if %errorlevel%==0 (
rem echo PROCESS FOUND
goto Loop
)
if %errorlevel%==1 (
rem echo PROCESS NOT FOUND
TASKKILL /IM POWERPNT.exe
)


_________________
System Configuration:
MBO: MSI MS-7613 (Iona-GL8E)
CPU: Intel i5-750 2.66GHz
SSD: Intel 520 60GB
HDD: Hitatchi 1TB 7200RPM
GPU: MSI N560GTX-Ti Twin Frozr II 880MHz
RAM: 12488MB DDR3 1333MHz x2
PSU: AYWUN Megapower 550w 80 PLUS


Top  Profile
 PostPost subject: Re: [Help] Batch scripting help        Posted: Sun Mar 25, 2012 10:12 am 
1337 Beta Collector
1337 Beta Collector
User avatar
Online

Joined
Sat Aug 22, 2009 4:28 pm

Posts
4204

Favourite OS
Mountain Lion, 6730, 8400
Taskkill /f /im - in this case, an app can be force killed even if it doesn't answer the quit code.

_________________
Longhorn Packet 1.21 - Solves most of the problems with Longhorn Setup


Top  Profile  YIM
 PostPost subject: Re: [Help] Batch scripting help        Posted: Sun Mar 25, 2012 10:35 am 
Pro Beta Collector
Pro Beta Collector
Offline

Joined
Mon Jan 03, 2011 10:49 pm

Posts
562

Location
Milkyway Galazy

Favourite OS
Windows 7601 64 bit
Ok time to have some fun I'll help ya out here I've done plenty of batch coding.

Heres what I think you wanna do.

Make a shortcut to the batch file so you don't notice its running to launch steam as well.

I can make this happen get me the Orgin.exe and Steam.exe locations as well as bf3.exe.

It should look something like this:

@echo off
Title Battlefield 3 launcher
pause
\\architecture check here
If Exist "C:\Program Files\(Path)\Steam.exe" (C:\Program Files\(Path)\Steam.exe) Else (C:\Program Files (x86)\(Path)\Steam.exe) \\Launches Steam
If Exist "C:\Program Files\(Path)\Orgin.exe" (C:\Program Files\(Path)\Orgin.exe) Else (C:\Program Files (x86)\(Path)\Orgin.exe) \\Launches Orgin
\\Are you Launching BF3 yourself? if not go on else skip this
C:\(Path to BF3)\bf3.exe \\Launches BF3
goto loop

:Loop
Query Process Bf3.exe
if %errorlevel%==1 (goto CloseDown) else (goto Loop)

:CloseDown
echo Closing Orgin now
Taskkill /IM /F Orgin.exe
echo Closing Down CMD now
exit

All done

_________________
-Smorgs

Given the fact that nothing is surprising in the tech universe if you know whats coming its actually quite boring to watch.


Top  Profile  WWW
 PostPost subject: Re: [Help] Batch scripting help        Posted: Sun Mar 25, 2012 4:53 pm 
Amateur Beta Collector
Amateur Beta Collector
User avatar
Offline

Joined
Sun Jul 20, 2008 12:30 am

Posts
292

Location
Finland

Favourite OS
They all blow
Strange that tskill didn't work.. I have seen other systems that have that similar issue as well.

Good to know about that 'query' command, didn't know that myself, plus getting valid errorlevels as returns is always good.


Top  Profile  WWW
 PostPost subject: Re: [Help] Batch scripting help        Posted: Tue Mar 27, 2012 9:12 am 
Amateur Beta Collector
Amateur Beta Collector
Offline

Joined
Fri Aug 12, 2011 10:49 am

Posts
164

Favourite OS
7601 SP1
Smorgan wrote:
Ok time to have some fun I'll help ya out here I've done plenty of batch coding.

Heres what I think you wanna do.

Make a shortcut to the batch file so you don't notice its running to launch steam as well.

I can make this happen get me the Orgin.exe and Steam.exe locations as well as bf3.exe.


Not quite, nearly there :)
I didn't want Origin running basically, so I turned the batch into an exe and made it a non steam shortcut.
I also wanted the steam overlay :), So by launching The launcher which i added code to launch origin whenever
I felt like playing then launching BF3 from it I should theoretically have the overlay. I also wanted origin to close
after I closed Battlefield 3 so this launcher running in the background checks that BF3 was running and if it is
gets ready to kill origin after I stop BF3. Simple :)

_________________
System Configuration:
MBO: MSI MS-7613 (Iona-GL8E)
CPU: Intel i5-750 2.66GHz
SSD: Intel 520 60GB
HDD: Hitatchi 1TB 7200RPM
GPU: MSI N560GTX-Ti Twin Frozr II 880MHz
RAM: 12488MB DDR3 1333MHz x2
PSU: AYWUN Megapower 550w 80 PLUS


Top  Profile
 PostPost subject: Re: [Help] Batch scripting help        Posted: Tue Mar 27, 2012 7:59 pm 
Pro Beta Collector
Pro Beta Collector
User avatar
Offline

Joined
Tue Apr 26, 2011 1:36 pm

Posts
367

Favourite OS
5.2.3790, 6.1.7600, 6.3.9400
This would be much easier to make in visual basic

Code:
 For Each myprocess As Process In Process.GetProcessesByName("origin.exe")
            Try
                myprocess.Kill()
            Catch

            End Try
        Next

_________________
Image
dont worry if it messes up, i have backups :D


Top  Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 




Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

All views expressed in these forums are those of the author and do not necessarily represent the views of the BetaArchive site owner.

Powered by phpBB® Forum Software © phpBB Group

Copyright © 2006-2013

 

Sitemap | XML | RSS