• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 621
  • Last Modified:

Outlook Signature Script Error

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
ICCNetworkAdmin
Asked:
ICCNetworkAdmin
2 Solutions
 
Alan GunnCommented:
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
 
David Johnson, CD, MVPOwnerCommented:
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
 
ICCNetworkAdminAuthor Commented:
Unfortunatly the modified script did not put any signatures in outlook when the profile was created.
0
 
David LeeCommented:
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
 
ICCNetworkAdminAuthor Commented:
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now