Help for Dos Newbie - Open 2 files and specfic close option

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
chrisino
Posts: 4
Joined: 23 Nov 2011 08:14

Help for Dos Newbie - Open 2 files and specfic close option

#1 Post by chrisino » 23 Nov 2011 08:23

Hi,

I am new to dos and can only grasp simple instructions at the moment.

I would like to open 2 files in the same directory. File 1 to be opened first and then File 2 five seconds afterwards.

My main problem is that I would like file 1 to automatically close when I close file 2. Is this something that can do in dos or does it require some kind of programming skills

Apologies for the noob question.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Help for Dos Newbie - Open 2 files and specfic close opt

#2 Post by Ed Dyreen » 23 Nov 2011 12:17

'
What do u mean by opening a file ?, Locking it from being written to ?

This can be done with vbscript. Nothing like that with default DOS commands :|

chrisino
Posts: 4
Joined: 23 Nov 2011 08:14

Re: Help for Dos Newbie - Open 2 files and specfic close opt

#3 Post by chrisino » 23 Nov 2011 13:34

Hi,

Not really. Heres the timing batch which I worked out for myself. Delay of 10 seconds between opening first.exe and second.exe. What I need to know is when I close second.exe can I have a script that closes first.exe as well?

It's probably not possible with any Dos commands like you said.

@ECHO OFF
start first.exe
echo wscript.sleep 10000 > temp.vbs
start /wait temp.vbs
start second.exe
del temp.vbs

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Help for Dos Newbie - Open 2 files and specfic close opt

#4 Post by Ed Dyreen » 23 Nov 2011 13:50

'
I think I understand now:

Code: Select all

taskKill.EXE /t /f /im "process.EXE"

chrisino
Posts: 4
Joined: 23 Nov 2011 08:14

Re: Help for Dos Newbie - Open 2 files and specfic close opt

#5 Post by chrisino » 24 Nov 2011 07:42

Hi,

I tried adding this to the batch and it didn't quit the first file when I quit the second. Maybe my explanation is poor?

If it can't be done then is it possible to minimise the first file to the toolbar?

Thanks

Chris

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Help for Dos Newbie - Open 2 files and specfic close opt

#6 Post by Ed Dyreen » 24 Nov 2011 08:24

'
Shutting down a process is not too difficult:

Code: Select all

@echo off

taskKill.EXE /?
pause

taskKill.EXE /t /f /im "cmd.EXE"
echo.never get's here.
pause

exit /b 0

taripo
Posts: 228
Joined: 01 Aug 2011 13:48

Re: Help for Dos Newbie - Open 2 files and specfic close opt

#7 Post by taripo » 25 Nov 2011 13:15

Here it is. The file stars from the line @echo off

It opens calc.exe(process 1) and wordpad.exe(process 2)

If you then close calc.exe, wordpad.exe will immediately close.

The way it works, is it starts them both.

Then in a loop it keeps testing if calc.exe is running. If it isn't running, then it has been closed, then it closes wordpad.exe

You can put your vbscript 5 second pause between starting the two processes if you want.

@echo off
set tmpf=%TEMP%\asdf.a

set proc1=c:\windows\system32\calc.exe
set proc1b=calc.exe
set proc2="c:\Program Files\Windows NT\Accessories\wordpad.exe"
set proc2b=wordpad.exe

start "" %proc1%

start "" %proc2%


:BLAH

tasklist >"%tmpf%"
type "%tmpf%" | find "%proc1b%" >nul

if ERRORLEVEL 1 (
taskkill /f /im %proc2b% >nul
GOTO EOF
)

GOTO BLAH

:EOF

chrisino
Posts: 4
Joined: 23 Nov 2011 08:14

Re: Help for Dos Newbie - Open 2 files and specfic close opt

#8 Post by chrisino » 26 Nov 2011 23:05

Thank very much worked a treat.

Post Reply