Unix/Linux Go Back    


Windows & DOS: Issues & Discussions All Windows and DOS questions should go here as well. Discuss UNIX to Windows (Desktop or Server) here!

Problems With User Creation Script

Windows & DOS: Issues & Discussions


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-07-2013   -   Original Discussion by charlieabee
charlieabee charlieabee is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 7 January 2013, 9:42 PM EST
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Problems With User Creation Script

Hello everyone,

I've been attempting to make a program which creates user accounts from a file which contains the usernames required. It also checks if the directory of the username exists in the C:\Users directory and then is going to give the option to delete the directory, or rename it, this is the code I have so far (not finished, using echo's for test purposes):

Code:
@ECHO OFF
GOTO USERADD

:USERADD 
	FOR /F %%i IN (C:\Users\Charlie\Documents\Usernames.txt) DO IF EXIST C:\Users\%%i (
											    SET /P deleteorkeep="This username %%i already exists, press d to delete the account and files, press k to delete the account but rename the files folder with a suffix of _old:" 
										            
											    IF /i "%deleteorkeep:~,1%" EQU "d" (
											     	ECHO delete
											   )

											    IF /i "%deleteorkeep:~,1%" EQU "k" (
												ECHO keep
											   ) ELSE (
											      NET USER %%i %%i /add
											   )
)

The problem I'm having is that when I type either 'k' or 'd' the echo output is often incorrect (the script echo's keep, when I've pressed d). I have no idea what the problem is as I'm relatively new to batch scripting, so I need someone's help!

Thanks in advance
Sponsored Links
    #2  
Old Unix and Linux 01-28-2013   -   Original Discussion by charlieabee
Hammadi dali Hammadi dali is offline
Registered User
 
Join Date: Feb 2009
Last Activity: 4 April 2014, 11:47 AM EDT
Location: Tunisia
Posts: 48
Thanks: 0
Thanked 1 Time in 1 Post
it is a problem of parenthesis positionning :

Code:
@echo off
 SET /P deleteorkeep="This username %%i already exists, press d to delete the account and files, press k to delete the account but rename the files folder with a suffix of _old:" 
IF /i "%deleteorkeep:~,1%" EQU "d" (      ECHO delete    )
   IF /i "%deleteorkeep:~,1%" EQU "k" (   ECHO keep     
   ) ELSE (     
   NET USER %%i %%i /add     )

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Bash shell script for user creation in solaris sintilash Shell Programming and Scripting 1 08-02-2012 01:32 PM
Can we Automate the User creation and setting password through a script in solaris 10 muraliinfy04 UNIX for Advanced & Expert Users 1 06-15-2012 12:55 PM
User creation script indrajit_renu Shell Programming and Scripting 1 10-17-2010 08:30 PM
user creation using shell script for JSP jarkvarma Shell Programming and Scripting 1 11-04-2001 12:27 PM



All times are GMT -4. The time now is 01:00 AM.