-
January 14th, 2004, 11:13 PM
#1
Junior Member
Help, Batch files WinXP
This is not a tutorial, but a question in need of an answer.
I am creating a batch file for creating user names and passwords for an apache website. If you are familar with apache then you know about the password utility that ecrypts the password part of the file.
Anyways, My problem is that before creating/adding the new user the batch file checks for to original file that is on a network folder. I will be add source code but be warned that it is real messy. I havent cleaned it up yet.
@ECHO on
title Create Password Utility
CLS
:Check1
REM Check for Primary User file
pause
IF EXIST \\yada\drive (d)\yada\Restricted\usr\yada\passwords goto copylocal
IF NOT EXIST \\yada\drive (d)\yada\Restricted\usr\yada\passwords GOTO username
:copylocal
REM Copy passwords file from server
copy \\yada\drive (d)\yada\Restricted\usr\yada\passwords passwords
REM Above here note that i didnt specify the location for the copied passwords because
REM This batch file may move am i want the copy in the same folder as it
pause
:username
ECHO/
ECHO/
ECHO/
:: SET /P prompts for input and sets the variable
:: to whatever the user types
SET Choice=
SET /P username=Type User name To be created:
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%username%'=='' SET Choice=%Choice:~0,1%
ECHO.
ECHO "%username%" is The user namer.
ECHO.
GOTO password
assword
ECHO/
ECHO/
ECHO/
:: SET /P prompts for input and sets the variable
:: to whatever the user types
SET Choice=
SET /P password=Type password To be created:
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%password%'=='' SET Choice=%Choice:~0,1%
ECHO.
ECHO "%password%" is The user namer.
ECHO.
GOTO display
ECHO
ECHO
ECHO
ECHO
:display
CLS
ECHO/
ECHO/
ECHO/
ECHO File Name: passwd.txt
ECHO File Name: %username%
ECHO File Name: %password%
Pause
IF EXIST H:\work\websites\passwords GOTO addtofile
IF NOT EXIST H:\work\websites\passwords GOTO createfile
:createfile
CLS
echo Creating password files passwords & passwd.txt
echo/
echo please wait.
rem Creates two password files
htpasswd.exe -bc passwords %username% %password%
htpasswd.exe -bcp passwd.txt %username% %password%
xcopy passwords \\yada\drive (d)\yada\Restricted\usr\yada\passwords
echo/
echo/
echo Remember to add users to the members list.
pause
edit "\\yada\drive (d)\yada\Restricted\usr\yada\groups"
pause
goto end
:addtofile
CLS
echo Creating password file passwd.txt
echo/
echo please wait.
rem Creates two password files
htpasswd.exe -b passwords %username% %password%
htpasswd.exe -bp passwd.txt %username% %password%
xcopy passwords \\yada\drive (d)\yada\Restricted\usr\yada\passwords
echo/
echo/
echo Remember to add users to the members list.
pause
edit "\\yada\drive (d)\yada\Restricted\usr\yada\groups"
:End
CLS
Also note that i am creating a local file for backup and later editing/viewing
Anyways the problem is with " If exist " it does not want to take my network address. it works fine if i run/open a file but it wont work with " if exist ".
Any help would be appreciated!
If i have said it once I have said it a thousand times!
My computer is a CURSE!
-
January 20th, 2004, 02:26 AM
#2
Junior Member
If anyone cares
Well I figured it out on my own.
I the case that anyone cares what i did to get it working here is the code.
This has been tested in XP pro ONLY!
@ECHO off
title Create Password Utility
CLS
:Check1
REM Check for Primary User file
ECHO/
ECHO/
ECHO/
echo Checking for profiles and groups file..
IF EXIST Z:\Websit~1\Restri~1\usr\sonicd~1\passwords goto copylocal
IF NOT EXIST Z:\Websit~1\Restri~1\usr\sonicd~1\passwords GOTO FilenotFound
:copylocal
REM Copy passwords file from server
copy Z:\Websit~1\Restri~1\usr\sonicd~1\passwords passwords
goto username
:FilenotFound
CLS
echo/
echo/
echo Warning Users file NOT FOUND!
echo Files my be over written..
echo/
ECHO C. To continue
ECHO Q. Quit
echo/
SET Choice=
SET /P continue=Type the letter and press Enter:
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%continue%'=='' SET Choice=%Choice:~0,1%
IF /I '%continue%'=='C' GOTO username
IF /I '%continue%'=='Q' GOTO end
IF /I '%continue%'=='quit' GOTO end
IF /I '%continue%'=='exit' GOTO end
ECHO "%continue%" is not valid. Please try again.
GOTO FilenotFound
:username
ECHO/
ECHO/
ECHO/
:: SET /P prompts for input and sets the variable
:: to whatever the user types
SET Choice=
SET /P username=Type User name To be created:
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%username%'=='' SET Choice=%Choice:~0,1%
IF /I '%username%'=='Q' GOTO end
IF /I '%username%'=='quit' GOTO end
IF /I '%username%'=='exit' GOTO end
:password
ECHO/
ECHO/
ECHO/
:: SET /P prompts for input and sets the variable
:: to whatever the user types
SET Choice=
SET /P password=Type password To be created:
:: The syntax in the next line extracts the substring
:: starting at 0 (the beginning) and 1 character long
IF NOT '%password%'=='' SET Choice=%Choice:~0,1%
IF /I '%password%'=='Q' GOTO end
IF /I '%password%'=='quit' GOTO end
IF /I '%password%'=='exit' GOTO end
GOTO display
:display
CLS
ECHO/
ECHO/
ECHO/
ECHO UserName: %username%
ECHO Password: %password%
ECHO File Name: passwd.txt
ECHO/
ECHO/
echo Please check that the above information is correct.
Pause
IF EXIST H:\work\websit~1\passwords GOTO addtofile
IF NOT EXIST H:\work\websit~1\passwords GOTO createfile
:createfile
ECHO/
ECHO/
CLS
echo Creating user profile for %username%
echo/
echo please wait.
rem Creates two password files
htpasswd.exe -bc passwords %username% %password%
htpasswd.exe -bcp passwd.txt %username% %password%
xcopy /Y passwords Z:\Websit~1\Restri~1\usr\sonicd~1
CLS
echo/
echo/
echo Please add %username% to the groups file.
pause
edit Z:\Websit~1\Restri~1\usr\sonicd~1\groups
pause
goto end
:addtofile
CLS
echo/
echo/
echo Creating password file passwd.txt
echo/
echo please wait.
rem Creates two password files
htpasswd.exe -b passwords %username% %password%
htpasswd.exe -bp passwd.txt %username% %password%
xcopy /Y passwords Z:\Websit~1\Restri~1\usr\sonicd~1
CLS
echo/
echo/
echo Remember to add users to the members list.
pause
edit Z:\Websit~1\Restri~1\usr\sonicd~1\groups
IF EXIST passwords del passwords
IF EXIST passwd.txt del passwd.txt
CLS
echo/
echo/
echo Successfully add %username% to the user database.
pause
goto end
:errorNoFile
CLS
echo/
echo/
echo User profile and group files NOT FOUND!
pause
:End
This batch file will work for the apache file htpasswd.exe for adding user names to a web server. I ended up creating a network drive and using the drive letter to access the files and folders I needed. Thanks for all the help I didn't get!
If i have said it once I have said it a thousand times!
My computer is a CURSE!
-
January 20th, 2004, 02:32 AM
#3
I've deleted your duplicate thread. Please do not use the Tutorials forums for posting questions as it's meant for members to post original Tutorials.
This -- however -- is a good place for this question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|