Need to retrieve CN Name not user name
sorry if have posted in wrong place, couldnt see script area
i have created script updating computer description on local macine far can show users username. better if show full name.
can 1 please. ive been scouring net 3 hours , no closer resoloution.
here script have
thanks in advance
const hkey_local_machine = &h80000002
strcomputer = "."
set shell = createobject("wscript.shell")
username = shell.expandenvironmentstrings("%username%")
set objregistry = getobject _
("winmgmts:\\" & strcomputer & "\root\default:stdregprov")
strkeypath = "system\currentcontrolset\services\lanmanserver\parameters"
strvaluename = "srvcomment"
strdescription = username
objregistry.setstringvalue hkey_local_machine, strkeypath, strvaluename, strdescription
hello,
from description, want script modify computer description current logon user's cn.
because there seems no variables indicate current log user's cn (dn), have query cn samaccountname (%username%) of current logon user via ldap.
here sample code may refer to:
----------------------------------------------------------
const hkey_local_machine = &h80000002
strcomputer = "."
set shell = createobject("wscript.shell")
username = shell.expandenvironmentstrings("%username%")
set objregistry = getobject ("winmgmts:\\" & strcomputer & "\root\default:stdregprov")
strkeypath = "system\currentcontrolset\services\lanmanserver\parameters"
strvaluename = "srvcomment"
const ads_scope_subtree = 5
set objconnection = createobject("adodb.connection")
set objcommand = createobject("adodb.command")
objconnection.provider = "adsdsoobject"
objconnection.open "active directory provider"
set objcommand.activeconnection = objconnection
objcommand.properties("page size") = 1000
objcommand.properties("searchscope") = ads_scope_subtree
objcommand.commandtext = "select name 'ldap://dc=domain,dc=com' objectcategory='user' " & "and samaccountname='" & username & "'"
set objrecordset = objcommand.execute
strdescription = objrecordset.fields("name").value
objregistry.setstringvalue hkey_local_machine, strkeypath, strvaluename, strdescription
----------------------------------------------------------
1. the code works in test environment. however, please make sure have tests before putting in productive environment.
2. the domain standard users (non administrator users) fail run script because users have not write permission in hklm.
3. when srvcomment value created via script, have reboot computer make shown in system properties dialog box.
hope helps.
Windows Server > Windows Server General Forum
Comments
Post a Comment