# Add script to clear Chrome upon logoff

This program automatically makes folders to add scripts to be ran once a computer is logged off a user. It checks to make sure it is not overwriting any previous scripts (windows).

:: Author: Brandon Finley
:: Date: 4/20/2017
:: Purpose: This program automatically makes folders to add scripts to be ran once a computer is logged off a user. It checks to make sure it is not overwriting any previous scripts
:: that may have already been created, and then adds the ChromeClear to the list. THIS PROGRAM IS A TOTAL NUKE TO THE CHROME BROWSER; IT WILL DELETE EVERYTHING!

:: If there are no previous scripts added, it needs to create the file locations to use
@ECHO OFF
IF NOT EXIST C:\Windows\System32\GroupPolicy\User MD C:\Windows\System32\GroupPolicy\User
IF NOT EXIST  C:\Windows\System32\GroupPolicy\User\Scripts MD C:\Windows\System32\GroupPolicy\User\Scripts
IF NOT EXIST C:\Windows\System32\GroupPolicy\User\Scripts\Logoff MD C:\Windows\System32\GroupPolicy\User\Scripts\Logoff

:: Writes the new .bat file to clear the browsers
ECHO DEL /q /s /f "%%ChromeDir%%">> C:\Windows\System32\GroupPolicy\User\Scripts\Logoff\ChromeClear.bat
ECHO RD /s /q "%%ChromeDir%%">> C:\Windows\System32\GroupPolicy\User\Scripts\Logoff\ChromeClear.bat

:: If there are no previous scripts.ini initialized it makes the begining of the new file (creates a new scripts.ini if not already there).
IF NOT EXIST "C:\Windows\System32\GroupPolicy\User\Scripts\scripts.ini" @echo:>>C:\Windows\System32\GroupPolicy\User\Scripts\scripts.ini
FOR /f "tokens=3" %%k in ('find /c "Logoff" "C:\Windows\System32\GroupPolicy\User\Scripts\scripts.ini"') do set theLogoff=%%k
IF /I %theLogoff%==0 @echo [Logoff]>> C:\Windows\System32\GroupPolicy\User\Scripts\scripts.ini

:: Writes to the scripts.ini file, and tries to continue the script counter if previous scripts are already added (which is why it doesn't just simply start at 0, but instead counts the scripts).
FOR /f "tokens=3" %%f in ('find /c "CmdLine" "C:\Windows\System32\GroupPolicy\User\Scripts\scripts.ini"') do set isComplete=%%f
ECHO %isComplete%CmdLine=ChromeClear.bat>> C:\Windows\System32\GroupPolicy\User\Scripts\scripts.ini
ECHO %isComplete%Parameters=>> C:\Windows\System32\GroupPolicy\User\Scripts\scripts.ini

:: Deletes the .bat file at it's location.
DEL "%~f0"

• Welcome to StackExchange Code Review! Please review How do I ask a good Question? Specifically, it is best to explain what the code does. This is especially true in the title. It looks like you did this in the comments, but it would be best to transfer that to prose a the beginning on the post. – Stephen Rauch Apr 21 '17 at 16:52
• Seems like extraneous information to just copy and paste what the comments say. Please refer to the comments provided in the script as to what it does. – Brandon Apr 21 '17 at 16:54
• Yes but, note that you are trying to attract peoples attention to your post so that you can get their feedback. The easier you make it for them to see if they are going to be productive in providing feedback, the more likely you will get that feedback. If they have to spend much time determining if they can help they may just move on. – Stephen Rauch Apr 21 '17 at 16:56
• I guess if I don't then I just get people criticizing on the format of the question rather than the question itself. Thanks for the useful insight to this website. – Brandon Apr 21 '17 at 17:02
• @Brandon I have no idea what you are talking about. – t3chb0t Apr 26 '17 at 3:58