Solved

Adding a homedirectory drive letter in  a batch script

Posted on 2004-09-06
13
3,283 Views
Last Modified: 2008-05-30
I have written a batch script which sets up a bunch of user accounts but have just realised the functionality of the NET USER command is somewhat restrictive in as far as one is unable to specify a network drive letter for the homedirectory. Does anyone know of a utility that includes this functionality?

Thanking you in advance

Saint.
0
Comment
Question by:The__Saint
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
  • +4
13 Comments
 
LVL 57

Expert Comment

by:Pete Long
ID: 11990676
Mapping Drives and Printers From Command

*****Drives*****

These command can be executed from either command line, Batch File OR Login Scripts

This command maps a drive "Z:\" to a shared directory on a server called "Server1"

net use z: \\server1\sharename\

If you need permissions to use this network resource toy can also enter the username and password. (See Security Below)

net use z: \\server1\sharename\ /user:username password

The above commands will work until a user logs out or the machine is rebooted, to make the mapping permanent you need to use a "Persistent switch"

net use z: \\server1\sharename\ /user:username password /Y

*****Printers*****

The Syntax is the same but this time you are mapping an "lpt" port (Line Printer Terminal) All the rules above apply so the full command is,

net use lpt1 \\machinename\sharename\ /user:username password /Y

or

RUNDLL32 PRINTUI.DLL,PrintUIEntry /dn /n\\COMPUTERNAME\PRINTERNAME      // removes printer    
RUNDLL32 PRINTUI.DLL,PrintUIEntry /in /n\\COMPUTERNAME\PRINTERNAME       // adds printer

Zero Administration Kit
http://www.microsoft.com/ntworkstation/downloads/Recommended/Featured/NTZAK.asp

How to Use Con2prt.exe to Connect to a Network Printer
http://support.microsoft.com/?kbid=181663


*****Security*****

If you do need to use  username and password, this has obvious security implications, Consider using NSIS
http://nsis.sourceforge.net/site/Download.6.0.html

For instructions on its use see http://www.experts-exchange.com/Operating_Systems/Win2000/Q_20710867.html
0
 
LVL 104

Expert Comment

by:Sembee
ID: 11991326
If the environment is all Windows XP then you can this with the "set" command - this is built in. I think it is also in Windows 2000, but I had some problems with it.

Set Homedrive=U:\
Set Homepath=\

If it is a mixed environment then you will need the "setx" Resource Kit utility.

If you are using setx don't forget to put the actual exe file in to netlogon share along with the batch file so that the logon script finds it.

Simon.
0
 

Author Comment

by:The__Saint
ID: 11992037
Sorry, I think I need to clarify slightly.
For the record this is an AD environment but the problem I have applies just as much to an NT environment. What I want to change are the properties of a user account, hence the example I used with NET USER. NET USER will change the script path for a user account, the profile path and the local drive path for the homefolder amongst other things. However I am unable to make it select the 'Connect' path and specify a drive letter. NET USER won't allow this but I find it difficult to believe there isn't a utility out there which provides this functionality.
0
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 
LVL 17

Expert Comment

by:jburgaard
ID: 11992189
I guess you are looking for the command: addusers.exe from Windows Resource Kit
http://support.microsoft.com/?kbid=199878
0
 

Author Comment

by:The__Saint
ID: 11992817
This would have been perfect had the user accounts not been already created! The users in question had the accounts themselves created a few months ago in order to use webmail and now they are going live properly. Therefore I need a utility which will manipulate an existing account.
0
 
LVL 7

Expert Comment

by:wparrott
ID: 11993808
While this is not a free tool, it is offered as a 30-day trial:

http://www.tools4ever.com/products/usermanagement/

It will do batch changes to user accounts, which is what you are looking for.

Hope this helps...
0
 

Author Comment

by:The__Saint
ID: 11994849
Cheers but it looks like the lite version is limited to only 5 users at a time and is a little much for what I need. Specifically I would like a command line utility. Sorry to be picky!

Cheers

Simon
0
 

Author Comment

by:The__Saint
ID: 11995086
I have selected all users within the OU I wish to change and changed the drive letter en mass (which I hadn't realised initially I could do). This has fixed my issue. I've still not found a command line utility though.
0
 
LVL 13

Expert Comment

by:hstiles
ID: 11998200
Do you want to set or change the home directory?

Why not just do this using vbscript

I knocked up the followed command file to move home directories for around 150 staff. Scripting it really cuts down on unneccesary errors due to typos/tiredness

rem copyhome.cmd by Hans Stiles
rem Script to copy contents of home directory from SERVERA to SERVERB
rem share new on SERVERB directory, set share and file permissions
rem modify home directory information for the user account
rem and then unshare old directory on SERVERA

@echo off

xcopy \\servera\d$\users\%1 d:\users\%1 /e /v /i /h /k /o /x

net share %1$=d:\users\%1 /grant:%1,CHANGE /grant:"domain admins",FULL

cacls d:\users\%1 /T /E /G %1:C

echo Set oUser = GetObject("WinNT://ourpdc/%1")>c:\movehome.vbs
echo oUser.HomeDirectory = "\\serverb\%1$">>c:\movehome.vbs
echo oUser.SetInfo>>c:\movehome.vbs
echo Set oUser = Nothing>>c:\movehome.vbs
echo strShareName = "%1$">>c:\movehome.vbs
echo Set objfServer = GetObject("WinNT://servera/lanmanserver")>>c:\movehome.vbs
echo objfServer.Delete "Fileshare", strShareName>>c:\movehome.vbs
echo Set objfServer= Nothing>>c:\movehome.vbs

cscript c:\movehome.vbs > NUL

del c:\movehome.vbs

:end

The function oUSer.HomeDirDrive  would be used to manipulate the drive letter.
0
 
LVL 13

Expert Comment

by:hstiles
ID: 11998228
I realise there is more code than you need here, but I thought the entire fiule would give you an idea of how you could create a command file that called a vb script.  I basically dumped a list of all users in to a text file and setup a command file as follows:

copyhome usera
call copyhome userb
call copyhome userc

kicked it off when I got home, went out for the evening, came home, cleared up any errors, claimed a day off in lieu :)

0
 
LVL 84

Accepted Solution

by:
oBdA earned 150 total points
ID: 12000347
Since you've mentioned AD, plus you said you were able to select multiple users, you're running a W2k3 domain.
If you have the W2k Resource Kit, you can use cusrmgr.exe from there to change the drive letter using a command line.
In addition, MS finally came up with some nice AD command line tools in W2k3., that you can use as well.
dsmod.exe user <User-DN> -hmdrv H:
To obtain the user dn (which you probably won't want to type), you can use dsquery:
dsquery.exe user -samid <Username>
These can be combined in a batch script:

@echo off
set User=%1
dsquery.exe user -samid %User% | dsmod.exe -hmdrv H:

The new command-line tools for Active Directory in Windows Server 2003
http://support.microsoft.com/?kbid=298882
0
 

Author Comment

by:The__Saint
ID: 12005194
This is just what I was looking for. I hadn't realised cusrmgr went much further than passwords (should have checked, but you forget about these things) although this must be run on the domain controller. DSMOD in particular looks very useful so thanks and thanks as always to everyone who has contributed.
0
 
LVL 84

Expert Comment

by:oBdA
ID: 12005565
cusrmgr doesn't need to be run on the DC; simply specify a DC's name with the -m switch.
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
A hard and fast method for reducing Active Directory Administrators members.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question