Page 1 of 1

Window wont close

Posted: 21 Jul 2011 03:03
by fonzi99
I have the following batch file on a Windows 7 machine and the dos window remains open after I run it.
It opens a registry subkey value (this subkey value contains the path to an .exe; it is called "Location"). It opens the .exe fine but the command window stays open and I have tried everything to close it.
To try it out on your own pc you can change the registry value I have (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\Programpath) to one on your own pc. Also this registry value has to have the subkey "Location".
I would appreciate any help, thanks.

Code: Select all

@echo off
set TESTK=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\Programpath
set TESTV=Location
call :reg_read "%TESTK%" "%TESTV%" "exit" || (echo ERROR: no value found for Location & exit /b 1)


:reg_read <key> <value>
setlocal

set key=%~1
set value=%~2

REM // make one call to reg to make sure the KEY/VALUE exists before reading it
reg query "%key%" /v "%value%" 1>nul 2>&1 || (exit /b 1)


for /f "tokens=2,*" %%a in ('reg query "%key%" /v "%value%" ^| findstr /c:"%value%"') do (
%%b
)




Re: Window wont close

Posted: 21 Jul 2011 03:24
by renzlo
try adding this to the last line of your code:

taskkill /f /im "cmd.exe"

Re: Window wont close

Posted: 21 Jul 2011 03:38
by fonzi99
Thanks for your reply; tried that but it doesn't work.

Re: Window wont close

Posted: 24 Jul 2011 13:41
by orange_batch
Uhm, exit?