Batch File Syntax Problem

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
itecaxuodel
Posts: 3
Joined: 07 Apr 2016 15:00

Batch File Syntax Problem

#1 Post by itecaxuodel » 07 Apr 2016 15:09

Hi i got a little problem with a batch file, the batch file that i created is creating a new account with some setting.
The problem is when i add some settings to the ''NET USER'' command it says syntax error.
The batch file work t'ill i add the ''expires'' or ''passwordchg" commands, i don't know why please help me haha.
Here's the batch file

Code: Select all

@echo off
set /p ajouter=Voulez-vous ajouter un compte ? Tapez Oui ou Non
if %ajouter% ==Oui goto menu
if %ajouter% ==Non goto CCC
:CCC
exit
:menu
set /p nomdecompte= Quel est le nom de compte ?
set /p motdepasse= Quel est le mot de passe ?
set /p actif= Voulez-vous un compte actif ? (Y/N)
if %actif%==Y set variable=yes
if %actif%==N set variable=no
set /p commentaire= Veuillez écrire un commentaire :
set /p expiration= Determinez la date d'expiration du compte (AAAA-MM-JJ)
set jj= %expiration:~8,2%
set MM= %expiration:~5,2%
set aaaa= %expiration:~0,4%
set /p fullname= Veuillez indiquez le nom complet d'utilisateur
set /p changerpass= L'utiliseur peut-il changer le mot de passe ? (Biensur/Pasquestion)
if %changerpass%==Biensur set Motpasse=yes
if %changerpass%==Pasquestion set Motpasse=no
NET USER %nomdecompte% %motdepasse% /add /comment:"%commentaire%" /active:%variable% /expires:%MM%/%jj%/%AAAA% /passwordchg:%Motpasse% 
pause

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch File Syntax Problem

#2 Post by foxidrive » 07 Apr 2016 15:55

The spaces before the == and also those after the = should be removed, as the spaces here are significant and are included.

Code: Select all

if %ajouter% ==Oui goto menu 
if %ajouter% ==Non goto CCC
set jj= %expiration:~8,2%
set MM= %expiration:~5,2%
set aaaa= %expiration:~0,4%

itecaxuodel
Posts: 3
Joined: 07 Apr 2016 15:00

Re: Batch File Syntax Problem

#3 Post by itecaxuodel » 07 Apr 2016 16:11

Oh thank you ! Now it doesn't say Syntax error anymore but i says my format date is not good ?
Is the way i write the date ok ?

/expires:%MM%/%jj%/%AAAA%

Thank you

itecaxuodel
Posts: 3
Joined: 07 Apr 2016 15:00

Re: Batch File Syntax Problem

#4 Post by itecaxuodel » 07 Apr 2016 16:14

Oh i wrote the date on this way : %aaaa%/%MM%/%jj% and i work !!
Thanks a lot !!

Post Reply