Articles

Can someone please check this batch file:

January 8, 2013 at 09:44:23
Specs: Windows 7

Place.bat
@echo off
GOTO Ziggie

:Ziggie
IF NO EXIST C:\Users\Ziggie THEN (GOTO Error1)
IF EXIST C:\Program Files (x86) THEN (MKDIR Program Files (x43)) ELSE (MKDIR Program Files (x86))
IF EXIST C:\Program Files (x86) THEN (XCOPY "C:\Users\Ziggie\Desktop\Program Files (x43)" "C:\") ELSE (XCOPY "C:\Users\Ziggie\Desktop\Program Files (x86)" "C:")
IF EXIST C:\Program Files (x43) THEN (XCOPY "C:\Users\Ziggie\Desktop\Computer Security2" "C:\Program Files (x43)") ELSE (XCOPY "C:\Users\Ziggie\Desktop\Computer Security2" "C:\Program Files (x86)")
IF EXIST C:\Program Files (x43) THEN (XCOPY "C:\Program Files (x43)\Computer Security2\Change Password.bat" "C:\Users\Ziggie\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup") ELSE (XCOPY "C:\Program Files (x86)\Computer Security2\Change Password.bat" "C:\Users\Ziggie\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup")
START C:\Users\Ziggie\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\Change Password.bat
IF EXIST C:\Users\Ziggie\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\Change Password.bat THEN (ECHO Files transferred to Ziggie Successful.) ELSE (ECHO Transfer to Ziggie Unsuccessful.)
GOTO Gonzales

:Gonzales
IF NO EXIST C:\Users\Gonzales THEN (GOTO Error1)
IF EXIST C:\Program Files (x86) THEN (MKDIR Program Files (x43)) ELSE (MKDIR Program Files (x86))
IF EXIST C:\Program Files (x86) THEN (XCOPY "C:\Users\Gonzales\Desktop\Program Files (x43)" "C:\") ELSE (XCOPY "C:\Users\Gonzales\Desktop\Program Files (x86)" "C:")
IF EXIST C:\Program Files (x43) THEN (XCOPY "C:\Users\Gonzales\Desktop\Computer Security2" "C:\Program Files (x43)") ELSE (XCOPY "C:\Users\Gonzales\Desktop\Computer Security2" "C:\Program Files (x86)")
IF EXIST C:\Program Files (x43) THEN (XCOPY "C:\Program Files (x43)\Computer Security2\Change Password.bat" "C:\Users\Gonzales\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup") ELSE (XCOPY "C:\Program Files (x86)\Computer Security2\Change Password.bat" "C:\Users\Gonzales\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup")
START C:\Users\Gonzales\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\Change Password.bat
IF EXIST C:\Users\Gonzales\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\Change Password.bat THEN (ECHO Files transferred to Gonzales Successful.) ELSE (ECHO Transfer to Gonzales Unsuccessful.)
GOTO End

:Error1
ECHO C:\Users\Ziggie does not exist.
PAUSE
EXIT

:Error2
ECHO C:\Users\Gonzales does not exist.
PAUSE
EXIT

:END
IF EXIST C:\Users\Ziggie\Desktop\Program Files (x43) THEN (DEL C:\Users\Ziggie\Desktop\Program Files (x43))
IF EXIST C:\Users\Ziggie\Desktop\Program Files (x86) THEN (DEL C:\Users\Ziggie\Desktop\Program Files (x86))
IF EXIST C:\Users\Ziggie\Desktop\Computer Security2 THEN (DEL C:\Users\Ziggie\Desktop\Computer Security2)
IF EXIST C:\Users\Gonzales\Desktop\Program Files (x43) THEN (DEL C:\Users\Gonzales\Desktop\Program Files (x43))
IF EXIST C:\Users\Gonzales\Desktop\Program Files (x86) THEN (DEL C:\Users\Gonzales\Desktop\Program Files (x86))
IF EXIST C:\Users\Gonzales\Desktop\Computer Security2 THEN (DEL C:\Users\Gonzales\Desktop\Computer Security2)
IF EXIST C:\Users\Ziggie THEN Rename "Place.bat" "SecPlace.bat"
IF EXIST C:\Users\Ziggie THEN XCOPY "C:\Users\Ziggie\Desktop\SecPlace.bat" "C:"
IF EXIST C:\Users\Gonzales THEN Rename "Place.bat" "SecPlace.bat"
IF EXIST C:\Users\Gonzales THEN XCOPY "C:\Users\Gonzales\Desktop\SecPlace.bat" "C:"
EXIT


See More: Can someone please check this batch file:

Report •


#1
January 8, 2013 at 09:47:22

By the way, if anyone needs any help with batch files, I have a .pdf document to help you guys a little, and I know a lot myself. I can write some for you too. For more information or help please contact me at Facebook.com\<removed> or at <removed>@gmail.com.

edited by moderator: Removed email address & FB info -Razor2.3


Report •

#2
January 8, 2013 at 11:28:17

What were you hoping to have someone check? On another note, you probably haven't gotten many responses because you posted to your own question.

I can see the first line IF NO should maybe be IF NOT.

:: mike


Report •

#3
January 8, 2013 at 14:56:46

Bet you get a stack of junk email - that address is all over the internet.

Always pop back and let us know the outcome - thanks


Report •

Related Solutions

#4
January 8, 2013 at 19:49:07

Well, to me, there is a lot of redundant code that could be handled more efficiently. Being simple myself, I like things simple, but that's just me. fwiw, here's my "rebuild":

:: begin batchscript
@echo off & setlocal
set toolong=appdata\roaming\microsoft\windows\start menu\programs\startup
:: I'm guessing here, that you only want to "process"/validate one of two potential users
if /i %username% neq ziggie if %username% neq gonzales goto :eof

:main
set src=program files (x86)
:: might need fully qualified path here... then add c:\%userprofile%\ or whatever
if exist "%src%" then set src=program files (x43)
md "%src%"
set locn="%userprofile%\desktop"
xcopy "%locn%\%src%" c:\
xcopy "%locn%\computer security2" "c:\%src%"
xcopy "c:\%src%\computer security2\change password.bat" "%userprofile%\%toolong%"
start "%userprofile%\%toolong%\change password.bat"
:: not sure about how this validates, but here goes
if not exist "%userprofile%\%toolong%\change password.bat" set un=UN
echo File transfer to %username% was %un%successful
:: might need to branch to either "end" or "eof" dep on success, don't know.
if defined %un% (goto :eof) else (goto :end)
goto :eof

:error1
:: this should never happen...
echo c:\users\%username% does not exist
goto :eof

:end
:: a lot of "if exists" can be eliminated by just doing the RD, sending "does not exist" out into limbo (nul)
rd /s /q "%locn%\%src%" 2>nul
rd /s /q "%locn%\computer security2" 2>nul
ren "%userprofile%\place.bat" secplace.bat
copy "%userprofile%\secplace.bat" c:\
::===== end batch script
Since I don't really know the details of what you want, I had to guess a lot. This compressed version may not be to your liking anyhooos.


Report •

#5
January 9, 2013 at 01:01:03

10 points to nbrane for effort.
I got as far as the 2nd line. No point in a GOTO that goes to the next line. [That's where it's headed anyway.]

=====================
M2 Golden-Triangle


Report •

#6
January 9, 2013 at 06:12:59

I'm still trying to figure out what CPU architecture is called "x43," and how it can exist along a PC capable of running the x86 instruction set.

How To Ask Questions The Smart Way


Report •

#7
January 9, 2013 at 19:04:20

@Dizzyizzy - By the way, if anyone needs any help with batch files, I have a .pdf document to help you guys a little, and I know a lot myself. I can write some for you too.

Post the pdf doc or a link to it, I may need a bit of help shortly.

Thanks.


Please come back & tell us if your problem is resolved.


Report •


Ask Question