Manipulating User Environment Profiles

   

Manipulating User Environment Profiles

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.

Figure 4.2. User Environment Profile dialog box in User Manager for Domains

graphics/04fig02.gif

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.

Manipulating a User Profile Path

Using the IADsUser interface and the Windows NT service provider, you can manipulate the User Profile Path entry in a user account SAM entry.

Querying the User Profile Path Using Visual Basic

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 
Setting a New User Profile Path Using Visual Basic

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 

Manipulating the LoginScript Property

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.

Querying the LoginScript Property Using Visual Basic

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 
Setting the LoginScript Property Using Visual Basic

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 

Manipulating a Home Directory Path

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.

Querying the Home Directory Path Using Visual Basic

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 
Setting a New Home Directory Path Using Visual Basic

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 

Manipulating the Home Directory Mapping

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.

Querying the Home Directory Mapping Using Visual Basic

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 
Setting a New Home Directory Mapping Using Visual Basic

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


Windows NT. 2000 ADSI Scripting for System Administration
Windows NT/2000 ADSI Scripting for System Administration
ISBN: 1578702194
EAN: 2147483647
Year: 2000
Pages: 194
Authors: Thomas Eck

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net