vbscript-mini-logo

Change text in Outlook signature files with VBScript

Some guy at work decided to change our Facebook group name and effectively remove the old Facebook group link. We used that old link for all of our employee email signatures and of course it all got b0rked. Only way to deal with this was to write a quick VBS script and put it into a GPO Logon. It seemed to fix it, day was saved!
Script can be found here: http://9v.lt/projects/other/change_signature.vbs

Here’s the script for quick review:

  1. '=================================================
  2. '  Description:
  3. '       Changes a string in a HTM file for Outlook signatures.
  4. '=================================================
  5.  
  6. Set wshShell = CreateObject("WScript.Shell")
  7. Set objFS = CreateObject("Scripting.FileSystemObject")
  8.  
  9. Const sigDir = "%appdata%\Microsoft\Signatures"
  10. Const sigFTmp = "_tmp"
  11. Const oldLink = "qwerty"
  12. Const oldLink1 = "azerty"
  13. Const newLink = "asdfg"
  14.  
  15. If (objFS.FolderExists(wshShell.ExpandEnvironmentStrings(sigDir))) Then
  16.     Dim objFile
  17.     For Each objFile In objFS.GetFolder(wshShell.ExpandEnvironmentStrings(sigDir)).Files
  18.         'only proceed if there is an extension on the file.
  19.         If (InStr(objFile.Name, ".") > 0) Then
  20.             'If the file's extension is "htm", write the path to the output file.
  21.             If (LCase(Mid(objFile.Name, InStrRev(objFile.Name, "."))) = ".htm") Then
  22.                 Set textStream = objFS.GetFile(objFile.Path).OpenAsTextStream(1, -2)
  23.                 Set objOutFile = objFS.CreateTextFile(objFile.Path & sigFTmp, True)
  24.                 REM x = MsgBox(objFile.Path & sigFTmp, 0, "qqqq")
  25.                 Do Until textStream.AtEndOfStream
  26.                     strLine = textStream.ReadLine
  27.                     If (InStr(strLine, oldLink) > 0) Then
  28.                         strLine = Replace(strLine, oldLink, newLink)
  29.                         REM x = MsgBox(strLine, 0, "wwwww")
  30.                     End If
  31.                     If (InStr(strLine, oldLink1) > 0) Then
  32.                         strLine = Replace(strLine, oldLink1, newLink)
  33.                         REM x = MsgBox(strLine, 0, "eeee")
  34.                     End If
  35.                     objOutFile.WriteLine(strLine)
  36.                 Loop
  37.                 objOutFile.Close()
  38.                 textStream.Close()
  39.                 oldFilename = objFile.Path
  40.                 objFS.DeleteFile(oldFilename)
  41.                 objFS.MoveFile oldFilename & sigFTmp, oldFilename
  42.             End If
  43.         End If
  44.     Next
  45. End If
Subscribe
Notify of
guest

6 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments