OK im trying to update the user profile of people that are logged on to the
machine. I was hoping to use something like the logon_user =
Request.ServerVariables("LOGON_USER") that we can use in .NET but if not
thats not a problem I know i can get it from registry. But if anyone knows
how can you please give me an example. Now Im using the following code to
query a perticular user in active directory. But I need to modify the user
profile
'---------------------------------------------------------------------------------------
Option Explicit
Const ADS_SCOPE_SUBTREE = 2

Dim strName
Dim strTSProfile
Dim strTSHomeDrive
Dim strProfile


Dim rs
Dim cnn
Dim cmd
Dim objuser
Set cnn = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")
' Open the connection.
cnn.Provider = "ADsDSOObject" ' This is the ADSI OLE-DB provider name
cnn.Open "Active Directory Provider"
' Create a command object for this connection.
Set cmd.ActiveConnection = cnn

' Compose a search string and replace DC=YourDomain, DC=COM
cmd.CommandText = "select name, distinguishedname, profilepath, homedrive,
homedirectory, userPrincipalName" _
& " from 'LDAP:// OU= NY, DC=FFHSJ, DC=COM' WHERE objectCategory='user' And
objectCategory='person' and userPrincipalName='wahidta@ffhsj.com'"
cmd.Properties("Page Size") = 1000
cmd.Properties("Timeout") = 30
cmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE 'search all containers
cmd.Properties("Cache Results") = False

Set rs = cmd.Execute
MsgBox "done"

'-------------------------------------------------------------------------------------

How can I use the recordset to make a change on that field and comit it back
to active directory??

Thanks.

Re: vbscript help by Torgeir

Torgeir
Fri Mar 11 13:41:48 CST 2005

Tash wrote:

> OK im trying to update the user profile of people that are logged on to the
> machine. I was hoping to use something like the logon_user =
> Request.ServerVariables("LOGON_USER") that we can use in .NET but if not
> thats not a problem I know i can get it from registry. But if anyone knows
> how can you please give me an example. Now Im using the following code to
> query a perticular user in active directory. But I need to modify the user
> profile.
Hi

You should not read the current user name from registry.

'--------------------8<----------------------
Set oWshNet = CreateObject("WScript.Network")
Wscript.Echo "Current user domain name: " & oWshNet.UserDomain
Wscript.Echo "Current computer name: " & oWshNet.ComputerName
Wscript.Echo "Current user name: " & oWshNet.UserName
'--------------------8<----------------------

But when connecting to the user object in AD it is much easier to use
the ADSystemInfo object to obtain the distinguished name of the
current user.

'--------------------8<----------------------
Set oADsSysInfo = CreateObject("ADSystemInfo")

' Some examples of ADSystemInfo's capabilities:

Wscript.Echo "Domain short name: " & oADsSysInfo.DomainShortName
Wscript.Echo "Domain DNS name: " & oADsSysInfo.DomainDNSName
Wscript.Echo "Forest DNS name: " & oADsSysInfo.ForestDNSName
Wscript.Echo "Domain is in native mode: " & oADsSysInfo.IsNativeMode
Wscript.Echo "Location (Site name) of the current computer: " _
& oADsSysInfo.SiteName
WScript.Echo "Distinguished name of the current computer: " _
& oADsSysInfo.ComputerName
WScript.Echo "Distinguished name of the current user: " _
& oADsSysInfo.UserName

'--------------------8<----------------------


In the script below, to update an user attribute, change
"SomeAttribute" to the attribute name you want to update:

'--------------------8<----------------------

Set oADsSysInfo = CreateObject("ADSystemInfo")

' get AD user object
Set oADsUser = GetObject("LDAP://" & oADsSysInfo.UserName)

Wscript.Echo "Old value: " & oADsUser.SomeAttribute

' change the value
oADsUser.SomeAttribute= "something"
oADsUser.SetInfo
Wscript.Echo "New value: " & oADsUser.SomeAttribute
'--------------------8<----------------------



--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx