# Batch file to generate password and username to a group of students



## akindulureni (Oct 29, 2012)

Can somebody help me to generate a code that I need to generate username and password to a group of 50 students and also send email to notify them of username and password (in batch file)


----------



## foxidrive (Oct 20, 2012)

Here is a script to send an email. You will need to use it in a command line and pass all the items there. It uses VBS.

The usernames and passwords will have to be in a file called users.txt with a format of
emailaddress1 username password
emailaddress2 username password
emailaddress3 username password
emailaddress4 username password

and no spaces or tabs in the username password

Put your own email address user pass in users.txt on a single line and test that to see if it works and you get the email.

The email details and server name (and course name) will need to be changed in the batch file below.

There is only one line between the parentheses.


```
@echo off
for /f "tokens=1,2,3" %%a in (users.txt) do (
call email-bat [email protected] %%a "Course username and password details for computing101"  "Your username is %%b and your password is %%c - for the course called computing101" mail.server.com [email protected]erver.com mailpassword
)
pause
```


```
::email-bat.cmd:::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal

:: defaults
set [email protected]
set [email protected]
set Subj="email test   %date% %time%"
set Body="did it work? %date% %time%"
set Serv=mail.server.com.au
set Auth=user
set Pass=pass
set fileattach=

:: if command line arguments are supplied then use them
if "%~7" NEQ "" (
set From=%1
set To=%2
set Subj="%~3"
set Body="%~4"
set Serv=%5
set "Auth=%~6"
set "Pass=%~7"
set "fileattach=%~8"
)

call :createVBS "email-bat.vbs"

call :send %From% %To% %Subj% %Body% %Serv% %Auth% %Pass%
echo email sent (if parameters were correct)
pause
del "%vbsfile%" 2>nul
goto :EOF

:send
cscript.exe /nologo "%vbsfile%" %1 %2 %3 %4 %5 %6 %7
goto :EOF

:createVBS
set "vbsfile=%~1"
del "%vbsfile%" 2>nul
set cdoSchema=http://schemas.microsoft.com/cdo/configuration
echo >>"%vbsfile%" Set objArgs       = WScript.Arguments
echo >>"%vbsfile%" Set objEmail      = CreateObject("CDO.Message")
echo >>"%vbsfile%" objEmail.From     = objArgs(0)
echo >>"%vbsfile%" objEmail.To       = objArgs(1)
echo >>"%vbsfile%" objEmail.Subject  = objArgs(2)
echo >>"%vbsfile%" objEmail.Textbody = objArgs(3)
if defined fileattach echo >>"%vbsfile%" objEmail.AddAttachment "%fileattach%"
echo >>"%vbsfile%" with objEmail.Configuration.Fields
echo >>"%vbsfile%"  .Item ("%cdoSchema%/sendusing")        = 2 ' not local, smtp
echo >>"%vbsfile%"  .Item ("%cdoSchema%/smtpserver")       = objArgs(4)
echo >>"%vbsfile%"  .Item ("%cdoSchema%/smtpserverport")   = 25
echo >>"%vbsfile%"  .Item ("%cdoSchema%/smtpauthenticate") = 1 ' cdobasic
echo >>"%vbsfile%"  .Item ("%cdoSchema%/sendusername")     = objArgs(5)
echo >>"%vbsfile%"  .Item ("%cdoSchema%/sendpassword")     = objArgs(6)
echo >>"%vbsfile%"  .Item ("%cdoSchema%/smtpusessl")       = False
echo >>"%vbsfile%"  .Item ("%cdoSchema%/smtpconnectiontimeout") = 30
echo >>"%vbsfile%"  .Update
echo >>"%vbsfile%" end with
echo >>"%vbsfile%" objEmail.Send
```


----------



## akindulureni (Oct 29, 2012)

I want the programme to use the student name as username and their date of birth as password, thanks a lot


----------



## foxidrive (Oct 20, 2012)

Are there spaces in the username?


----------



## akindulureni (Oct 29, 2012)

what I mean is that I want to create 2 text files one with their name and the other with their date of birth. I want to make their names as username and use their date of birth as the passwords, after creating this username and password it will now be sent to their email to notify them of their new username and password. i will really appreciate your help. i am very gratefully for your assistance


----------



## Squashman (Apr 4, 2003)

Why would you have two text files? Just put the Username and Birthday on one line. One line for each user. If you put all the birthdays in another file by themselves you would have no way to match the correct username with the correct birthday.


----------



## akindulureni (Oct 29, 2012)

I still need the code for that. i really appreciate you help


----------



## Squashman (Apr 4, 2003)

akindulureni said:


> I still need the code for that. i really appreciate you help


Foxidrive already gave you the code


----------

