Generating Outlook Signatures Based on Active Directory Information - Creating the signature
(Page 3 of 4 )
Hopefully, you now have an idea of what you want to put into your signature file. Armed with this information, we can now start to create the file. The first thing you need to do is create the file itself; we can do this using a simple CreateTextFile command:
Set CreateSigFile = FileSysObj.CreateTextFile (SigFile, 8, False)
This will give us our file and a handle to it. Now we can start to write some information into it.
Before writing the code to build the file, it might be worth it to first look at the signature HTML document in a WYSIWYG editor. Once you are happy with the way it looks, you can copy and paste the HTML code into your script.
First of all, we will write the opening HTML code into the file:
CreateSigFile.WriteLine "<!DOCTYPE HTML PUBLIC " & """-//W3C//DTD HTML 4.0 Transitional//EN""" & ">"
CreateSigFile.WriteLine "<HTML><HEAD><TITLE>Outlook Signature</TITLE>"
CreateSigFile.WriteLine "<META http-equiv=Content-Type content=" & """text/html; charset=windows-1252""" & ">"
CreateSigFile.WriteLine "<META content=" & """MSHTML 6.00.2900.3059""" & " name=GENERATOR></HEAD>"
CreateSigFile.WriteLine "<BODY>"
CreateSigFile.WriteLine "<HR>"
Now that we have that, the next step is to start using information we have about the user, which is held in the active directory object we opened. To get at this information, we just use UserObj.AttributeName. So if we want to print the user's company, we call UserObj.Company.
As mentioned before, you get to see all the attributes using the ADSIEdit application. So, here is the object in action:
CreateSigFile.WriteLine "<DIV align=left><STRONG><FONT face=Arial color=#000000>" & UserObj.displayName & "</strong></FONT></DIV>"
If UserObj.description <> "" then CreateSigFile.WriteLine "<DIV align=left><FONT face=Arial size=2 color=#000000><strong>" & UserObj.description & "</strong></FONT></DIV>"
CreateSigFile.WriteLine "<DIV align=left><FONT face=Arial size=2></FONT><BR></DIV>"
CreateSigFile.WriteLine "<DIV align=left><FONT face=Arial size=2 color=#000000><strong>" & UserObj.company & "</strong></FONT></DIV>"
As you can see, we are getting the user's Display name (not their login name), description, and company. Before writing the description out, we first check to see if there is one. If not, we try to write one out or we would just end up with a blank line.
Next: Finishing the Signature File >>
More Windows Scripting Articles
More By Luke Niland