Signature Automation on a budget of $0

Signature Automation on a budget of $0

Signature

Ok, time for another low effort post on how to do something. This time it’s how to automate signatures for users of Outlook (2010, 2013, 2016) against information pulled from AD. There’s countless better ways to do this but this is an old script I wrote literally years ago that’s still in use at several of my clients. As I had to update it, today, I figured I’d post it to the world, for ridicule and also to maybe help someone. It’s VBScript, because it’s that old.

Step 1 – Get a copy of the signature template.

This isn’t hard, just make the signature in Outlook as you’d like it to be, then go to %appdata%\microsoft\signatures and pick up the .htm (yes, it’s Microsoft so there’s no “”l” at the end of that file) and the associated folder of the same name, with _files at the end of it. Copy these to \\domaincontroller\netlogon\signatures\ or some other directory that everyone in the domain can read from.

Step 2 – Edit the template

Now we have the template, go through it and modify it, by removing the real names, phone numbers, emails, etc. and replacing them with $NAME, $EMAIL, etc. as per this list:

  • $NAME
  • $FIRSTNAME
  • $DESC
  • $DEPT
  • $ROLE
  • $PHONE
  • $EMAIL
  • $MOBILE
  • $STREET
  • $PCODE
  • $CITY

Now, obviously, make sure those fields (or the ones you care about) are populated in Active Directory for the users who want automated signatures.

Now just put the VBScript as below in \\domaincontroller\netlogon\sig\ or wherever you need to put it. As always, please check how this cut-and-pastes into your editor, as some quotations marks may be changed by your browser.

Const OverwriteExisting = TRUE

Const ForReading = 1

Const HKEY_CURRENT_USER   = &H80000001

on error resume next

set objNetwork = CREATEOBJECT("wscript.network")

strADsPath = getUser(objNetwork.Username)

Set objSysInfo = CreateObject("ADSystemInfo")

'set objUser = GetObject("LDAP://" & objSysInfo.UserName)

set objUser = GetObject(strADsPath) 

Function WriteReg(RegPath, Value, RegType)

      Dim objRegistry, Key

      Set objRegistry = CreateObject("Wscript.shell")

      Key = objRegistry.RegWrite(RegPath, Value, RegType)

      WriteReg = Key

End Function

Function ReadReg(RegPath)

      Dim objRegistry, Key

      Set objRegistry = CreateObject("Wscript.shell")

      Key = objRegistry.RegRead(RegPath)

      ReadReg = Key

End Function

function getUser(BYVAL UserName)

' Function to return the ADsPath from a username (sAMAccountName)

' e.g. LDAP://cn=user1,cn=users,dc=wisesoft,dc=co,dc=uk

dim objRoot

dim getUserCn,getUserCmd,getUserRS

on error resume next

set objRoot = GETOBJECT("LDAP://RootDSE")

set getUserCn = CREATEOBJECT("ADODB.Connection")

set getUserCmd = CREATEOBJECT("ADODB.Command")

set getUserRS = CREATEOBJECT("ADODB.Recordset")

getUserCn.open "Provider=ADsDSOObject;"

getUserCmd.activeconnection=getUserCn

getUserCmd.commandtext="<LDAP://" & objRoot.GET("defaultNamingContext") & ">;" & _

"(&(objectCategory=user)(sAMAccountName=" & username & "));" & _

"adsPath;subtree"

set getUserRs = getUserCmd.EXECUTE

if not rs.BOF and not rs.EOF then

getUserRs.MoveFirst

getUser = getUserRs(0)

else

getUser = ""

end if

getUserCn.close

end function

function FindAndReplace(strFilename, strFind, strReplace)

wscript.echo strFilename

    Set inputFile = CreateObject("Scripting.FileSystemObject").OpenTextFile(strFilename, 1)

    strInputFile = inputFile.ReadAll

    inputFile.Close

    Set inputFile = nothing

    Set outputFile = CreateObject("Scripting.FileSystemObject").OpenTextFile(strFilename,2,true)

    outputFile.Write Replace(strInputFile, strFind, strReplace)

    outputFile.Close

    Set outputFile = nothing

end function

Set oShell = CreateObject("WScript.Shell")

strHomeFolder = oShell.ExpandEnvironmentStrings("%APPDATA%")

Set objFSO = CreateObject("Scripting.FileSystemObject")

set tmp = objFSO.CreateFolder (strHomeFolder & "\Microsoft\signatures" )

path = "\\domaincontroller\NETLOGON\sig\"

subgroup = "name-of-htm-file"

Set colFiles = objFolder.Files

