Generating Outlook Signatures Based on Active Directory Information - Checking for Existing Signature File
(Page 2 of 4 )
Before we start to create anything, it's always a good idea to do a couple of checks first. First of all, let's make sure the signature directory exists before trying to create anything in it -- if it's not there, then create it:
'check the existence of the sig dir, if not there create it
if not FileSysObj.FolderExists(SigFolder) then
FileSysObj.CreateFolder(SigFolder)
end if
These lines use the File system object we created at the start of the script to check for the existence of the signature folder. If that check returns false, then we create it using the file system object again.
The next thing we are going to do is work out if we actually need to go through the process of creating the signature.
We will do this by first checking for the existence of the signature file, then seeing if the last modified date of the file is before the last modified date of the user. If the user has changed since the file was created, we need to create the file again, otherwise we don't need to bother. The following section of code accomplishes this task:
if FileSysObj.FileExists(SigFile) then
'get amended date of file, then compare it to the changed date of the user
Set objFile = FileSysObj.GetFile(SigFile)
datSigAlt = objFile.DateLastModified
intTimeDiff = DateDiff("n", datSigAlt, UserObj.whenChanged)
'if the difference is less than 0 then we do not need to do anything as the sig file is uptodate
if intTimeDiff < 0 then wscript.Quit
end if
Once we know if the signature file exists, we get a handle on it and find out the last time it was modified. Once we know this, we compare in minutes to the last time the user object in the active directory was modified. If the difference is less than zero (0), then the script must be up-to-date, so we don't need to do anything and can just quit the script.
If we are still running at this point, it's time to create the signature file.
Getting the information for the signature file
Before going headlong into creating the file, it's a good idea to first know what you want in it. The example I am going to use will contain simple contact details (name, position, address, telephone, fax, email, and website), a company logo graphic, and a link to some terms and conditions. Your requirements, however, might be different. So how do you know what all the fields in the active directory user object are called?
Well, there is a little app available from Microsoft, called ADSIEdit, that comes with the Windows 2003 support tools. Using this app, you can browse your domain, and see all the objects in it.
If you right click on an object and view its properties, you can see a list of all the available attributes and their current values. You can pick up any of these attributes and insert them into your signature.
Next: Creating the signature >>
More Windows Scripting Articles
More By Luke Niland