+ Post New Thread
Results 1 to 7 of 7
Windows Thread, help with logon script (writing to active directory) in Technical; ive managed to write a script (well pinched and edited really) that when run dumps the computer name into a ...
  1. #1


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,647
    Thank Post
    229
    Thanked 865 Times in 743 Posts
    Rep Power
    297

    help with logon script (writing to active directory)

    ive managed to write a script (well pinched and edited really) that when run dumps the computer name into a users active directory info. Currently it works but it dumps the info to description id like it to dump it in office but if i change description to office the script just bombs out

    Code:
    Const ADS_PROPERTY_CLEAR = 1
    
    Set objSysInfo = CreateObject("ADSystemInfo")
    Set objNetwork = CreateObject("WScript.Network")
    strCompName = LCase(objNetwork.ComputerName)
    strUserDN = objSysInfo.userName
    Set objUser = GetObject("LDAP://" & strUserDN)	' Bind to the user object in Active Directory with the LDAP provider.
    
    objUser.Put "Description", (strCompName)	'...add the computer name to Active Directory profile...
    objUser.SetInfo										' ...and save the changes.

  2. Thanks to sted from:

    mcrompton01 (3rd February 2012)

  3. #2

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,249
    Thank Post
    671
    Thanked 1,643 Times in 1,466 Posts
    Rep Power
    424
    Change it to:

    physicalDeliveryOfficeName

    Ben

  4. #3

    plexer's Avatar
    Join Date
    Dec 2005
    Location
    Norfolk
    Posts
    13,249
    Thank Post
    671
    Thanked 1,643 Times in 1,466 Posts
    Rep Power
    424

  5. Thanks to plexer from:

    sted (3rd February 2012)

  6. #4

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,698
    Thank Post
    335
    Thanked 516 Times in 484 Posts
    Rep Power
    180
    Try physicalDeliveryOfficeName

    Edit - I'm slow

    Steve

  7. Thanks to Steve21 from:

    sted (3rd February 2012)

  8. #5


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,647
    Thank Post
    229
    Thanked 865 Times in 743 Posts
    Rep Power
    297
    thankyou

  9. #6
    mcrompton01's Avatar
    Join Date
    May 2006
    Location
    Burntwood
    Posts
    44
    Thank Post
    1
    Thanked 10 Times in 7 Posts
    Rep Power
    19
    Hi sted,

    Thanks for the above script it has proved really useful for us we coupled it with a couple of things:
    1. Logoff script to clear this value
    2. Changed the AD schema to add a new option to the users right click in ADUC: Start VNC session

    We did find one limitation it could not get the client name when a user logs into our terminal servers. We have pinched and modified some functions that allow you to get the clientname. Thought I'd post it back in case you find it useful.

    Code:
    '########################################################################################################################
    '#	VERSION HISTORY													#
    '#															#
    '#	v1.00 - Log basic conputer name to AD based on						
    '#	http://www.edugeek.net/forums/windows/89800-help-logon-script-writing-active-directory.html 			#
    '#	v2.00 - Now works with Terminal Server ClientName								#
    '#															#
    '########################################################################################################################
    
    On Error Resume Next
    
    'Define the Update AD attribute and define all variables
    	Const ADS_PROPERTY_UPDATE = 2
    	Dim objSysInfo, objNetwork, strCompName, strUserDN, objUser, strClientName, strTerminalServerIdent
    
    'Part of the computer name that is unique to terminal servers (e.g. XYZ-TS-00X) must be lower case.
    	strTerminalServerIdent = "-ts-"
    
    'Create the objects required to get required information
    	Set objSysInfo = CreateObject("ADSystemInfo")
    	Set objNetwork = CreateObject("WScript.Network")
    
    'Set the variables required
    	strCompName = LCase(objNetwork.ComputerName)
    	strUserDN = objSysInfo.userName
    
    'check if the computer name is a Terminal Server
    	If Instr(strCompName,strTerminalServerIdent) > 0 then
    		strClientName = clientName()
    		If strClientName <> "" then
    			strCompName = trim(strClientName) 	
    		End If
    	End If
    
    'Connect to the user/computer AD path (Bind)
    	Set objUser = GetObject("LDAP://" & strUserDN)	
    
    'Add the computer name to the Office AD value for the user and save it
    	objUser.Put"physicalDeliveryOfficeName", Trim(Ucase(strCompName))
    	objUser.SetInfo
    
    'Close/empty all the variables (tidy up)
    	strCompName = ""
    	strCompName = Null
    
    	strUserDN = ""
    	strUserDN = Null
    
    	strClientName = ""
    	strClientName = Null
    
    	Set objSysInfo = Nothing
    	Set objNetwork = Nothing
    	Set objUser = Nothing		
    
    '############# FUNCTIONS REQUIRED #########################
    	Function sessionNumber()
    		Dim oShell, oExec, sOutput, iUserPos, iUserLen, iStatePos
    		Set oShell = CreateObject("WScript.Shell")
    		Set oExec = oShell.Exec("query session %username%")
    		sOutput = LCase(oExec.StdOut.ReadAll)
    		iUserPos = InStr(sOutput,LCase(oShell.ExpandEnvironmentStrings("%username%")))
    		iStatePos = InStr(sOutput,"active")
    		iUserLen = Len(oShell.ExpandEnvironmentStrings("%username%"))
    		sessionNumber = CInt(Trim(Mid(sOutput,iUserPos+iUserLen,iStatePos-iUserPos-iUserLen)))
    	End Function
     
    	Function clientName()
     		Dim oShell
     		Set oShell = CreateObject("WScript.Shell")
     		On Error Resume Next
     		If Err.Number = 0 Then
    			clientName = LCase(oShell.RegRead("HKCU\Volatile Environment\"& sessionNumber() &"\CLIENTNAME"))
     		Else
    			clientName =  ""
     		End If
     	End Function
    Mark!

  10. #7


    Join Date
    Mar 2009
    Location
    Leeds
    Posts
    6,647
    Thank Post
    229
    Thanked 865 Times in 743 Posts
    Rep Power
    297
    no probs

    my main purpose for my script is so that i can quickly see the spec of a given pc so it seems sensible to shove it in ad as it is a database and keeps as much info in the same place as poss.

SHARE:
+ Post New Thread

Similar Threads

  1. Help with beginner script/batch file to rename Program File?
    By El_Nombre in forum How do you do....it?
    Replies: 3
    Last Post: 23rd June 2011, 02:05 PM
  2. Replies: 7
    Last Post: 31st January 2008, 12:17 PM
  3. Help with KIX script please
    By salan in forum Windows
    Replies: 8
    Last Post: 8th November 2007, 06:55 PM
  4. Stupid CMD error with logon script
    By tarquel in forum Windows
    Replies: 37
    Last Post: 14th June 2006, 09:07 AM
  5. Importing data to Active Directory
    By fooby in forum Wireless Networks
    Replies: 3
    Last Post: 16th February 2006, 05:08 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •