Richard
Mon Jan 02 20:20:39 CST 2006
"Jerold Schulman" <Jerry@jsiinc.com> wrote in message
news:onkjr1ts58t3cp35vjfmr00047i7i858fr@4ax.com...
> On Mon, 2 Jan 2006 15:53:02 -0800, "Frank"
> <Frank@discussions.microsoft.com> wrote:
>
>>
>>I would like to have a greeting in my login script, but I don't want to
>>use
>>the username. I would like to use the person's first name. I've
>>encountered
>>dozens of sample scripts with something like strUser =
>>objNetwork.UserName,
>>but nothing that explains how to use the person's FIRST name.
>>
>>I'd also like to tell them what drives they are mapped to and reply their
>>default printer.
>>
>>Thanks for your help.
>>
>
> On Error Resume Next
> Dim objConnection, objCommand
> Dim strQuery, objRecordSet
> Set objSysInfo = CreateObject("ADSystemInfo")
> sUser = objSysInfo.UserName
> Set objConnection = CreateObject("ADODB.Connection")
> Set objCommand = CreateObject("ADODB.Command")
> objConnection.Provider = "ADsDSOOBject"
> objConnection.Open "Active Directory Provider"
> Set objCommand.ActiveConnection = objConnection
> strBase = "<LDAP://" & sUser & ">"
> strAttributes = "givenName"
> strQuery = strBase & ";;" & strAttributes & ";subtree"
> objCommand.CommandText = strQuery
> objCommand.Properties("Page Size") = 99999
> objCommand.Properties("Timeout") = 300
> objCommand.Properties("Cache Results") = False
> Set objRecordSet = objCommand.Execute
> objRecordSet.MoveFirst
> Do Until objRecordSet.EOF
> strGN = objRecordSet.Fields("givenName")
> Wscript.Echo strGN
> objRecordSet.MoveNext
> Loop
> objConnection.Close
> Set objConnection = Nothing
> Set objCommand = Nothing
> Set objRecordSet = Nothing
>
> Jerold Schulman
> Windows Server MVP
> JSI, Inc.
>
http://www.jsiinc.com
>
http://www.jsifaq.com
Hi,
Once you retrieve the Distinguished Name of the user from ADSystemInfo and
bind to the user object, you can retrieve givenName directly. For example:
========================
Option Explicit
Dim objSysInfo, objUser, strFirstName
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
strFirstName = objUser.givenName
Call MsgBox("Hello " & strFirstName)
=========================
You can use the Drives object from the FileSystemObject to enumerate all
drives, local or network:
=========================
Dim objFSO, objDrives, objDrive
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDrives = objFSO.Drives
For Each objDrive In objDrives
Wscript.Echo objDrive.Path & " " & objDrive.ShareName
Next
=========================
It's up to you how you display this in a logon script. Alternatively, you
can use the wshNetwork object and enumerate the Drives collection. This only
includes network drives. You can also enumerate all printers connected to
the client, as below:
=========================
Dim objNetwork, j, objDrives, objPrinters
Set objNetwork = CreateObject("Wscript.Network")
Set objDrives = objNetwork.EnumNetworkDrives
For j = 0 To objDrives.Count - 2 Step 2
Wscript.Echo "Drive " & objDrives(j) & " = " & objDrives(j + 1)
Next
Set objPrinters = objNetwork.EnumPrinterConnections
For j = 0 To objPrinters.Count - 2 Step 2
Wscript.Echo "Printer " & objPrinters(j) & " = " & objPrinters(j + 1)
Next
==========================
The SetDefaultPrinter method of the wshNetwork object sets the default
printer, but I don't know how to determine what the default is. Perhaps
someone else does.
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab -
http://www.rlmueller.net