AD Based Outlook Email Signature for 2003 and 2007 Continued – Implementation Guide

earlier on in the year I blogged about AD based signatures for 2003 and 2007 outlook (find the post here), It seems I am not the only person that needs this, I have been getting rather high stats on this topic and a few questions.

So I thought I would go through a little more in detail in terms of what you have to modify and how you would go about implementing the script into an AD based environment.

Ok So lets start with the script and what you need to modify. I will highlight in RED what needs to change

NOTE: DO NOT COPY AND PASTE THE BELOW SCRIPT IT WILL NOT WORK, as there are various comments to show you what you need to change. Please refer to the previous post which has the original code, which you should copy, paste and modify.



‘ VBScript: <Signatures.vbs>
‘ AUTHOR: Peter Aarts
‘ Contact Info:
‘ Version 2.04
‘ Date: January 20, 2006
‘ Moddified By Brad Marsh Now works with both 2003 and 2007 outlook
‘ Contact:
‘ Date 19 feb 08
‘ Tested on Vista, XP, XP64 and office 2003 and 2007.
‘ NOTE will not work that well with various email accounts

‘Option Explicit
On Error Resume Next

Dim qQuery, objSysInfo, objuser
Dim FullName, EMail, Title, PhoneNumber, MobileNumber, FaxNumber, OfficeLocation, Department
Dim web_address, FolderLocation, HTMFileString, StreetAddress, Town, State, Company
Dim ZipCode, PostOfficeBox, UserDataPath

‘ Read LDAP(Active Directory) information to asigns the user’s info to variables.
Set objSysInfo = CreateObject(“ADSystemInfo”)
qQuery = “LDAP://” & objSysInfo.Username
Set objuser = GetObject(qQuery)

FullName = objuser.displayname
EMail = objuser.mail
Company = objuser.Company
Title = objuser.title
PhoneNumber = objuser.TelephoneNumber
FaxNumber = objuser.FaxNumber
OfficeLocation = objuser.physicalDeliveryOfficeName
StreetAddress = objuser.streetaddress
PostofficeBox = objuser.postofficebox
Department = objUser.Department
ZipCode = objuser.postalcode
Town = objuser.l
MobileNumber = objuser.TelephoneMobile
web_address =”  — Change this to your web address

‘ This section creates the signature files names and locations.
‘ Corrects Outlook signature folder location. Just to make sure that
‘ Outlook is using the purposed folder defined with variable : FolderLocation
‘ Example is based on Dutch version.
‘ Changing this in a production enviremont might create extra work
‘ all employees are missing their old signatures
Dim objShell, RegKey, RegKey07, RegKeyParm
Set objShell = CreateObject(“WScript.Shell”)
RegKey = “HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\General”
RegKey07 = “HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Common\General”
RegKey07 = RegKey07 & “\Signatures”
RegKey = RegKey & “\Signatures”
objShell.RegWrite RegKey , “AD_elcom” — Change this to what you would like the regitsry key to specify

objShell.RegWrite RegKey07 , “AD_elcom”– Change this to what you would like the regitsry key to specify

UserDataPath = ObjShell.ExpandEnvironmentStrings(“%appdata%”)
FolderLocation = UserDataPath &”\Microsoft\AD_elcom\” – Change this to your desired path
HTMFileString = FolderLocation & “Elcom.htm” — change this to your desired file name

