patternMinor
Windows Batch Tech Tool
Viewed 0 times
techtoolbatchwindows
Problem
I made this to help new techs be more proficient while they are learning. I know most of it is common knowledge around here. I would also like to point out that I don't really know batch but I am learning. Feel free to copy, share or contribute. This should work on XP, Vista, 7, 8, 8.1, and 10 but it's not 100% tested on all versions so some things might not work correctly.
Shortcuts and Kill a Process **REMOVE FOR BODY LIMIT**
Full code can be found here. Updated 12-14-2014
```
@echo off
mode con: cols=86 lines=38
Title = ---- Control Center -----
: Control_Center
color 9F&prompt $v
echo.
echo.
echo Control Center
echo.
echo.
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º º
echo º º
echo º Please Make a Choice By typing the corresponding number... º
echo º º
echo º º
echo º 1. Shortcuts **REMOVE FOR BODY LIMIT** º
echo º 2. Printer Repair º
echo º 3. Internet Repair º
echo º 4. Repair OS º
echo º 5. Kill a Process **REMOVE FOR BODY LIMIT** º
echo º 6. UAC (User Account Controls) º
echo º 7. Activate Admin Account º
echo º 8. S.M.A.R.T Status of Hard Drive (C) º
echo º 9. (F8) Enable legacy mode (Windows 8/8.1 only) º
echo º 10. Reboot to Safe Mode with Networking º
echo º 11. Clean Up after Virus Removal º
echo º 12. E
Shortcuts and Kill a Process **REMOVE FOR BODY LIMIT**
Full code can be found here. Updated 12-14-2014
```
@echo off
mode con: cols=86 lines=38
Title = ---- Control Center -----
: Control_Center
color 9F&prompt $v
echo.
echo.
echo Control Center
echo.
echo.
echo ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
echo º º
echo º º
echo º Please Make a Choice By typing the corresponding number... º
echo º º
echo º º
echo º 1. Shortcuts **REMOVE FOR BODY LIMIT** º
echo º 2. Printer Repair º
echo º 3. Internet Repair º
echo º 4. Repair OS º
echo º 5. Kill a Process **REMOVE FOR BODY LIMIT** º
echo º 6. UAC (User Account Controls) º
echo º 7. Activate Admin Account º
echo º 8. S.M.A.R.T Status of Hard Drive (C) º
echo º 9. (F8) Enable legacy mode (Windows 8/8.1 only) º
echo º 10. Reboot to Safe Mode with Networking º
echo º 11. Clean Up after Virus Removal º
echo º 12. E
Solution
Wow! You put a lot of work into this. Thank you for sharing. I have some suggestions for you to consider.
-
Add
-
Get into the habit whenever you set a variable to a string, to
As a pleasant side effect, employing this advice with
-
That's a nice thought that you're using braces around each item in some of your
-
Instead of
-
While we're on the subject of
Try this:
... etc. The way that works is, if this script is run on an XP box, "Version 5." gets replaced by nothing, so the original
Using the batch language's internal processing is usually faster than calling an executable (unless you're trying to replace
-
Search and replace
-
Remove the trailing period from
-
Since many of the actions offered by this script require elevation to admin privilege, consider having your script prompt for elevation if needed.
Otherwise, the blood, sweat, and tears you have devoted to this project are obvious. I can see this script being useful for many people. Well done, Bobby!
-
Add
setlocal to the top of your script. This script uses a lot of variables. After you exit, they're still hanging around, junking up your environment, potentially causing problems for other scripts that expect those variables not to be defined. Adding setlocal just below @echo off will narrow the scope of those variables to this script, and the variables will be forgotten on exit (whether the script exits gracefully or not).-
Get into the habit whenever you set a variable to a string, to
set "var=value" with the var + value pair enclosed in quotation marks. One of these days you may need to capture special characters like & or |, or some XML or HTML to a variable. If you set "var=" you don't have to worry about those special characters getting evaluated unintentionally. Get this habit under your fingers now and you will spend much less time in the future debugging.As a pleasant side effect, employing this advice with
set /P "var=Enter a choice: " allows you to echo a trailing space after your prompt, which makes text entry a little nicer for the user than your (perhaps overly generous) use of ellipses.-
That's a nice thought that you're using braces around each item in some of your
if statements, but not terribly effective. If the variable you're testing includes a space, your script will crash. Use quotation marks instead. if "%option%"=="1" for example.-
Instead of
if %ERRORLEVEL% equ 0 consider using conditional execution with the && and || operators. For example: ver | find "5.0." > nul && goto ver5x.-
While we're on the subject of
ver | find (or findstr as the case may be), you know you're executing that up to 8 times in a few of your subroutines. A more efficient method would be to set a variable to ver once, then test for substring matches using string substitution.Try this:
for /f "delims=" %%I in ('ver') do set "ver=%%I"
if "%ver%" neq "%ver:Version 5.=%" goto ver5x
if "%ver%" neq "%ver:Version 6.=%" goto ver6x... etc. The way that works is, if this script is run on an XP box, "Version 5." gets replaced by nothing, so the original
%ver% no longer equals the manipulated %ver%; and thus, goto is fired. But on Vista, since %ver% doesn't contain "Version 5.", there's nothing to replace. "%ver%" equ "%ver%", and the script continues to the next line.Using the batch language's internal processing is usually faster than calling an executable (unless you're trying to replace
sed with a hive of nested for loops or similar, but I digress). Even if the difference is only a couple hundred milliseconds, efficiency is rarely a bad thing.-
Search and replace
%choice% with %option%. Looks like you changed your mind about the variable name, but didn't get it updated everywhere it needed to be.-
Remove the trailing period from
%windir%\ie8\spuninst\spuninst.exe.-
Since many of the actions offered by this script require elevation to admin privilege, consider having your script prompt for elevation if needed.
Otherwise, the blood, sweat, and tears you have devoted to this project are obvious. I can see this script being useful for many people. Well done, Bobby!
Code Snippets
for /f "delims=" %%I in ('ver') do set "ver=%%I"
if "%ver%" neq "%ver:Version 5.=%" goto ver5x
if "%ver%" neq "%ver:Version 6.=%" goto ver6xContext
StackExchange Code Review Q#71949, answer score: 6
Revisions (0)
No revisions yet.