1st Real Project Posted BTW
*edit: had to reattach attachment. Working on explaining how to edit the setsignature.xml
Purpose: To standardize a signature for all users using data from Active Directory. This script also includes adding signatures to Outlook Web Access (OWA). Settings can also be changed for both Outlook and OWA, this can include default message type (HTML, Rich Text, Text), default signature used, OWA timezone settings, ect... This script is meant to be ran within the login script to setup each user's signature.
Versions:
0.5 Initial Release 7-19-2006: Includes ability to change Outlook and OWA signatures. Ability to change settings in both Outlook and OWA.
Explaination of files included in the zip file:
EmailSig.au3: AutoIT script
ExCmd.exe : is from HERE. I have contacted the author and he has stated it is freeware. Feel free to scan it, prod it, whatever, I trust the source and have not seen any unwanted results from using it. It is simply a WEBDAV command line utility.
getproperty.xml : is from the above site as well, it is used to replace variables before sending the command to the exchange server. Typically used to get the value of a property.
setproperty.xml : is from the above site as well, it is used to replace variables before sending the command to the exchange server. Typically used to set the value of a property.
setsignature.xml : is from the above site as well, it is used to replace variables before sending the command to the exchange server. Typically used to set the value of the signaturehtml field.
Here is the code for anyone interested, I am still refining it, and welcome any suggestions on how to improve any portion of the code.
#include <GUIConstants.au3> #include <Misc.au3> #include <File.au3> #include <Process.au3> #include <Constants.au3> #include <string.au3> Dim $UserObj DIM $sigpath = ( @AppDataDir &'\microsoft\signatures' ) Dim $msg Dim $msg1 Dim $domain = @LogonDomain ;pulls domain that user is logged into Dim $username = @UserName ;pulls username that is logged in Const $ADS_NAME_INITTYPE_GC = 3 Const $ADS_NAME_TYPE_NT4 = 3 Const $ADS_NAME_TYPE_1779 = 1 $oMyError = ObjEvent("AutoIt.Error", "ComError") $objRootDSE = ObjGet("LDAP://RootDSE") ; DNS domain name. $objTrans = ObjCreate("NameTranslate") $objTrans.Init ($ADS_NAME_INITTYPE_GC, "") $objTrans.Set ($ADS_NAME_TYPE_1779, @LogonDomain) $objTrans.Set ($ADS_NAME_TYPE_NT4, @LogonDomain & "\" & @UserName) $strUserDN = $objTrans.Get ($ADS_NAME_TYPE_1779) $UserObj = ObjGet("LDAP://" & $strUserDN) DIM $fullname = $UserObj.FullName DIM $department = $UserObj.Department DIM $streetaddress = $UserObj.get("streetAddress") DIM $city = $UserObj.get("l") DIM $state = $UserObj.get("st") DIM $zipcode = $UserObj.PostalCodes DIM $country = $UserObj.get("c") DIM $emailaddress = $UserObj.EmailAddress DIM $officenumber = $UserObj.TelephoneNumber DIM $mobilenumber = $UserObj.TelephoneMobile DIM $faxnumber = $UserObj.FaxNumber DIM $homeMDB = $UserObj.get("homeMDB") Dim $homeMDBtext = StringSplit($homeMDB, ",") Dim $mailboxname = StringTrimLeft($homeMDBtext[4], 3) Dim $salutation = ("Best Regards,") Dim $Disclaimer = ("Disclaimer here") Dim $Defaultsigname = ("test") Dim $sightm = ("test.html") Dim $siggif = ("testgif.html") Dim $sigtxt = ("test.txt") If FileExists ( $sigpath &'\'& $sightm) Then ;checks to see if the htm version of the signature is there returns '1'=exist '0'=does not exist Exit EndIf If FileExists ( $sigpath &'\'& $siggif) Then ;checks to see if the htm version with a gif image embedded in the signature is there returns '1'=exist '0'=does not exist Exit EndIf If FileExists ( $sigpath &'\'& $sigtxt) Then ;checks to see if the txt version of the signature is there returns '1'=exist '0'=does not exist Exit EndIf call ("regsig") call ("gifsig") call ("textsig") call ("SigRegisty") call ("OWAsig") call ("OWATimeZone") Func OWATimeZone (); Sets timezone to equal what is on the users PC Dim $timezone = RegRead ("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation", "StandardName") Run(@ComSpec & " /c " & 'ExCmd proppatch http://'& $mailboxname &'.'& $domain &'/exchange/'& $username &' /c:setproperty.xml ns="http://schemas.microsoft.com/exchange/" name="timezone" value="'& $timezone &'"', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) EndFunc Func OWAsig () FileInstall (@ScriptDir &"\ExCmd.exe", @ScriptDir &"\ExCmd.exe") FileInstall (@ScriptDir &"\setsignature.xml", @ScriptDir &"\setsignature.xml") FileInstall (@ScriptDir &"\setproperty.xml", @ScriptDir &"\setproperty.xml") FileInstall (@ScriptDir &"\getproperty.xml", @ScriptDir &"\getproperty.xml") $filename = (@ScriptDir &"\setsignature.xml") ;Replaces Salutation $find = "<salutation>" $replace = ""& $salutation $retval = _ReplaceStringInFile($filename,$find,$replace) ;Replaces Fullname $find = "<fullname>" $replace = ""& $fullname $retval = _ReplaceStringInFile($filename,$find,$replace) ;Replaces the Department $find = "<department>" $replace = ""& $department $retval = _ReplaceStringInFile($filename,$find,$replace) ;Replaces the Office Number $find = "<officenumber>" $replace = ""& $officenumber $retval = _ReplaceStringInFile($filename,$find,$replace) ;Replaces the Mobile Number $find = "<mobilenumber>" $replace = ""& $mobilenumber $retval = _ReplaceStringInFile($filename,$find,$replace) ;Replaces the email address $find = "<emailaddress>" $replace = ""& $emailaddress $retval = _ReplaceStringInFile($filename,$find,$replace) ;Replaces the Street Address $find = "<streetaddress>" $replace = ""& $streetaddress $retval = _ReplaceStringInFile($filename,$find,$replace) ;Replaces the City $find = "<city>" $replace = ""& $city $retval = _ReplaceStringInFile($filename,$find,$replace) ;Replaces the state $find = "<state>" $replace = ""& $state $retval = _ReplaceStringInFile($filename,$find,$replace) ;Replaces the zipcode $find = "<zipcode>" $replace = ""& $zipcode $retval = _ReplaceStringInFile($filename,$find,$replace) ;Replaces the country $find = "<country>" $replace = ""& $country $retval = _ReplaceStringInFile($filename,$find,$replace) ;Replaces Disclaimer $find = "<disclaimer>" $replace = ""& $Disclaimer $retval = _ReplaceStringInFile($filename,$find,$replace) $foo = Run (@ComSpec & " /c " & 'ExCmd proppatch http://'& $mailboxname &'.'& $domain &'/exchange/'& $username &' /c:setsignature.xml ns="http://schemas.microsoft.com/exchange/" name="signaturehtml"', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;Testing purposes only ;Dim $foo1 = Run(@ComSpec & " /c " & 'exCmd propfind http://'& $mailboxname &'.'& $domain &'/exchange/'& $username &' /c:getproperty.xml ns="http://schemas.microsoft.com/exchange/" name="signaturehtml"', "", @SW_SHOW, $STDERR_CHILD + $STDOUT_CHILD) ;~ While 1 ;~ $line = StdoutRead($foo) ;~ If @error = -1 Then ExitLoop ;~ FileWrite ("C:\test.txt", $line &"") ;~ MsgBox(64, "STDOUT read:", $line) ;~ ;~ Wend ;~ While 1 ;~ $line = StdoutRead($foo1) ;~ If @error = -1 Then ExitLoop ;~ FileWrite ("C:\test.txt", $line &"") ;~ MsgBox(64, "STDOUT read:", $line) ;~ ;~ Wend EndFunc Func regsig () $filename1 = $sigpath & "\test.htm" $msg1 &= "<HTML><HEAD><TITLE>test Signature</TITLE>"& @CRLF $msg1 &= "<BODY>"& @CRLF $msg1 &= "<DIV align=left><FONT face=Arial size=2>"& $salutation &"</FONT></DIV>"& @CRLF $msg1 &= "<DIV align=left> </DIV>"& @CRLF $msg1 &= "<DIV align=left><FONT face=Arial size=2></FONT> </DIV>"& @CRLF $msg1 &= "<DIV align=left><FONT size=2><FONT face=Arial><STRONG><FONT" & @CRLF $msg1 &= "color=#808080>"& $fullname &"</FONT></STRONG> <STRONG><FONT " & @CRLF $msg1 &= "color=#808080>"& $department &"</FONT></STRONG></FONT></FONT></DIV>" & @CRLF $msg1 &= "<EM>technologies</EM></FONT></FONT></DIV>"& @CRLF $msg1 &= "<DIV align=left><FONT face=Arial size=2><STRONG>T:</STRONG> "& $officenumber &" <STRONG>M:</STRONG></FONT> "& $mobilenumber &" </DIV>"& @CRLF $msg1 &= "<DIV align=left><FONT face=Arial size=2><a href='mailto:"& $emailaddress &"'> "& $emailaddress &"</a> "& $streetaddress &" "& $city &", "& @CRLF $msg1 &= ""& $state &" "& $zipcode &" "& $country &"</FONT></DIV><FONT face='Arial' size=3></FONT><I><FONT color=#808080 size=1>"& $Disclaimer &"</FONT></DIV></I></BODY></HTML>" FileWrite($filename1, $msg1 );Writes the text to the html file EndFunc Func gifsig () $filename = $sigpath & "\testgif.htm" FileInstall(@ScriptDir &"\smalllogo2.gif", $sigpath & '\smalllogo2.gif') $msg &= "<HTML><HEAD><TITLE>test Signature with GIF</TITLE>"& @CRLF $msg &= "<BODY>"& @CRLF $msg &= "<DIV align=left><FONT face=Arial size=2>"& $salutation &"</FONT></DIV>"& @CRLF $msg &= "<DIV align=left> </DIV>"& @CRLF $msg &= "<DIV align=left><FONT face=Arial size=2></FONT> </DIV>"& @CRLF $msg &= "<DIV align=left><FONT size=2><FONT face=Arial><STRONG><FONT" & @CRLF $msg &= "color=#808080>"& $fullname &"</FONT></STRONG> <STRONG><FONT " & @CRLF $msg &= "color=#808080>"& $department &"</FONT></STRONG></FONT></FONT></DIV>" & @CRLF $msg &= "<DIV align=left><FONT size=2><FONT face=Arial> <STRONG><FONT color=#808080><IMG alt='' hspace=0 src='"& $sigpath & "\smalllogo2.gif' align=baseline border=0></FONT></STRONG></FONT></FONT> $msg &= "<DIV align=left><FONT face=Arial size=2><STRONG>T:</STRONG> "& $officenumber &" "& @CRLF $msg &= " <a href='mailto:"& $emailaddress &"'> "& $emailaddress &"</a> "& $streetaddress &" "& $city &", "& @CRLF $msg &= ""& $state &" "& $zipcode &" "& $country &"</FONT></DIV>"& @CRLF $msg &= "<DIV align=left><I><FONT face=Arial color=#808080 size=1>"& $Disclaimer &"</FONT></DIV></I></BODY></HTML>" FileWrite($filename, $msg );Writes the text to the html file EndFunc Func textsig () ;Text file creation $filename = $sigpath & "\test.txt" $msg = ""& $salutation & @CRLF $msg &= @CRLF $msg &= @CRLF $msg &= ""& $fullname &" "& $department &"" & @CRLF $msg &= "T: "& $officenumber &" M: "& $mobilenumber &" "& @CRLF $msg &= ""& $emailaddress &" "& $streetaddress &" "& $city &", "& $state &" "& $zipcode &" "& $country &"" & @CRLF $msg &= ""& $Disclaimer FileWrite($filename, $msg );Writes the text to the file EndFunc Func SigRegisty ();Changes registry settings for Outlook $var = RegRead ("HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Options\Mail\", "EditorPreference") if $var = 131072 Then Else RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Options\Mail\", "EditorPreference", "REG_DWORD", "131072");Changes the default format for outgoing messages to HTML EndIf ;Working on adding a string to HEX conversion for the name of the default signature, ;Writes NEW Signature as the default signature (Requires Restart of Outlook to take affect). Set your signature and drill down in the resgistry to find the HEX value for the signature name RegWrite ("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\%profilename%\9375CFF0413111d3B88A00104B2A6676\00000001", "New Signature", "REG_BINARY", "%HEX Signature name with 00 between each letter and trailing 0000000%") EndFunc ;COM Error function Func ComError() If IsObj($oMyError) Then $HexNumber = Hex($oMyError.number, 8) SetError($HexNumber) Else SetError(1) EndIf Return 0 EndFunc ;==>ComError
Attached Files
Edited by joshiieeii, 26 July 2006 - 01:36 AM.






