1

I have a batch file program something like.

@echo off
start Mat.exe
>>Need a code here to runand check for termination of "Mat.exe"
rundll32.exe user32.dll, LockWorkStation

>>end of program

If anyone can help me set up the program so that I can lock my computer as soon as the "Mat.exe" file is terminated. I'd really appreciate it. Thanks in advance

kotAPI
  • 387
  • 1
  • 7
  • 20

2 Answers2

5

Simply drop the start before Mat.exe so your batch-file will wait until Mat.exe has finished.

Edit: This only works if your Mat.exe runs in a console or similar. If dropping the start didn't work you may have to check wheather or not Mat.exe is still running. For that I found a quite useful post, which should work for you: How to wait for a process to terminate to execute another process in batch file

Edit2: Complete Code:

@echo off
:LOOP
start Mat.exe
TASKLIST 2>&1 | find "Mat.exe" > nul
IF ERRORLEVEL 1 (
  rundll32.exe user32.dll, LockWorkStation
) ELSE (
  SLEEP 3
  GOTO LOOP
)

You can adjust the SLEEP as you like, but i would suggest use at least 1 sec, otherwise you'll have 100% usage.

Community
  • 1
  • 1
Christoph
  • 315
  • 1
  • 5
  • 1
    Not helpful at all, I need to run an OpenGL exe file that I made. I need to lock my computer as soon as it is terminated. How do I even get the exe file to start if I don't use the "start" command? – kotAPI Sep 27 '13 at 11:25
  • Just entering a valid filename is enough to start a programm, the start command opens a new window to run the program in it, so a batch-file won't block it's execution. – Christoph Sep 27 '13 at 11:29
1

Try using the Start command with the /Wait switch. Here is an example:

@echo off 
REM //start Mat.exe
start /wait [path of Mat.exe]
rundll32.exe user32.dll, LockWorkStation

Remember to use the 8.3 filenames and do not include (" ") in the path string

m8L
  • 119
  • 4
  • 9