Home > Enterprise Desktop Tips > > One script creates directory, permissions
Enterprise Desktop Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 


One script creates directory, permissions


Hans Schefske, Contributor
02.23.2005
Rating: -3.86- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Please let us know how useful you find this tip by rating it below. Do you have a useful Windows tip, timesaver or workaround to share? Submit it to our tip contest and you could win a prize!


This sample script shows you how to create a user and with a home directory, and also sets the necessary permissions on that directory.

The script creates a user and adds additional properties such as telephone number and title, sets the password and enables the user's account. It also creates the user's home folder, sets administrators to have "full" control and the user to have "change" control on the folder. If you view the command line switches for CACLS.EXE and make the appropriate changes in the script, you can easily modify the script to the set permissions to fit the requirements of any environment.

Copy and paste the following script into Notepad (make sure you have Word Wrap disabled) and then save it with a .vbs extension:.

================================================
Option Explicit

Const WAIT_ON_RETURN = True
Const HIDE_WINDOW = 0
Const USER_ROOT_UNC = "\\dc1\users" 'Set Home Folder Location Here

Dim WshShell, WshNetwork, objFS, objServer, objShare

Set WshShell = Wscript.CreateObject("Wscript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objFS = CreateObject("Scripting.FileSystemObject")
Set ou = GetObject("LDAP://OU=Users,OU=Billing,OU=Network,DC=my,DC=domain,DC=com")

'Create the User
Set usr = ou.Create("user", "CN=James Smith")
usr.Put "samAccountName", "jsmith"
usr.Put "sn", "Smith"
usr.Put "givenName", "James"
usr.Put "userPrincipalName", "jsmith@my.domain.com"
usr.Put "telephoneNumber", "(555) 555 0111"
usr.Put "title", "Network Billing Dept"
usr.SetInfo

Now that you created the user, reset the user's password and enable the account. usr.SetPassword "secret***!" usr.AccountDisabled = False usr.SetInfo

Now create the user's home folder and set permissions. strUser = usr.samAccountName Call objFS.CreateFolder(USER_ROOT_UNC & "\" & strUser) Call WshShell.Run("cacls " & USER_ROOT_UNC & "\" & strUser & _ " /e /g Administrators:F", HIDE_WINDOW, WAIT_ON_RETURN) Call WshShell.Run("cacls " & USER_ROOT_UNC & "\" & strUser & _ " /e /g " & strUser & ":C", HIDE_WINDOW, WAIT_ON_RETURN) ====================================================

NOTE: Make sure you have the latest scripting engines on the workstation you run this script from. You can download the latest scripting engines here: Microsoft Scripting Home Page

In addition, when working with the Active Directory Services Interface (ADSI), you must have the same applicable rights, as you would use the built-in administrative tools.

Editor's Note: If you would like to receive similar tips on how to manage Windows as well as other expert advice, be sure to subscribe to The Administrator Tip newsletter.


ABOUT THE AUTHOR: Hans Schefske is an Active Directory and SMS Architect for Management Decisions Inc., a telecommunications company based in Atlanta. He was awarded a Microsoft Most Valuable Professional (MVP) Award for SMS in 2003. Hans can be contacted at: hschefske@yahoo.com.

Rate this Tip
To rate tips, you must be a member of SearchEnterpriseDesktop.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Windows legacy operating systems
Windows 7 launches, offers salvation from Vista
Admins can wear many hats using Netcat
Choosing the best way to install images
Ten ways to sell security to management
Improve Windows security with our top 10 tips
Windows Vista management tutorial
Ten ways to selling security to management
Vista security option changes to named pipe access
Minasi talks Vista security, Windows Server 2008 features
Troubleshooting IEEE 1394 bus devices for Windows machines

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
drive-by download  (SearchEnterpriseDesktop.com)
Error messages for Windows 2000  (SearchEnterpriseDesktop.com)
IO.SYS  (SearchEnterpriseDesktop.com)
MS-DOS  (SearchEnterpriseDesktop.com)
remote desktop  (SearchEnterpriseDesktop.com)
W2K  (SearchEnterpriseDesktop.com)
Windows 2000  (SearchEnterpriseDesktop.com)
Windows 98  (SearchEnterpriseDesktop.com)
Windows Remote Desktop  (SearchEnterpriseDesktop.com)
Windows XP  (SearchEnterpriseDesktop.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Enterprise Desktop Security - Virus Protection, Malware Protection, Intrusion Detection
HomeTopicsITKnowledge ExchangeTipsMultimediaWhite PapersBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2008 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts