Early I wrote about it, and now I want to go back and show you another way how to do it. This way more easly because all you need it just put your PowerShell script in the end of batch file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | @echo off
setlocal
for /f "tokens=1 delims=:" %%i in ('^
findstr /l /b /n /c:"exit /b" "%~dpnx0"') do set "n=%%i"
more +%n% "%~dpnx0">>foo.ps1
powershell /nologo /noprofile /noexit .\foo.ps1
endlocal
exit /b
#PowerShell script begin
function Add-Clock {
$code = {
$reg = '\d{2}:\d{2}:\d{2}'
do {
$now = Get-Date -format 'HH:mm:ss'
$old = [Console]::Title
if ($old -match $pattern) {
$new = $old -replace $pattern, $now
}
else {
$new = "$now $old"
}
[Console]::Title = $new
Start-Sleep -seconds 1
} while ($true)
}
$ps = [PowerShell]::Create()
[void]$ps.AddScript($code)
$ps.BeginInvoke()
}
Add-Clock | Out-Null
Remove-Item .\foo.ps1
|
Hi. This works, but the command prompt window never closes after the script ends.
Any ideas how to solve that?