Simple batch file, CLS causes slowness and flickering???

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
InfoH
Posts: 2
Joined: 12 Jun 2013 06:12

Simple batch file, CLS causes slowness and flickering???

#1 Post by InfoH » 12 Jun 2013 06:20

So heres the file I made, its a bit simple and probably much easier ways to get the same result.. it basically creates a VBS file which fixes an issue in the registry

However when I run the batch file and press enter for it to start.. everytime the screen clears (cls) to add another dot to my progress bar thingy it causes the screen to flash rather annoyingly so its hard to understand whats happening.. i'd like this to be almost seemless, however still want to keep the delays between the dots..

any ideas??

Code: Select all

@ECHO OFF
Title Active Desktop Recovery Fix
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
pause
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
echo [#1] Generating script file.
PING localhost -n 1 -w 1000 > nul
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
echo [#1] Generating script file..
PING localhost -n 1 -w 1000 > nul
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
echo [#1] Generating script file...
PING localhost -n 1 -w 1000 > nul
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
echo [#1] Generating script file....
PING localhost -n 1 > nul
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
echo [#1] Generating script file................ Complete
PING localhost -n 1 -w 1000 > nul
echo HKEY_CURRENT_USER = ^&H80000001 >> ADRF.vbs
echo strComputer = "." >> ADRF.vbs
echo Set objReg = GetObject("winmgmts:\\" ^& strComputer ^& "\root\default:StdRegProv") >> ADRF.vbs
echo strKeyPath = "Software\Microsoft\Internet Explorer\desktop\SafeMode\Components" >> ADRF.vbs
echo strValue = "0" >> ADRF.vbs
echo ValueName = "DeskHtmlVersion" >> ADRF.vbs
echo objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue >> ADRF.vbs
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
echo [#1] Generating script file................ Complete
echo [#2] Executing created script.
PING localhost -n 1 -w 500 > nul
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
echo [#1] Generating script file................ Complete
echo [#2] Executing created script..
PING localhost -n 1 -w 500 > nul
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
echo [#1] Generating script file................ Complete
echo [#2] Executing created script...
PING localhost -n 1 -w 500 > nul
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
echo [#1] Generating script file................ Complete
echo [#2] Executing created script....
PING localhost -n 1 -w 500 > nul
ADRF.vbs
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
echo [#1] Generating script file................ Complete
echo [#2] Executing created script.............. Complete
PING localhost -n 1 -w 500 > nul
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
echo [#1] Generating script file................ Complete
echo [#2] Executing created script.............. Complete
echo [#3] Refreshing desktop.
PING localhost -n 1 -w 500 > nul
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
echo [#1] Generating script file................ Complete
echo [#2] Executing created script.............. Complete
echo [#3] Refreshing desktop..
PING localhost -n 1 -w 500 > nul
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
echo [#1] Generating script file................ Complete
echo [#2] Executing created script.............. Complete
echo [#3] Refreshing desktop...
PING localhost -n 1 -w 500 > nul
RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
DEL /F /Q ADRF.vbs
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
echo [#1] Generating script file................ Complete
echo [#2] Executing created script.............. Complete
echo [#3] Refreshing desktop....
PING localhost -n 1 -w 500 > nul
cls
echo.
echo.
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris 
echo.
echo.
echo [#1] Generating script file................ Complete
echo [#2] Executing created script.............. Complete
echo [#3] Refreshing desktop.................... Complete
PING localhost -n 1 -w 500 > nul
echo.
echo.
Pause

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Simple batch file, CLS causes slowness and flickering???

#2 Post by Squashman » 12 Jun 2013 08:09

Why bother doing all that. If I caused delays in my batch files that I write for my department they would hang me!

InfoH
Posts: 2
Joined: 12 Jun 2013 06:12

Re: Simple batch file, CLS causes slowness and flickering???

#3 Post by InfoH » 13 Jun 2013 05:49

I'm not really writing it for them, its more just a little thing i'm doing on the side to help me learn batch scripting
thought i'd make something useful, I know I can just strip it all out to just creat the vbs, run, delete and refresh with no messages but I like to make it look pretty :) lol

plus I kinda wanna learn which bit of it is causing the lag so I can overcome similar issues in the future

jeb
Expert
Posts: 1062
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Simple batch file, CLS causes slowness and flickering???

#4 Post by jeb » 13 Jun 2013 11:07

Your code is a bit redundant, or in other words:
You should use some functions.

And to avoid flickering, try to avoid CLS at all.
Better only append the dots to the current line.
To echo something without a linefeed you can use

Code: Select all

<nul set /p "=My text without linefeed"


Your complete code could look like.

Code: Select all

@ECHO OFF
Title Active Desktop Recovery Fix
cls
echo(
echo(
echo    [ Active Desktop Recovery ]
echo      -----------------------
echo          By Chris Harris
echo(
echo(
call :waitForKey
<nul set /p "=[#1] Generating script file."
call :ProgressWait 16
(
   echo HKEY_CURRENT_USER = ^&H80000001
   echo strComputer = "."
   echo Set objReg = GetObject("winmgmts:\\" ^& strComputer ^& "\root\default:StdRegProv"^)
   echo strKeyPath = "Software\Microsoft\Internet Explorer\desktop\SafeMode\Components"
   echo strValue = "0"
   echo ValueName = "DeskHtmlVersion"
   echo objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, ValueName, strValue
) > ADRF.vbs
echo Complete

<nul set /p "=[#2] Executing created script."
call :ProgressWait 14
echo Complete

<nul set /p "=[#3] Refreshing desktop."
call :ProgressWait 20
rem RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters
rem DEL /F /Q ADRF.vbs
echo Complete
call :waitForKey

exit /b
:WaitForKey
<nul set /p "=Press a key"
pause > nul
echo(
exit /b

:ProgressWait
for /L %%n in (1 1 %1) do (
   PING localhost -n 1 -w 500 > nul
   <nul set /p "=."
)
exit /b

Post Reply