Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch or script to add a new share on NT server

Status
Not open for further replies.

brent01

Technical User
Jul 11, 2001
32
GB
Please, please help!

When a new user start in our company I have to create a new share for that user plus three sub folders, that are always the same name.

I am looking for a way to use NT commands from the command prompt and hopefully create some kind of batch script to semi-automate the process.

At present for a new user for example James Bond, I will user Server Manager to select the server HTMOA2, and add a new share with, in this case, the following details -

Share Name = Bond$
Path = d:\users\Bond
Comment = James Bond

Is there any way of writing a batch script, that prompts the user to enter a share name, path, and comment, and then go away and set the share up as above.
For setting up one user, this won't save a great deal of time, but when setting up a number of users, it would be a great help. Also this I hope could be just part of a longer script, to automate the other steps carried out when setting up a user.

Any help would be most appreciated.

Thanks
Brent
 
You could use the NET SHARE command to share the directory.

NET SHARE BOND$=D:\USERS\BOND /REMARK:"James Bond"

The part about the batch script where the users enters the share name is a bit tricky. How much rights has the user to the "d:\users" directory ? Should they really be allowed to create their own shares on a server ?

 
Thanks for the reply SusieGirl. I am sure thanks to you, I'm a step forward already, but just to clarify. I have admin rights, so it's me that always creates the users initial folders and share. Basically, when a new user starts work for the company, and his NTid is assigned (not created on NT, at this point) The fisrt task is to create a share in the d:\users directory, that will effectively be that user home (h:) drive, for their own work. Rather than have to use the NT gui interface, I would like to create a script, let's call it Addusers.

When I enter the batch command Addusers I would like a prompt something like -

What share name do you want? (my input - bond$)
What is the path for the share ? (my input - d:\users\bond)
What is the users Full Name? (my input - James Bond)

with these variable created, I would like the batch script to then create the share, rather than having to use Server Manager, to add the share.

The three questions that the batch script would ask (as above) are effectively the three fields you complete when using Server Manager to add a share.

Does the NET SHARE command only share a directory, rather than create it as well? Should I map to \\HTMOA2\d$, and the use command MKDIR \users\BOND to create the folder, then use the command
NET SHARE BOND$=D:\USERS\BOND /REMARK:"James Bond" to actually share the folder? is the /REMARK the equivalent of the comments field in the 'Add a New Share dialogue box, in Server Manager?

I hope nobody's is too confused!

Sorry for the long post and for sounding stupid, but I am pretty new to NT, from an admin side of things, and know hardly anything about using NT commands from the command line. Unix, MPE/iX, and even old DOS, I'm fine with but NT from the command line?? Help!

Any more help would be fantastic.

Thanks
Brent (Levi Strauss (UK))
 
Why not use Home Directories?

In user manager under user properties and then profile, choose connect then a drive letter, then enter a sharename e.g. \\servername\users\%username% then this will create a directory with the name of the user with the correct rights on it.

Sorry to veer off topic, but do you know a guy called Simon Mason at Levi?
 
Here's what I did. NOt too pretty but worked and saved me some time.

Ran the showmbrs tool to list the members of my group. I then copied that list into a batch file that would make the dirs....ie
md e:\users\ARLENEJ
md e:\users\BILLF
md e:\users\BILLH
md e:\users\BLESGUEST
md e:\users\BLESGUEST2

Then I ran a batch file based on the net share command.

net share ARLENEJ$=E:\users\arlenej
net share BILLF$=E:\users\billf
net share BILLH$=E:\users\billh
net share BLESGUEST$=E:\users\blesguest
net share BLESGUEST2$=E:\users\blesguest2
net share BOBC$=E:\users\bobc

Worked fine for me. Alot of replacing and editing of the batch file, but, again, it worked for me.
 
Hi,

The net share command only shares, it does not create a directory. So first of all you'd need to create the directory structure. You could do it as follows with a batch file:

md d:\users\%1
md d:\users\%1\subfolder1
md d:\users\%1\subfolder2
md d:\users\%1\subfolder3
net share %1=d:\users\%1 /remark:%2

In this instance %1=username or name of folder %2=full name
So you'd use it as follows:

adduser smithj "Jack Smith"

If you wanted to create an NT domain account at the same time, you'd use net user, example below:

net user /domain %1 /add

And you may need/want to give the user permissions to their home directories with the cacls command, example below:

cacls d:\users\%1 /t /e /g %1:c

am not entire sure if this would work correctly, probably worth a test first.

hope this helps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top