Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AD script at logon to get the currently logged on users email address?

Status
Not open for further replies.

markm75

IS-IT--Management
Joined
Oct 12, 2006
Messages
187
Location
US
Is there a way, in our login script, that I can grab the current user's email address when they log in?

Ideally I will then want to take that value and place it in the correct spot in the registry so that Office Communicator 2005 sign in information is filled in... (not sure on how to do this either, except for the location in the registry).

Thanks for any help

Mark
 
Something like this might work for you.

Code:
Option Explicit
'On Error Resume Next

Dim objUser, objADSysInfo

Set objADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
WScript.Echo objUser.Mail

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
How about something like this??

Code:
Set objUser = GetObject _
    ("LDAP://cn=myerken,ou=management,dc=fabrikam,dc=com")


WScript.Echo "First Name: " & objUser.givenName
WScript.Echo "Initials: " & objUser.initials
WScript.Echo "Last Name: " & objUser.sn
WScript.Echo "Display Name: " & objUser.displayName
WScript.Echo "Office: " & _
    objUser.physicalDeliveryOfficeName
WScript.Echo "Telephone Number: " & objUser.telephoneNumber
WScript.Echo "Email: " & objUser.mail
WScript.Echo "Home Page: " & 
 
For Each strValue in objUser.description
    WScript.Echo "Description: " & strValue
Next

For Each strValue in objUser.otherTelephone
    WScript.Echo "Other Telephone: " & strValue
Next

For Each strValue in objUser.url
    WScript.Echo "URL: " & strValue
Next

Hope this helps


Thanks

John Fuhrman
Titan Global Services
 
This was most useful..

One question though.. here is what I have so far.. I just want to use this same script to add/change an existing key in the registry.. Some of the code below is actually batch file code, any ideas on how I would do the same converted to vbs?

CODE:

Option Explicit
'On Error Resume Next

Dim objUser, objADSysInfo

Set objADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
WScript.Echo objUser.Mail

'batch code here:
reg add "%%c\HCU\Microsoft\Communicator" /V "UserMicrosoft RTC Instant Messaging" /T REG_SZ /F /D objUser.Mail

 
FYI, the example in the link has this:

WshShell. RegWrite

should be

WshShell.RegWrite

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
I checked that out.. actually here is the code I have as a result.. which almost appears to be working (no error messages).. except that the registry entry doesnt seem to be changing (The old value remains, also if I delete the existing key, the new one doesnt get created for some reason) I've tried this on Vista and XP, so I know its not a UAC issue at least:

New Code:

Option Explicit
'On Error Resume Next

Dim objUser, objADSysInfo

Set objADSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objADSysInfo.UserName)
WScript.Echo objUser.Mail


Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.RegWrite "HKCU\Microsoft\Communicator"& "UserMicrosoft RTC Instant Messaging", objUser.Mail, "REG_SZ"

 
I also tried modifying the last line to this.. thinking it didnt look quite right.. but this didnt result in anything either:

WshShell.RegWrite "HKCU\Microsoft\Communicator\UserMicrosoft RTC Instant Messaging", objUser.Mail, "REG_SZ"

The value "UserMicrosoft...." is a string underneith the key "Communicator"...
 
It actually should look similar to this.

WshShell.RegWrite "HKCU\Microsoft\Communicator\UserMicrosoft RTC Instant Messaging", objUser.Mail, "REG_SZ"

Wouldn't Microsoft\Com.. be under Software?

i.e. "HKCU\Software\Communicator\UserMicrosoft RTC Instant Messaging", objUser.Mail, "REG_SZ"

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
Yes.. that was a typo on the missing software path...

But this did the trick.. the slight change to the script with the .RegWrite command.

Thanks for the help
 
Not sure if you've completed your script or not, but thaught this bit of code I use to read and set registry setting may help.

Code:
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."
 
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    strComputer & "\root\default:StdRegProv")

dwValue0 = ""
strKeyPath = "SOFTWARE\Citadel Security Software\Hercules\3.0\Client"
Const Enable = 1

strValueName = "LogEnabled"
oReg.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue0
If dwValue0 <> 1 Then 
	Wscript.Echo "Herc Logging: " & "			disabled" 
	oReg.SetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,Enable

 Else
	Wscript.Echo "Herc Logging: " & "			enabled" 
End If

Hope this helps.


Thanks

John Fuhrman
Titan Global Services
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top