‘ This section disables the change of the signature by the user. AND HAS BEEN COMMENTED OUT, uncommented it at your risk
‘objShell.RegWrite “HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\MailSettings\NewSignature” , “L1-Handtekening” — change this to your desired setting (note I did not use these settings they were commented out

‘objShell.RegWrite “HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Common\MailSettings\ReplySignature” , “L1-Handtekening” — change this to your desired setting (note I did not use these settings they were commented out

‘objShell.RegWrite “HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Options\Mail\EnableLogging” , “0″, “REG_DWORD”

‘ This section checks if the signature directory exits and if not creates one.
Dim objFS1
Set objFS1 = CreateObject(“Scripting.FileSystemObject”)
If (objFS1.FolderExists(FolderLocation)) Then
Call objFS1.CreateFolder(FolderLocation)
End if

‘ The next section builds the signature file
Dim objFSO
Dim objFile,afile
Dim aQuote
aQuote = chr(34)

‘ This section builds the HTML file version
Set objFSO = CreateObject(“Scripting.FileSystemObject”)

‘ This section deletes to other signatures.
‘ These signatures are automaticly created by Outlook 2003.
Set AFile = objFSO.GetFile(Folderlocation&”Elcom.rtf”)
Set AFile = objFSO.GetFile(Folderlocation&”Elcom.txt”)

Set objFile = objFSO.CreateTextFile(HTMFileString,True)
Set objFile = objFSO.OpenTextFile(HTMFileString, 2)



always start a new line of code with objfile.write “
Close every line with ” & vbCrLf

the rest is simple HTML, you will need to change this to suite your requirements

–start of HTML  Body Started, you can copy this–

objfile.write “<!DOCTYPE HTML PUBLIC ” & aQuote & “-//W3C//DTD HTML 4.0 Transitional//EN” & aQuote & “>” & vbCrLf
objfile.write “<HTML><HEAD><TITLE>Microsoft Office Outlook Signature</TITLE>” & vbCrLf
objfile.write “<META http-equiv=Content-Type content=” & aQuote & “text/html; charset=windows-1252″ & aQuote & “>” & vbCrLf
objfile.write “<META content=” & aQuote & “MSHTML 6.00.3790.186″ & aQuote & ” name=GENERATOR></HEAD>” & vbCrLf
objfile.write “<body>” & vbCrLf

– Start of Style and open and close of head, you can copy this you may want to change the style a little –

objfile.write “    <head> <style type=text/css>” & vbCrLf
objfile.write “}” & vbCrLf
objfile.write “.style4 {” & vbCrLf
objfile.write “    text-decoration: none;” & vbCrLf
objfile.write “    color: #696969;” & vbCrLf
objfile.write “    font-family: Verdana;” & vbCrLf
objfile.write “}” & vbCrLf
objfile.write “</style></head>” & vbCrLf


–Start of the actual Signature, CHANGE this, however make sure you keep the Variables in tack, just more them to suite you variables in this signature are and should look like below when inserted into the HTML:

“& FullName &”
“& EMail &”
“& Company &”
“& Title &”
“& PhoneNumber &”
“& FaxNumber &
“& OfficeLocation &”
“& StreetAddress &”
“& PostofficeBox &”
“& Department &”
“& ZipCode &”
“& Town &”
“& MobileNumber &”
“& web_address &”

I will highlight them red so you can see where they actully are used within the HTML, I did not use all of the variables listed above.



objfile.write “<font color=696969 face=Verdana>” & vbCrLf
objfile.write “<b> <span style=’font-size: 10pt;’> “& FullName & “</span> </b> ” & vbCrLf
objfile.write “<span style=’color: #FF0000;font-size: 10pt;font-weight: bold;’>|</span> ” & vbCrLf
objfile.write “<a href=mailto:” & Email &” span style=’font-size: 8pt;text-decoration: none;color: #696969;’ > <span style=’font-size: 8pt;text-decoration: none;color: #696969;’>” & Email &” </span></a>” & vbCrLf
objfile.write “<br>” & vbCrLf
objfile.write “<span style=’font-size: 8pt;color: #696969;font-weight: bold;’>” & title & ” </span> <br>” & vbCrLf
objfile.write “<br>” & vbCrLf
objfile.write “<span style=’font-size: 7.5pt;color: #696969;’>“& Company & ” </span>” & vbCrLf
objfile.write “<span style=’color: #FF0000; font-size: 7.5pt;’>|</span> <span style=’font-size: 7.5pt;color: #696969;’>Australian Technology Park</span> ” & vbCrLf
objfile.write “<span style=’color: #FF0000; font-size: 7.5pt;’>| </span> ” & vbCrLf
objfile.write “<span style=’font-size: 7.5pt;color: #696969;’> Sydney </span><br>” & vbCrLf
objfile.write “<span style=’color: #FF0000; font-size: 7.5pt;’>t</span><span style=’font-size: 7.5pt;color: #696969;’> +612 ” & PhoneNumber &”</span><span style=’color: #FF0000; font-size: 7.5pt;’>&nbsp;&nbsp;f</span><span style=’font-size: 7.5pt;color: #696969;’> +612 9209 4423</span>” & vbCrLf
objfile.write “<span style=’color: #FF0000; font-size: 7.5pt;’>| </span>” & vbCrLf
objfile.write “<span style=’font-size: 7.5pt;color: #696969;’> <a href=><span class=style4></a></span> </span><br>” & vbCrLf
objfile.write “<br>” & vbCrLf
objfile.write “<A href=> <img src=×70.gif height=70 width=175 border=0></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;” & vbCrLf
objfile.write “<img src= height=55 width=265><br>” & vbCrLf
objfile.write “<br>” & vbCrLf
objfile.write “<span style=’font-size: 7.5pt;color: #696969;’>Please consider </span><span style=’font-size: 7.5pt;color: #00b050;’>our environment</span><span style=’font-size: 7.5pt;color: #696969;’> before printing this email.</span></font><font color=696969 size=1 face=Verdana><br> ” & vbCrLf
objfile.write “<hr size=1 font align=left width=465 color=696969><span style=’font-size: 7.5pt;color: #696969;’>This email is intended for the intended recipients(s) and may contain confidential information. <br> Reproduction, dissemination or distribution of this message is prohibited unless authorised by the sender.<br> If you are not the intended recipient, please notify the sender immediately and you must not read,<br> keep, use, disclose, copy or distribute this email without the sender’s prior permission.<br> The views expressed by the sender are not necessarily those of Elcom Technology Pty Ltd</font></span></font>” & vbCrLf





‘ ===========================
‘ This section readsout the current Outlook profile and then sets the name of the default Signature
‘ ===========================
‘ Use this version to set all accounts
‘ in the default mail profile
‘ to use a previously created signature

Call SetDefaultSignature(“Elcom“,”")  — this appears in the outlook file as the signature name, change it to desired

‘ Use this version (and comment the other) to
‘ modify a named profile.
‘Call SetDefaultSignature _
‘ (“Signature Name”, “Profile Name”)

Sub SetDefaultSignature(strSigName, strProfile)
Const HKEY_CURRENT_USER = &H80000001
strComputer = “.”

If Not IsOutlookRunning Then
Set objreg = GetObject(“winmgmts:” & _
“{impersonationLevel=impersonate}!\\” & _
strComputer & “\root\default:StdRegProv”)
strKeyPath = “Software\Microsoft\Windows NT\” & _
“CurrentVersion\Windows ” & _
“Messaging Subsystem\Profiles\”
‘ get default profile name if none specified
If strProfile = “” Then
objreg.GetStringValue HKEY_CURRENT_USER, _
strKeyPath, “DefaultProfile”, strProfile
End If
‘ build array from signature name
myArray = StringToByteArray(strSigName, True)
strKeyPath = strKeyPath & strProfile & _
objreg.EnumKey HKEY_CURRENT_USER, strKeyPath, _
For Each subkey In arrProfileKeys
strsubkeypath = strKeyPath & “\” & subkey
objreg.SetBinaryValue HKEY_CURRENT_USER, _
strsubkeypath, “New Signature”, myArray
objreg.SetBinaryValue HKEY_CURRENT_USER, _
strsubkeypath, “Reply-Forward Signature”, myArray
strMsg = “Please shut down Outlook before ” & _
“running this script.” – this is the message when error occurs, change it to desired.

MsgBox strMsg, vbExclamation, “SetDefaultSignature”
End If
End Sub

Function IsOutlookRunning()
strComputer = “.”
strQuery = “Select * from Win32_Process ” & _
“Where Name = ‘Outlook.exe’”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” _
& strComputer & “\root\cimv2″)
Set colProcesses = objWMIService.ExecQuery(strQuery)
For Each objProcess In colProcesses
If UCase(objProcess.Name) = “OUTLOOK.EXE” Then
IsOutlookRunning = True
IsOutlookRunning = False
End If
End Function

Public Function StringToByteArray _
(Data, NeedNullTerminator)
Dim strAll
strAll = StringToHex4(Data)
If NeedNullTerminator Then
strAll = strAll & “0000″
End If
intLen = Len(strAll) \ 2
ReDim arr(intLen – 1)
For i = 1 To Len(strAll) \ 2
arr(i – 1) = CByte _
(“&H” & Mid(strAll, (2 * i) – 1, 2))
StringToByteArray = arr
End Function

Public Function StringToHex4(Data)
‘ Input: normal text
‘ Output: four-character string for each character,
‘ e.g. “3204″ for lower-case Russian B,
‘ “6500″ for ASCII e
‘ Output: correct characters
‘ needs to reverse order of bytes from 0432
Dim strAll
For i = 1 To Len(Data)
‘ get the four-character hex for each character
strChar = Mid(Data, i, 1)
strTemp = Right(“00″ & Hex(AscW(strChar)), 4)
strAll = strAll & Right(strTemp, 2) & Left(strTemp, 2)
StringToHex4 = strAll

End Function


Ok that’s the end of the code

Now on to how to implement it into AD.

First this is first, copy your .vbs to one of the domain controllers, We generally put
scripts in the following location (we do this so that the scripts are replicated through our AD servers, if you have multiple AD server I recommend putting it in the same place.

\\computername\SYSVOL\domain name\scripts\

You will need to ensure all your users that you are applying this to have the required fields complemented with in AD remember your variables, these are what you will need filled in (or at least what you use within the signature)

“& FullName &”
“& EMail &”
“& Company &”
“& Title &”
“& PhoneNumber &”
“& FaxNumber &”
“& OfficeLocation &”
“& StreetAddress &”
“& PostofficeBox &”
“& Department &”
“& ZipCode &”
“& Town &”
“& MobileNumber &”
“& web_address &”


Now you to the users that you are applying this script to you must have a GROUP POLICY that is applied to those users, if not create one, or just use the default domain policy.

open up that group policy you wish to apply this VBS to and then within the Group Policy Editor choose:

User configuration
  Windows Settings
      Scripts (logon/logoff)

double click on logon, you will see the below screen, you may not have anything in it just yet though, to add the location go to ‘Add’ and then simply browse to the location of the VBS. I am using a logon.bat because we have various logon scripts we execute, so we have complied it into just the one batch file that opens and executes all scripts.



Once you have added the file press OK.

That’s more or less all you need to do, however you might want to test it to do this you may want to force the GP to refresh

at the command line type ‘gpupdate /force’

then log off and then on, open outlook and test.


For any 2007 users if you find that after you run the script and then you or a user opens outlook after login and they revive the error message that from teh script saying that outlook is open, well there is a way around that too.

Go to your Group Policy management again

this time go to

User configuration
  Administrative Templates
          Run logo Scripts Scnchronously

Enable this!



If you are unsure about this, below is the description of what it is you are enabling




Hopefully this helps a few more people.

Good luck!

Leave a Reply