I have a VB script being used for certain OU's that will check for an installation of Office and if it is there it will pull the AD name and insert it as the Office user.
'// Get into the habit of ALWAYS declaring your variables - it saves a lot of heartache'// if there are coding errors!Option ExplicitDim objSysInfoDim objUserDim objWordOn Error Resume NextSet objSysInfo = CreateObject("ADSystemInfo")
If Not IsObject(objSysInfo) ThenWScript.Quit(False)End IfstrUser = objSysInfo.UserNameSet objUser = GetObject("LDAP://" & strUser)If Not IsObject(objUser) ThenSet objSysInfo = NothingWScript.Quit(False)End IfSet objWord = CreateObject("Word.Application")If Not IsObject(objWord) ThenSet objSysInfo = NothingSet objUser = NothingWScript.Quit(False)End If'// You should check whether or not these properties contain any text'// before trying to trim themobjWord.UserName = objUser.givenName & " " & objUser.SNobjWord.UserInitials = Left(objUser.givenName, 1) & Left(objUser.SN, 1)objWord.Quit'// Always clean up afterwards, tooSet objWord = NothingSet objUser = NothingSet objSysInfo = Nothing
Personally, to avoid the nasty "If Not IsObject..." code repetition, I'd build a function to create the objects and just pass in the name and ProgId, handling any errors in that function but it's a tiny script so maybe save that for a bigger project.
Ha, ha, ha! Ha, ha, ha! Ha, ha, ha! Ha, ha, ha! Ha, ha, ha! Ha, ha, ha!
I don't think I've *ever* encountered this before...it seems the (let's call it) interpreter is falling over the word "trim" which, as you may or may not know, is a VBScript keyword. The WSH (Windows Scripting Host) version on my machine, 5.8, ignores it, though.
Anyway...remove the comment and the script should run.