;Set Break to on if the script is not running at logon.
;This will prevent you being logged of when testing this script and closing
;it when it's running.
If NOT @LOGONMODE
Break on
EndIf
;Call the readfile UDF.
;This UDF is used later in the script.
Call @LDRIVE + "\functions\readfile().udf"
;Delete all existing signatures.
;Stuff can change. Therefore the signatures are
;deleted and recreated each time.
$appdata = ExpandEnvironmentVars(%appdata%)
Del $appdata + "\Microsoft\Signatures\*.*"
;Get data from AD
;Open ADSystemInfo object
$objSysInfo = CreateObject("ADSystemInfo")
;Get the username from AD.
$strUser = $objSysInfo.UserName
;Get the users deatils using LDAP.
$objUser = GetObject("LDAP://" + $strUser)
;Get the users full name.
$strName = $objUser.FullName
;Get the users title.
$strTitle = $objUser.Title
;Get the users default reply e-mail address.
$strMail = $objUser.mail
;Get the users department.
$strDepartment = $objUser.Department
;Get the users company name.
$strCompany = $objUser.Company
;Get the users street address.
$strStreet = $objUser.StreetAddress
;Get the users postal code.
$strPostalCode = $objUser.PostalCode
;Get the users city.
$strCity = $objUser.L
;Get the users country.
$strCountry = $objUser.Co
;Get the users phone number.
$strPhone = $objUser.telephoneNumber
;Get the users fax number.
$strFax = $objUser.FacsimileTelephoneNumber
;Get the users mobile phone number
$strMobile = $objUser.Mobile
;Get the users homepage.
$strWeb = $objUser.wWWHomePage
;Read the contents of the news text file using the
;readfile UDF called at the top of the script.
$strNews = ReadFile(@LDRIVE + "\tools\News.txt")
;Initialize word to write the signature.
$objWord = CreateObject("Word.Application")
;Add a document to word and set various options.
$objDoc = $objWord.Documents.Add()
$objSelection = $objWord.Selection
$objEmailOptions = $objWord.EmailOptions
$objSignatureObject = $objEmailOptions.EmailSignature
$objSignatureEntries = $objSignatureObject.EmailSignatureEntries
;Write signature.
;Set font to use in the signature.
$objSelection.Font.Name = "Arial"
;Set the font size.
$objSelection.Font.Size = "10"
;Write text.
$objSelection.TypeText("Kind regards,")
;Write a "soft" enter. Just like br in HTML.
$objSelection.TypeText(Chr(11))
;Write a "soft" enter. Just like br in HTML.
$objSelection.TypeText(Chr(11))
;Set the colour of the following text.
$objSelection.Font.Color = "26367"
;Write text and use the variables filled when retrieving data from AD.
$objSelection.TypeText($strName + " | " + $strTitle)
;Set font size.
$objSelection.Font.Size = "9"
;Write a "soft" enter. Just like br in HTML.
$objSelection.TypeText(Chr(11))
;Write text and use the variables filled when retrieving data from AD.
$objSelection.TypeText($strCompany)
;Set the colour of the following text.
$objSelection.Font.Color = "8421504"
;Write text and use the variables filled when retrieving data from AD.
$objSelection.TypeText(" | " + $strStreet + " | " + $strPostalcode + " | " + $strCity)
;Write a "soft" enter. Just like br in HTML.
$objSelection.TypeText(Chr(11))
;Write text and use the variables filled when retrieving data from AD.
$objSelection.TypeText("Phone: " + $strPhone + " | " + "Fax: " + $strFax + " | " + "Mobile: " + $strMobile)
;Write a "soft" enter. Just like br in HTML.
$objSelection.TypeText(Chr(11))
;Write text and use the variables filled when retrieving data from AD.
$objSelection.TypeText("E-mail: " + $strmail + " | " + "Web: " + $strWeb)
;Write a "soft" enter. Just like br in HTML.
$objSelection.TypeText(Chr(11))
;Write a "soft" enter. Just like br in HTML.
$objSelection.TypeText(Chr(11))
;Write a news message to the signature..
;If there is no news the news file will be empty ($strNews[0] will be empty) or
;the news file does not exist (Ubound($strNews) will be -1).
;Skip the news part the file does not exist or write nothing if the first line is empty.
If Ubound($strNews) <> "-1"
;Strip leadign and trailing spaces from ech line in the $strNews variable.
For $i = 0 to Ubound($strNews)
$strNews[$i] = Trim($strNews[$i])
Next
If $strNews[0] <> ""
;Set font style. 1 = bold, 0 = regular.
$objSelection.Font.Bold = "1"
;Set the colour of the following text.
$objSelection.Font.Color = "26367"
;Set the font size.
$objSelection.Font.Size = "10"
;Write text.
$objSelection.TypeText("News:")
;Set the font size.
$objSelection.Font.Size = "9"
;Set font style. 1 = bold, 0 = regular.
$objSelection.Font.Bold = "0"
;Write a "soft" enter. Just like br in HTML.
$objSelection.TypeText(Chr(11))
;Write each line from the $strNews variable.
;$strNews is an array so it gets written line by line (element by element).
;$i is used as an index counter to tell the scrip what line it should write.
;$i starts out as 0 and ends up as the largest element of the array.
For $i = 0 to Ubound($strNews)
;Set the color of the folowing text.
$objSelection.Font.Color = "8421504"
;Write the line from $strNews given by the index.
$objSelection.TypeText($strNews[$i])
;Write a "soft" enter. Just like br in HTML.
$objSelection.TypeText(Chr(11))
Next
EndIf
EndIf
$objSelection = $objDoc.Range()
;Add signature.
;You could change @FULLNAME to whatever you want. Just be sure to change it the same on the
;two parts below where outlook is told to use or not use a signature on the different types of messages.
$objSignature = $objSignatureEntries.Add(@FULLNAME, $objSelection)
;Set outlook to use the signatures on each new message.
$objSignatureObject.NewMessageSignature = @FULLNAME
;$objSignatureObject.NewMessageSignature = ""
;Switch the ; on the two lines above to use no signature on new messages.
;Set outlook to use the signatures on each reply message.
;$objSignatureObject.ReplyMessageSignature = @FULLNAME + " NL"
$objSignatureObject.ReplyMessageSignature = ""
;Switch the ; on the two lines above to use no signature on reply messages.
;Save the signature and quit word
$objDoc.Saved = 1
$objWord.Quit