I am using batch scripting to do basic user functions (add user, delete, change account type etc.) rather than manually do it all. The program asks the user what they would like to do, following options with A, B, C, … G. This part works fine, however, after the user enters in the option, it imminently closes. After checking, the commands following the if statement do not run. How should I fix the if statements?
@echo off
net user
echo What would you like to do?
echo A: Turn off default admin account
echo B: Turn off default guest account
echo C: Add a user
echo D: Remove a user
echo E: Change a users privilages
echo F: Change a password
echo G: Nothing
set /p en = "Enter in the Letter:"
if %en% == "A" (
net user administrator /active:no
echo Built-In Admin Is Turned Off
Pause
)
if %en% == "B" (
net user guest /active:no
echo Guest Account Is Turned Off
Pause
)
if %en% == "C" (
set /p adduser = What is the name of the user you would like to add(Case Sensitive)?
set /p addpassword = What is the password you would like to add to %adduser%?
net user %adduser% %addpassword% /added
echo Added %adduser%
set /p objUser = GetObject(WinNT://MyComputer/%adduser%,user)
%objUser%.PasswordExpired = 1
%objUser%.SetInfo
echo Password Will Need To Be Changed On Next Logon
Pause
if %en% == "D" (
set /p deluser = What is the name of the user you would like to delete(Case Sensitive)?
net user %deluser% /del
echo User %deluser% has been Deleted
The code should be able to run the commands corresponding with the letter, and then stay open until the user is ready to close it. However, it will not run the sequence and closes upon the user entering in a letter to set for variable 'en'.
If it is not out of inconvenience, please explain why your code works in simpler terms. I am fairly new to using batch scripting and still do not understand a vast majority of commands and terms.