RE: Windows MAC address spoofer | V2.0 05-18-2013, 08:06 AM
#8
Yeah, I can help a bit...
1. Replace all goto :end's with exit /b and get rid of :end
2. This isn't needed really:
3. You set arg to nothing, and then never use it after this:
4. There's a better way than this:
Try this for instance:
Same thing applies to other arguments that you check.
5. Avoid naming block sections the same names as your variables:
That can lead to trouble for debugging if you are writing a big script.
ASSOC is a command as well, so you should be a bit more unique than this:
6. Last thing I would say is to validate the invoked script with the arguments by doing an arg count as a minimum, before you decide to use arg %1 for something %2, %3, and when you need %4 it doesn't exist...
edit: As for what @"Deque" pointed out:
You actually don't need type, /f is specific for files too, you just need this:
As for those if statements:
You might be able to check then just shift the arguments. And assign to the same one since shifting is downwards. You aren't dealing with more than 9 arguments though, otherwise I usually create my own pseudo array of arguments...
1. Replace all goto :end's with exit /b and get rid of :end
2. This isn't needed really:
Code:
cd %~dp0
3. You set arg to nothing, and then never use it after this:
Code:
set arg=
4. There's a better way than this:
Code:
set arg1=%1
if /i "%arg1%"=="-help" set arg1=
if defined arg1 goto arg1
Try this for instance:
Code:
@echo off
if [%1] neq [] if "%1" neq "-help" goto :program
:helpdoc
echo Help requested...
pause & exit /b
:program
echo Program started...
pause
Same thing applies to other arguments that you check.
5. Avoid naming block sections the same names as your variables:
Code:
:arg1
That can lead to trouble for debugging if you are writing a big script.
ASSOC is a command as well, so you should be a bit more unique than this:
Code:
:assoc
6. Last thing I would say is to validate the invoked script with the arguments by doing an arg count as a minimum, before you decide to use arg %1 for something %2, %3, and when you need %4 it doesn't exist...
edit: As for what @"Deque" pointed out:
Code:
if exist "con.txt" for /f "delims= tokens=*" %%k in ('type con.txt') do set con=%%k
You actually don't need type, /f is specific for files too, you just need this:
Code:
if exist "con.txt" for /f "tokens=*" %%k in (con.txt) do set con=%%k
As for those if statements:
Code:
if /i "%2"=="-c" set con=%3
if /i "%3"=="-c" set con=%4
if /i "%4"=="-c" set con=%5
if /i "%5"=="-c" set con=%6
if /i "%6"=="-c" set con=%7
You might be able to check then just shift the arguments. And assign to the same one since shifting is downwards. You aren't dealing with more than 9 arguments though, otherwise I usually create my own pseudo array of arguments...
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]