Using ADSI, you can programmatically manipulate the User Environment Profile and Home Directory parameters for any given user account (as shown in Figure 4.2). This can be handy in cases where the server responsible for home directories or user profile storage is renamed or consolidated and all existing users must have their profiles modified to reflect the changes.
With ADSI, the administrator can quickly write a few lines of code and adapt gracefully to the ever-changing minds of management without drastically affecting the amount of free time available for the more interesting projects that may present themselves . Ultimately, the goal of any development-savvy systems administrator should be to create scripts that increase proactive monitoring of conditions in the domains, as well as quickly adapt to the inevitable changes of the modern enterprise.
Using the IADsUser interface and the Windows NT service provider, you can manipulate the User Profile Path entry in a user account SAM entry.
To find the current value used by Windows NT to specify the location of a user's profile, use the following Visual Basic code:
Dim User as IADsUser Dim UserName as String Dim UserDomain as String UserDomain = " Target_User_Domain " UserName = " Target_User_Name " Set User = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user") Dim RetVal as String RetVal = User.Profile Debug.Print RetVal
To set a new value for a user's profile path, use the following Visual Basic code:
Dim User as IADsUser Dim UserName as String Dim UserDomain as String Dim NewValue as String UserDomain = " Target_User_Domain " UserName = " Target_User_Name " NewValue = " New_User_Profile_Path " Set User = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user") User.Profile = NewValue User.SetInfo
Just as you can query and set the value of the Profile property for any given user account, you can also manipulate the value of the LoginScript property.
Use the following Visual Basic code to find the login script currently in use for the bound user account:
Dim User as IADsUser Dim UserName as String Dim UserDomain as String UserDomain = " Target_User_Domain " UserName = " Target_User_Name " Set User = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user") Dim RetVal as String RetVal = User.LoginScript Debug.Print RetVal
To specify a new login script for the bound user object, use the following Visual Basic code:
Dim User as IADsUser Dim UserName as String Dim UserDomain as String UserDomain = " Target_User_Domain " UserName = " Target_User_Name " Set User = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user") Dim NewValue as String NewValue = "NewLoginScript.CMD" User.LoginScript = NewValue User.SetInfo
Like many of the most commonly configured properties of a user record in the SAM, the Home Directory Path entry is manipulated using a property of the IADsUser interface.
To find the UNC path associated with the user's home directory, use the following Visual Basic code:
Dim User as IADsUser Dim UserName as String Dim UserDomain as String UserDomain = " Target_User_Domain " UserName = " Target_User_Name " Set User = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user") Dim RetVal as String RetVal = User.HomeDirectory Debug.Print RetVal
If you need to change the location of a user's home directory you can programmatically manipulate the user's SAM record to reflect the change. Consider the following Visual Basic code:
Dim User as IADsUser Dim UserName as String Dim UserDomain as String Dim NewValue as String UserDomain = " Target_User_Domain " UserName = " Target_User_Name " NewValue = " New_Home_Directory_Path_Value " Set User = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user") User.HomeDirectory = NewValue User.SetInfo
Although HomeDirectory is exposed as a property of the IADsUser interface, to manipulate the Home Directory Mapping entry in the SAM, you must use the IADs Get method to access the HomeDirDrive property.
To find the drive letter used to map a user's home directory, use the following Visual Basic code:
Dim User as IADsUser Dim UserName as String Dim UserDomain as String UserDomain = " Target_User_Domain " UserName = " Target_User_Name " Set User = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user") Dim RetVal as String RetVal = User.Get("HomeDirDrive") Debug.Print RetVal
To change the drive letter used to map a user's home directory, use the following Visual Basic code:
Dim User as IADsUser Dim UserName as String Dim UserDomain as String Dim NewValue as String UserDomain = " Target_User_Domain " UserName = " Target_User_Name " NewValue = " New_Value_For_Home_Directory_Drive " Set User = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user") User.Put("HomeDirDrive", NewValue) User.SetInfo
Tip
To set the drive letter used for the home directory mapping, pass in the drive letter and a colon as a string value (such as "H:" ) .
If you want to specify a local path for the home directory, simply set the HomeDirDrive property to a null string:
User.Put("HomeDirDrive", "")
Top |