1.

Solve : net user Error Code?

Answer»

Hi,

I am using batch file to create Users using net USER command. If a user creation fails i like to pop up a message to the user.

How can i do that. i do not know what is the condition to use if.



Thanks Use an IF statement to check the errorlevel variable. If you are doing multiple users and will need to check multiple times, you just have to set up another variable to check against that keeps the running errorlevel seperate from the errorlevel variable. I know that sounds confusing, maybe a demo will help.

Code: [Select]set errorcheck=0
...
net user username password /add

if not "%errorlevel%"=="%errorcheck%" (
set errorcheck=%errorlevel%
echo Error message
PAUSE
)
...

As you can see, the errorcheck variable will always keep the previous errorlevel seperate from the errorlevel variable so you get an accurate READING each time the errorlevel is checked.



Discussion

No Comment Found