Page 1 of 1 1
Topic Options
#204544 - 2012-03-22 05:49 PM Setting Outlook Signature from Kix script
andy_neenan Offline
Just in Town

Registered: 2012-03-15
Posts: 4
Loc: England
Hi all,

I have inherited ownership of a Kix login script on our work domain, and need to make some slight modifications.

This is the current script for the Outlook signature section

 Quote:
;Set outlook email signature
;

? " "
? "SET EMAIL SIGNATURE"
? " "
$appData = ExpandEnviromentVars(%appdata%)
DEL $appData + "\Microsoft\Signatures\AD Signature.*" /c /f

$objSysInfo = CreateObject("ADSystemInfo")
$strUser = $objSysInfo.UserName
$objUser = GetObject("LDAP://" + $strUser)
$strName = $objUser.FullName
$strTitle = $objUser.Title
$strDepartment = $objUser.Department
$strCompany = $objUser.Company
$strPhone = $objUser.telephoneNumber
$strMail = $objUser.mail
$strMobile = $objUser.mobile
$strFax = $objUser.facsimileTelephoneNumber
$strPost = $objUser.postalCode
$strStreet = $objUser.streetAddress
$strStreet = REPLACE($strStreet, CHR(10), " ")
$strStreet = REPLACE($strStreet, CHR(11), " ")
$strStreet = REPLACE($strStreet, CHR(12), " ")
$strStreet = REPLACE($strStreet, CHR(13), " ")
$strCity = $objUser.l
$strOffice = $objUser.physicalDeliveryOfficeName
$strWebsite = $objUser.wWWHomePage
$strAddress = $strStreet + " " + $strCity + " " + $strPost

$objWord = CreateObject("Word.Application")

$objDoc = $objWord.Documents.Add()
$objSelection = $objWord.Selection

$objEmailOptions = $objWord.EmailOptions
$objSignatureObject = $objEmailOptions.EmailSignature
$objSignatureEntries = $objSignatureObject.EmailSignatureEntries

$objSelection.Font.Name = "Arial"
$objSelection.Font.Size = "9"
$objSelection.Font.Bold = "1"
$objSelection.Font.Color = "6710886"
$objSelection.TypeText($strName)
$objSelection.TypeText(Chr(11))
$objSelection.TypeText($strTitle)
$objSelection.Font.Size = "8"
$objSelection.TypeText(Chr(11))
$objSelection.TypeText(Chr(11))
$objSelection.TypeText($strCompany)
$objSelection.TypeText(Chr(11))
$objSelection.Font.Bold = "0"
$objSelection.TypeText($strAddress)
$objSelection.TypeText(Chr(11))
if $strPhone <> ""
$objSelection.TypeText("T: " + $strPhone)
$objSelection.TypeText(Chr(11))
endif
if $strMobile <> ""
$objSelection.TypeText("M: " + $strmobile)
$objSelection.TypeText(Chr(11))
endif
if $strWebsite <> ""
$objSelection.TypeText("W: " + $strWebsite)
endif

$objSelection = $objDoc.Range()

$objSignature=$objSignatureEntries.Add("AD Signature", $objSelection)
$objSignatureObject.NewMessageSignature = "AD Signature"
$objSignatureObject.ReplyMessageSignature = "AD Signature"

$objDoc.Saved = 1
$objWord.Quit


I have two additions I need to make

1. If a user is in a certain AD container or group (e.g. IT), I want the script to only input the users NAME and job title, and then some set text that is to be defined in the script.

2. As you can see from the script, it sets the created signature as both the New and Reply signature. I need the script to set a Reply signature that includes only the Users name and job title.

Is the above possible?

Any help is greatly appreciated

Thanks

Top
#204545 - 2012-03-22 06:12 PM Re: Setting Outlook Signature from Kix script [Re: andy_neenan]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Hi Andy,

I'm using a similar style script for our outlook sigs. In our environment it contains some features requested by the marketing department and required by company policy like adding a marketing banner, disclaimer text, etc...
We had some issues at first with Word taking some time to close and the script started the next line before Word had actually fully shutdown so I placed a short sleep for half a second just after $objWord.Quit to allow Word to close. After the sleep I call the EnumProccess UDF to see if Word is still running and kill it if it is.

Below is and example of what you could do. I did not test the code so run some tests first.
 Code:

;Set outlook email signature
;

? " "
? "SET EMAIL SIGNATURE"
? " "
$appData = ExpandEnviromentVars(%appdata%)
Del $appData + "\Microsoft\Signatures\AD Signature.*" /c /f

$objSysInfo = CreateObject("ADSystemInfo")
$strUser = $objSysInfo.UserName
$objUser = GetObject("LDAP://" + $strUser)
$strName = $objUser.FullName
$strTitle = $objUser.Title
$strDepartment = $objUser.Department
$strCompany = $objUser.Company
$strPhone = $objUser.telephoneNumber
$strMail = $objUser.mail
$strMobile = $objUser.mobile
$strFax = $objUser.facsimileTelephoneNumber
$strPost = $objUser.postalCode
$strStreet = $objUser.streetAddress
$strStreet = REPLACE($strStreet, Chr(10), " ")
$strStreet = REPLACE($strStreet, Chr(11), " ")
$strStreet = REPLACE($strStreet, Chr(12), " ")
$strStreet = REPLACE($strStreet, Chr(13), " ")
$strCity = $objUser.l
$strOffice = $objUser.physicalDeliveryOfficeName
$strWebsite = $objUser.wWWHomePage
$strAddress = $strStreet + " " + $strCity + " " + $strPost


