Signatures in Outlook RRS feed

  • Question

  • I`m just wondering if someone can help me with this. We are having difficulties with the scrept that previous IT guy created. Suddenly it gives us the following error:

    Script :


    ' NAME:     CreateOutlookSignature.vbs
    ' AUTHOR:     Tim Bosinius, Tractebel Gas Engineering GmbH
    ' DATE :     15.07.2005
    ' COMMENT:    This script will extract Active Directory user information and
    '            create Outlook HTML signatures based on a XSL template.
    '            It is designed to work on any windows machine that has ADSI, WSH
    '            and some XML version installed. In theory any Windows machine
    '            from Windows NT 4.0 (which DsClient & IE 6.0) and above.
    '            If AD isn't your first choice (well it should be, because you know
    '            for sure that if the user can log onto the network that script will
    '            work), you can easily modify it and use some database or whereever
    '            you get your user Information in XML form.
    '            I tried to make it as generic as possible, but modifications in
    '            in the XSL file are required. You need to change the registry
    '            for your Outlook version - see buttom for more details.
    '            There isn't any error checking included, which might be a good
    '            idea after all. I dropped it for the sake of readablity.
    '            If you ask yourself why I sometimes use a hungarian notation,
    '            and sometimes not - I cannot tell you. This is a habit that I developed
    '            over years. I basically only use it for strings and longs.
    '            There is one thing about the output HTML that I don't understand.
    '            In the XSL I use the following line:<xsl:text>   </xsl:text>
    '            this should be converted to   in HTML - but it will be a space in the
    '            output file. If you know where I made the mistake - pls let me know
    '            Anybody can use this script. It would be nice if you drop me a mail With
    '            your comments on the script.                 tb@tractebel.de
    ' Note from : use command parameters without switches to launch script
    ' usage: signature.vbs _Official signature.xsl
    ' will create a new signature called _Official using signature.xsl for format
    ' contact me with any questions: 
    Dim oShell
    Set oShell = WScript.CreateObject ("WSCript.shell")

    Dim strSigName, strXSL 'store values here
    Dim intCount 'use for counting 

    Set objArgs = WScript.Arguments
    For Each varArg in ObjArgs

    If (intCount=1) then
    msgbox varArg
    End If

    If (intCount=2) then
    'msgbox varArg
    End If


    Set oShell = Nothing

    Const adPersistXML = 1
    Const ForWriting = 2

    Const REGSIGKEY = "HKCU\Software\Microsoft\Office\10.0\Common\MailSettings\NewSignature"

    Dim XML,XSL, FSO
    Dim WshShell, WshNet, rsAD, Com, ConAD, f

    'We need to get details from attributes that are only available from the LDAP provider
    'We cannot assume that the AdsSecurity.DLL is available on the client to retrieve our DN

    'What we do know, is who we are (samaccountname) and that must be unique within a domain
    Set WshNet = WScript.CreateObject("WScript.Network")
    sUsername = WshNet.UserName

    'Wscript.Network knows the Netbios Domain, but we might not know our DNS domainname
    sPrefix = "LDAP://"
    Set cont = GetObject(sPrefix & "rootdse")
    sDN = cont.get("defaultnamingcontext")

    'Alright - we are now prep'd to do a little search to get our adspath...
    'We will open an ADO connection to AD
    Set conAD = WScript.CreateObject( "ADODB.Connection" )
    Set com = WScript.CreateObject( "ADODB.Command" )

    'set the provider
    conAD.Provider = "ADSDSOObject"
    ' Open a connection object
    conAD.Open "Active Directory Provider"
    Set Com.ActiveConnection = conAD

    'what do we want to find - well our details...
    sFilter = "(samaccountname=" & sUsername & ")"
    'what do we need to know?
    sAttributes = "givenname,sn,ipPhone,telephonenumber,mail,Streetaddress,l,st,postalcode,co,mobile,company,facsimileTelephoneNumber,title,department,wwwHomepage"

    'build the command string
    Com.CommandText = "<" & sPrefix & sDN & ">;" & sFilter & ";" & sAttributes

    ' Set some preferences for search
    Com.Properties( "Page Size" ) = 512
    Com.Properties( "TimeOut" ) = 30 ' seconds

    'Execute the query to get our objects from Active Directory.
    Set rsAD = CreateObject("ADODB.Recordset")
    Set rsAD = Com.Execute

    If (Err.Number <> 0) Then
        WScript.Echo Err.Number, "on Execute"
    End If
    'WScript.Echo "LDAP user objects:" & rsAD.RecordCount  'for testing
    Set xml = CreateObject("Microsoft.XMLDOM")
    rsAD.Save xml, adPersistXML
    XML.async = False

    Set xsl = CreateObject("Microsoft.XMLDOM")
    xsl.async = False
    'Load the XSL file. We keep it in the same path as the script, but it could be stored anyway. e.g. Webserver

    ' msgbox strXSL

    xsl.load "\\iservices\netlogon\signature.xsl" 

    xsl.preserveWhiteSpace = True
    'Lets Save the signature file to disk to the profile - we are aiming for the Outlook signature path
    Set WshShell = CreateObject("Wscript.Shell")

    'sUserProfile = WshShell.ExpandEnvironmentStrings("%UserProfile%")

    sUserProfile = WshShell.ExpandEnvironmentStrings("%appdata%") 

    sSignaturePath= sUserProfile & "\Microsoft\Signatures\"

    msgbox sSignaturePath

    sOutputfile = sSignaturePath & sUserName & ".htm"

    'sOutputfile = sSignaturePath & strSigName & ".htm"
    'msgbox sOutputfile

    Set FSO = CreateObject("Scripting.Filesystemobject")
    'create directory if it does not exist
    if (not FSO.FolderExists (sSignaturePath)) Then
    'create directory
    Set objFolder = FSO.CreateFolder(sSignaturePath)
    End if

    msgbox sOutputFile

    Set f = FSO.OpenTextFile(sOutputFile,ForWriting,True)
    f.Write XML.transformNode(xsl)

    'Make it the default signature, if no signature is set.
    'Now here I don't know how to make the office version generic.
    'The registrykey path depends on the version of Outlook. If you have PCs that have been upgraded,
    'or that run a mixture of Office 2000,XP,2003 - how do you easily find out which registrypath you should take?

    On Error Resume Next
    sRegKey = "" & WshShell.RegRead(REGSIGKEY)
    If sRegkey ="" Then
        WshShell.RegWrite REGSIGKEY, "AD_" & sUsername, "REG_SZ"
    End If
    On Error GoTo 0

    So the error is on this line:

    f.Write XML.transformNode(xsl)

    here is the XML template:

    <?xml version='1.0' encoding='utf-8'?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema" exclude-result-prefixes="rs z">
    method = "html"
    doctype-public = "-//W3C//DTD HTML 4.01 Transitional//EN"
    encoding = "UTF-8"
    indent = "yes"/>
    <xsl:template match="/">
                    <span style="font-size: 11pt; font-family: arial">
                        <xsl:value-of select="xml/rs:data/z:row/@givenname"/><![CDATA[ ]]>
                        <xsl:value-of select="xml/rs:data/z:row/@sn"/>
                    <span style="font-size: 10pt; font-family: arial">
                        <xsl:if test="xml/rs:data/z:row/@title">
                            <xsl:value-of select="xml/rs:data/z:row/@title"/>
                        <img src="\\192.168.100.xx\netlogon\logo.jpg" alt="3PI" style="width:128px;height:96px">
     			<i>Powering a <font color="#04B404"> Greener </font> Future</i>
                    <span style="font-size: 11pt; font-family: arial">
                            <xsl:when test="xml/rs:data/z:row/@company">
                                <xsl:value-of select="/xml/rs:data/z:row/@company"/>
                        <xsl:if test="xml/rs:data/z:row/@Streetaddress">
                            <xsl:value-of select="/xml/rs:data/z:row/@Streetaddress"/> -
                            <xsl:value-of select="xml/rs:data/z:row/@l"/><![CDATA[ ]]>
                            <xsl:value-of select="xml/rs:data/z:row/@st"/>,<![CDATA[ ]]>
    						<xsl:value-of select="/xml/rs:data/z:row/@postalcode"/> -
                            <xsl:value-of select="/xml/rs:data/z:row/@co"/>
    					<xsl:if test="xml/rs:data/z:row/@ipPhone !=''">
    						Office Direct: 
                                <xsl:value-of select="xml/rs:data/z:row/@ipPhone"/>
                            <xsl:when test="xml/rs:data/z:row/@telephonenumber">
                                <xsl:value-of select="xml/rs:data/z:row/@telephonenumber"/>
                                <xsl:if test="/xml/rs:data/z:row/@facsimileTelephoneNumber">
                                    <xsl:value-of select="/xml/rs:data/z:row/@facsimileTelephoneNumber"/>
                                Phone:      Fax: 
                        <xsl:if test="xml/rs:data/z:row/@mobile">Mobile:
                            <xsl:value-of select="/xml/rs:data/z:row/@mobile"/>
                            <xsl:when test="xml/rs:data/z:row/@wwwHomepage">
                                <a href="{xml/rs:data/z:row/@wwwHomepage}">
                                    <xsl:value-of select="/xml/rs:data/z:row/@wwwHomepage"/>
                                <a href="http://www..com">www..com</a>
                        <xsl:text>   </xsl:text>
                        <a href="mailto:{xml/rs:data/z:row/@mail}">
                            <xsl:value-of select="xml/rs:data/z:row/@mail"/>
                        <xsl:text>   </xsl:text>
    					<xsl:text>CONFIDENTIALITY NOTICE</xsl:text>
    					<xsl:text>This is electronic mail from 3PI and is intended only for the person(s) named above.  It may contain information that is confidential, privileged, and/or exempt from disclosure under applicable law. DO NOT READ THIS EMAIL IF YOU ARE NOT THE INTENDED RECIPIENT.  If you are not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is STRICTLY PROHIBITED.  If you receive this communication in error, please notify us immediately by email and destroy the original transmission and its attachments), if any, without reading or saving in any manner.</xsl:text>	


    Thursday, April 30, 2015 2:05 PM