Solved

Outlook Signature Script Error

Posted on 2013-05-17
5
606 Views
Last Modified: 2013-05-28
We have a outlook signature script that runs every time a user logs on a computer. The script runs flawlessly unless it is their first time logging on the computer. If it is their first time the script gives an error (attached). Is there a way of creating the signature directory without running outlook? It looks like the script will fail unless the user has a outlook profile on the computer. This particuarly happens in meeting rooms where the user doesn't normally login. I also attached the script for reference.

Thanks!
OutlookSig1-Example.vbs
Script-Error.PNG
0
Comment
Question by:ICCNetworkAdmin
5 Comments
 
LVL 6

Expert Comment

by:Alan Gunn
ID: 39175139
What a cool script!

Unfortunatley, as you surmise, the registry won't contain the required keys until the user logs on and starts Outlook.

If you have a domain and central storage of some kind you could set up roaming profiles.

In this scenario, the "User" registry keys and potentially other specific folders are stored centrally and are applied to each machine that the user logs into.

Could be worth a look. :-)

Cheers!

TRM
0
 
LVL 79

Accepted Solution

by:
David Johnson, CD, MVP earned 250 total points
ID: 39175357
Here is the modified script
 Set objUser = CreateObject("WScript.Network")
userName = objUser.UserName
domainName = objUser.UserDomain 

FUNCTION GetUserDN(BYVAL UN, BYVAL DN)
Set ObjTrans = CreateObject("NameTranslate")
objTrans.init 1, DN
objTrans.set 3, DN & "\" & UN
strUserDN = objTrans.Get(1)
GetUserDN = strUserDN
END FUNCTION

Set objLDAPUser = GetObject("LDAP://" & GetUserDN(userName,domainName))

Dim objFSO, objWsh, appDataPath, pathToCopyTo, plainTextFile, plainTextFilePath, richTextFile, richTextFilePath, htmlFile, htmlFilePath
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWsh = CreateObject("WScript.Shell")
appDataPath = objWsh.ExpandEnvironmentStrings("%APPDATA%")
'
' added section
'
pathToCopyTo = appDataPath & "\Microsoft\Signatures\"
If Not objFSO.FolderExists(pathToCopyTo) Then
   objFSO.CreateFolder(pathToCopyTo)
End If
'
' end of modified Section
'
plainTextFilePath = pathToCopyTo & "Default.txt"
Set plainTextFile = objFSO.CreateTextFile(plainTextFilePath, TRUE)
plainTextFile.WriteLine(objLDAPUser.FirstName & " " & objLDAPUser.LastName)
plainTextFile.WriteLine(objLDAPUser.title)
plainTextFile.WriteLine ("Insert Company Here")
plainTextFile.WriteLine [BR]
If Len(objLDAPUser.physicalDeliveryOfficeName) > 1 THEN
	IF  CStr(REPLACE(objLDAPUser.physicalDeliveryOfficeName, "x", "")) >  200 THEN
		plainTextFile.WriteLine("Insert Phone Here" & REPLACE(objLDAPUser.physicalDeliveryOfficeName, "x", "" ) & " (Direct) ")
	ELSE
		plainTextFile.WriteLine("Insert Phone Here" & REPLACE(objLDAPUser.physicalDeliveryOfficeName, "x", "") & " (Direct) ")
	END If
END If
IF  Len(objLDAPUser.telephoneNumber) > 3 THEN
  plainTextFile.WriteLine(objLDAPUser.telephoneNumber & " " & "(Cell)")
END If
 
plainTextFile.WriteLine( "(xxx) xxx-xxxx (Fax) " )
plainTextFile.Close

Open in new window

0
 

Author Comment

by:ICCNetworkAdmin
ID: 39176682
Unfortunatly the modified script did not put any signatures in outlook when the profile was created.
0
 
LVL 76

Assisted Solution

by:David Lee
David Lee earned 250 total points
ID: 39201105
Is it the absence of a Signature folder that's causing the error?  If so, then yes, you can create the folder outside of Outlook.  Add this code to the script you already have and insert a call to it immediately after this line

Set objWsh = CreateObject("WScript.Shell")

Sub CreateSigFolder()
    Dim objFSO, objShl, strFld
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objShl = CreateObject("WScript.Shell")
    strFld = objShl.ExpandEnvironmentStrings("%AppData%") & "\Microsoft\Signatures"
    If Not objFSO.FolderExists(strFld) Then objFSO.CreateFolder (strFld)
    Set objFSO = Nothing
    Set objFld = Nothing
End Sub

Open in new window

0
 

Author Closing Comment

by:ICCNetworkAdmin
ID: 39201945
Thank you for the help! With the help of ve3ofa and BlueDevilFan the script is now working as needed. We backed away from the Default part because some users were complaining but as for the error it no longer appears.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Follow this checklist to learn more about the 15 things you should never include in an email signature from personal quotes, animated gifs and out-of-date marketing content.
Find out what you should include to make the best professional email signature for your organization.
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now