;Start creating long sig
$objWord = CreateObject("Word.Application")
$objDoc = $objWord.Documents.Add()
$objSelection = $objWord.Selection
$objEmailOptions = $objWord.EmailOptions
$objSignatureObject = $objEmailOptions.EmailSignature
$objSignatureEntries = $objSignatureObject.EmailSignatureEntries
$objSelection.Font.Name = "Arial"
$objSelection.Font.Size = "9"
$objSelection.Font.Bold = "1"
$objSelection.Font.Color = "6710886"
If InGroup("ITPeople")
	$objSelection.TypeText($strName)
	$objSelection.TypeText(Chr(11))
	$objSelection.TypeText($strTitle)
	$objSelection.TypeText(Chr(11))
	$objSelection.TypeText("Put whatever text you want here")
Else
	$objSelection.TypeText($strName)
	$objSelection.TypeText(Chr(11))
	$objSelection.TypeText($strTitle)
	$objSelection.Font.Size = "8"
	$objSelection.TypeText(Chr(11))
	$objSelection.TypeText(Chr(11))
	$objSelection.TypeText($strCompany)
	$objSelection.TypeText(Chr(11))
	$objSelection.Font.Bold = "0"
	$objSelection.TypeText($strAddress)
	$objSelection.TypeText(Chr(11))
	If $strPhone <> ""
		$objSelection.TypeText("T: " + $strPhone)
		$objSelection.TypeText(Chr(11))
	EndIf
	If $strMobile <> ""
		$objSelection.TypeText("M: " + $strmobile)
		$objSelection.TypeText(Chr(11))
	EndIf
	If $strWebsite <> ""
		$objSelection.TypeText("W: " + $strWebsite)
	EndIf
EndIf

$objSelection = $objDoc.Range()

$objSignature = $objSignatureEntries.Add("New message sig", $objSelection)
$objSignatureObject.NewMessageSignature = "New message sig"
$objDoc.Saved = 1
$objWord.Quit


;Start creating short sig.
$objWord = CreateObject("Word.Application")
$objDoc = $objWord.Documents.Add()
$objSelection = $objWord.Selection
$objEmailOptions = $objWord.EmailOptions
$objSignatureObject = $objEmailOptions.EmailSignature
$objSignatureEntries = $objSignatureObject.EmailSignatureEntries
$objSelection.Font.Name = "Arial"
$objSelection.Font.Size = "9"
$objSelection.Font.Bold = "1"
$objSelection.Font.Color = "6710886"
$objSelection.TypeText($strName)
$objSelection.TypeText(Chr(11))
$objSelection.TypeText($strTitle)
If InGroup("ITpeople")
	$objSelection.TypeText(Chr(11))
	$objSelection.TypeText("Put whatever text you want here")
EndIf
$objSignature = $objSignatureEntries.Add("Reply message sig", $objSelection)
$objSignatureObject.ReplyMessageSignature = "Reply message sig"
$objDoc.Saved = 1
$objWord.Quit
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#204643 - 2012-04-05 04:59 PM Re: Setting Outlook Signature from Kix script [Re: Mart]
andy_neenan Offline
Just in Town

Registered: 2012-03-15
Posts: 4
Loc: England
Hi Mart,

Thanks very much for your help with this, and apologies for the delay.

I have now inserted your script into a test script, replacing the relevant section in my original script. I added my unique info, and set up a test user in the relevant group and logged in with it on a domain machine. Nothing else within the script has changed.

I am now getting errors on login using the test user and test script about "error: error in use statement" on lines PRIOR to the new code being inserted.

Would there be a reason for this? I am still fairly new to these login scripts so any assistance in troubleshooting this would be great.

Thanks

Andy

**EDIT** - Found the problem

@HOMESHR was the line previous to the new signature script - it wasnt defined on the AD profile - now working.

The Reply signature doesnt work yet though - looking into that as we speak.

Thanks again


Edited by andy_neenan (2012-04-05 05:16 PM)

Top
#204644 - 2012-04-05 05:01 PM Re: Setting Outlook Signature from Kix script [Re: andy_neenan]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Please post your code. Otherwise it is all guesses.
Top
#204648 - 2012-04-05 08:27 PM Re: Setting Outlook Signature from Kix script [Re: andy_neenan]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
You probably have a syntax error - missing quote or mismatched pair of tokens. Fastest way to locate this is with the SANITY UDF, (posted here, requires some glue code to use) or simply download the KixDev package from my web site.

With KGen, just rename your script to a .TXT file extension and type KGEN Scriptname. It will copy the file back to the .KIX file and then analyze it for all kinds of issues. It will report the line on which the issue occurred, and create several report files. The most useful for diagnosing is a "map" of all the paired statements, indented so you can easily match the start and end of each pair. Only the first few characters are displayed along with the line number.

I write nearly every script using KGen.. it automatically locates and includes the UDF files from my library for me and finds most issues before I ever run the script.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (mole) and 494 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.029 seconds in which 0.012 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org