Set objNet = CreateObject("WScript.NetWork")

Set fso = CreateObject("Scripting.FileSystemObject")

'************************************************START NEW EMAIL SIGNATURE

'Copy the core new email signature

fso.CopyFile path & "" & subgroup & ".htm", strHomeFolder & "\Microsoft\signatures\"

'Check if the we've done this in the past before moving on.

if not (FSO.FolderExists(strHomeFolder & "\Microsoft\signatures\" & subgroup & "_files\")) then

fso.CreateFolder strHomeFolder & "\Microsoft\signatures\" & subgroup & "_files\"

end if

fso.CopyFile path & "" & subgroup & "_files\colorschememapping.xml", strHomeFolder & "\Microsoft\signatures\" & subgroup & "_files\" 

fso.CopyFile path & "" & subgroup & "_files\filelist.xml", strHomeFolder & "\Microsoft\signatures\" & subgroup & "_files\"

fso.CopyFile path & "" & subgroup & "_files\image001.png", strHomeFolder & "\Microsoft\signatures\" & subgroup & "_files\"

fso.CopyFile path & "" & subgroup & "_files\themedata.thmx", strHomeFolder & "\Microsoft\signatures\" & subgroup & "_files\"

'Replace placeholders with actual content from Active Directory.

FindAndReplace strHomeFolder & "\Microsoft\signatures\" & subgroup & ".htm","$NAME",objUser.displayName

FindAndReplace strHomeFolder & "\Microsoft\signatures\" & subgroup & ".htm","$FIRSTNAME",objUser.givenName

FindAndReplace strHomeFolder & "\Microsoft\signatures\" & subgroup & ".htm","$DESC",objUser.description

FindAndReplace strHomeFolder & "\Microsoft\signatures\" & subgroup & ".htm","$DEPT",objUser.department

FindAndReplace strHomeFolder & "\Microsoft\signatures\" & subgroup & ".htm","$ROLE",objUser.Title

FindAndReplace strHomeFolder & "\Microsoft\signatures\" & subgroup & ".htm","$PHONE",objUser.ipPhone

FindAndReplace strHomeFolder & "\Microsoft\signatures\" & subgroup & ".htm","$EMAIL",objUser.mail

FindAndReplace strHomeFolder & "\Microsoft\signatures\" & subgroup & ".htm","$MOBILE",objUser.mobile

FindAndReplace strHomeFolder & "\Microsoft\signatures\" & subgroup & ".htm","$STREET",objUser.streetAddress

FindAndReplace strHomeFolder & "\Microsoft\signatures\" & subgroup & ".htm","$PCODE",objUser.postalCode

FindAndReplace strHomeFolder & "\Microsoft\signatures\" & subgroup & ".htm","$CITY",objUser.l

'Force the changes to the default signatures for Office 2010 (14.0) and 2013 (15.0) in the registry

Temp = WriteReg("HKCU\Software\Microsoft\Office\14.0\Common\MailSettings\NewSignature","" & subgroup & "","REG_EXPAND_SZ")

Temp = WriteReg("HKCU\Software\Microsoft\Office\15.0\Common\MailSettings\NewSignature","" & subgroup & "","REG_EXPAND_SZ")

'************************************************END NEW EMAIL SIGNATURE

'************************************************START REPLY SIGNATURE

'Force the changes to the default signatures for Office 2010 (14.0) and 2013 (15.0) in the registry

Temp = WriteReg("HKCU\Software\Microsoft\Office\14.0\Common\MailSettings\ReplySignature","" & subgroup & "","REG_EXPAND_SZ")

Temp = WriteReg("HKCU\Software\Microsoft\Office\15.0\Common\MailSettings\ReplySignature","" & subgroup & "","REG_EXPAND_SZ")

'************************************************END REPLY SIGNATURE

 

Now call it with a .cmd file:

cscript \\domaincontroller\netlogon\sig\updateSignature.cmd

Then just call that CMD file as a logon script in AD.

Now every time a user logs in, their signature will be updated against the information in AD. If you uncomment those registry keys at the bottom of the file, it will force the new / reply signatures to be the default AND block them from editing them.

There you go – signature automation on a budget of $0.

About the Author

Rodney

I’m a veteran of way too many years of IT (although I still love it) and I currently head up the techincal work over at Host One (major sponsor of this site), where I’m also a partner. Feel free to ask me anything about Cloud Computing and I’ll try to be helpful, in a non-salesy kind of way.

View all posts by Rodney →

Leave a Reply

Time limit is exhausted. Please reload CAPTCHA.