Login Script to pull users telephoneNumber from AD and then create a registry key in HKCU with that value

StackOverflow https://stackoverflow.com/questions/22919508

  •  29-06-2023
  •  | 
  •  

Question

I am trying to create a login script that pulls the logged in users telephone extension from active directory, I then want to take that variable and use it to create a registry string value in HKCU\software\ with that extension number.

I can create registry keys, and pull the data from AD, but I am stumped on how to pass the information from AD to my registry entry.

Example extension is 1234 and I want to create a registry value of HKCU\software\shoreline teleworks\shoreware client\AgentID, "1234"

Thanks for any help!

Script 1

Dim objSysInfo, objUser
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
set strtelno = objuser.telephonenumber ' Currently logged in User

Script 2

Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\shoreline teleworks\shoreware client\"
KeyPath = "SOFTWARE\shoreline teleworks\shoreware client"
strValueName = "AgentID"
strValue = "1234"
objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPath, strvaluename, strvalue
Was it helpful?

Solution

By the look of it, you are very close. Try (untested code):

Dim objSysInfo, objUser
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject("LDAP://" & objSysInfo.UserName)
set strtelno = objuser.telephonenumber ' Currently logged in User

Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\shoreline teleworks\shoreware client\"
KeyPath = "SOFTWARE\shoreline teleworks\shoreware client"
strValueName = "AgentID"
strValue = strtelno ' <-- This sets the Telephone Number
objRegistry.CreateKey HKEY_CURRENT_USER, strKeyPath, strvaluename, strvalue
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top