Solved

Outlook Signature Script Error

Posted on 2013-05-17
5
599 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 78

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Learn more about how the humble email signature can be used as more than just an electronic business card. When used correctly, a signature can easily be tailored for different purposes by different departments within an organization.
Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 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

24 Experts available now in Live!

Get 1:1 Help Now