Window wont close

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
fonzi99
Posts: 2
Joined: 21 Jul 2011 02:54

Window wont close

#1 Post by fonzi99 » 21 Jul 2011 03:03

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
)




renzlo
Posts: 116
Joined: 03 May 2011 19:06

Re: Window wont close

#2 Post by renzlo » 21 Jul 2011 03:24

try adding this to the last line of your code:

taskkill /f /im "cmd.exe"

fonzi99
Posts: 2
Joined: 21 Jul 2011 02:54

Re: Window wont close

#3 Post by fonzi99 » 21 Jul 2011 03:38

Thanks for your reply; tried that but it doesn't work.

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: Window wont close

#4 Post by orange_batch » 24 Jul 2011 13:41

Uhm, exit?

Post Reply