Создание подписи в Microsoft Outlook. Изменение html-шаблона#VBScript#ivc
Const APPLICATION_DATA = &H1a&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(APPLICATION_DATA)
Set objFolderItem = objFolder.Self
'On Error Resume Next
ParentFolder = objFolderItem.Path &"\Microsoft"
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(ParentFolder)
objFolder.NewFolder "Signatures"
'On Error Resume Next
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(APPLICATION_DATA)
Set objFolderItem = objFolder.Self
'Копирование графики в папку пользователя
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
strCopyFrom = "\\adm\Софт\Шаблон подписи Microsoft Office Outlook\VSV\"
objFSO.CopyFile strCopyFrom & "new-logo_go.gif", WshShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Application Data\Microsoft\Signatures\"
objFSO.CopyFile strCopyFrom & "new-ugolok.gif", WshShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Application Data\Microsoft\Signatures\"
objFSO.CopyFile strCopyFrom & "re-ugolok.gif", WshShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Application Data\Microsoft\Signatures\"
objFSO.CopyFile strCopyFrom & "newcompany.htm", WshShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Application Data\Microsoft\Signatures\"
objFSO.CopyFile strCopyFrom & "recompany.htm", WshShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\Application Data\Microsoft\Signatures\"
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objRegExp = CreateObject("VBScript.RegExp")
objRegExp.IgnoreCase = False ' учитывать регистр символов
objRegExp.Multiline = True ' многострочный объект
objRegExp.Global = True ' Ищем по всему тексту
'Подключаем ADSystemInfo'
Set objSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
'New Фамилия Имя'
Set objTextFile = objFSO.OpenTextFile (objFolderItem.Path &"\Microsoft\Signatures\newcompany.htm", ForReading, False)
strTextFile = objTextFile.ReadAll
objTextFile.Close
objRegExp.Pattern = "Фамилия Имя"
strName = objUser.FullName
strName = InputBox ("Добро пожаловать в программу настройки подписи Outlook. Измените ФИО так как они должны выглядеть в подписи", "ФИО", strName)
strTextFile = objRegExp.Replace(strTextFile,strName)
Set objTextFile = objFso.OpenTextFile(objFolderItem.Path &"\Microsoft\Signatures\newcompany.htm", ForWriting, False)
objTextFile.Write strTextFile
objTextFile.Close
'RE Фамилия Имя'
Set objTextFile = objFSO.OpenTextFile (objFolderItem.Path &"\Microsoft\Signatures\recompany.htm", ForReading, False)
strTextFile = objTextFile.ReadAll
objTextFile.Close
objRegExp.Pattern = "Фамилия Имя"
strTextFile = objRegExp.Replace(strTextFile,strName)
Set objTextFile = objFso.OpenTextFile(objFolderItem.Path &"\Microsoft\Signatures\recompany.htm", ForWriting, False)
objTextFile.Write strTextFile
objTextFile.Close
'New Email'
Set objTextFile = objFSO.OpenTextFile (objFolderItem.Path &"\Microsoft\Signatures\newcompany.htm", ForReading, False)
strTextFile = objTextFile.ReadAll
objTextFile.Close
objRegExp.Pattern = "href='mailto:mymail@company.ru'>mymail@company.ru"
strEmail = objUser.mail
strEmail = "href='mailto:" & strEmail & "'>" & strEmail
strTextFile = objRegExp.Replace(strTextFile,strEmail)
Set objTextFile = objFso.OpenTextFile(objFolderItem.Path &"\Microsoft\Signatures\newcompany.htm", ForWriting, False)
objTextFile.Write strTextFile
objTextFile.Close
'Re Email'
Set objTextFile = objFSO.OpenTextFile (objFolderItem.Path &"\Microsoft\Signatures\recompany.htm", ForReading, False)
strTextFile = objTextFile.ReadAll
objTextFile.Close
objRegExp.Pattern = "href='mailto:mymail@company.ru'>mymail@company.ru"
strTextFile = objRegExp.Replace(strTextFile,strEmail)
Set objTextFile = objFso.OpenTextFile(objFolderItem.Path &"\Microsoft\Signatures\recompany.htm", ForWriting, False)
objTextFile.Write strTextFile
objTextFile.Close
'New Должность'
Set objTextFile = objFSO.OpenTextFile (objFolderItem.Path &"\Microsoft\Signatures\newcompany.htm", ForReading, False)
strTextFile = objTextFile.ReadAll
objTextFile.Close
objRegExp.Pattern = "Должность"
strTitle = InputBox ("Введите Вашу должность, например: Системный администратор", "Должность")
strTextFile = objRegExp.Replace(strTextFile,strTitle)
Set objTextFile = objFso.OpenTextFile(objFolderItem.Path &"\Microsoft\Signatures\newcompany.htm", ForWriting, False)
objTextFile.Write strTextFile
objTextFile.Close
'Re Должность'
Set objTextFile = objFSO.OpenTextFile (objFolderItem.Path &"\Microsoft\Signatures\recompany.htm", ForReading, False)
strTextFile = objTextFile.ReadAll
objTextFile.Close
objRegExp.Pattern = "Должность"
strTextFile = objRegExp.Replace(strTextFile,strTitle)
Set objTextFile = objFso.OpenTextFile(objFolderItem.Path &"\Microsoft\Signatures\recompany.htm", ForWriting, False)
objTextFile.Write strTextFile
objTextFile.Close
'New Телефон'
Set objTextFile = objFSO.OpenTextFile (objFolderItem.Path &"\Microsoft\Signatures\newcompany.htm", ForReading, False)
strTextFile = objTextFile.ReadAll
objTextFile.Close
objRegExp.Pattern = "Тел.:"
strPhone = InputBox ("Введите номер внутреннего телефона (четыре цифры, например, 7550)", "Телефон")
If strPhone <> "" then
strPhone = "Тел.: +7 (812) 111-11-11 (доб. " & strPhone & ")"
else
strPhone = "Тел.: +7 (812) 111-11-11"
end if
strTextFile = objRegExp.Replace(strTextFile,strPhone)
Set objTextFile = objFso.OpenTextFile(objFolderItem.Path &"\Microsoft\Signatures\newcompany.htm", ForWriting, False)
objTextFile.Write strTextFile
objTextFile.Close
'Re Телефон'
Set objTextFile = objFSO.OpenTextFile (objFolderItem.Path &"\Microsoft\Signatures\recompany.htm", ForReading, False)
strTextFile = objTextFile.ReadAll
objTextFile.Close
objRegExp.Pattern = "Тел.:"
strTextFile = objRegExp.Replace(strTextFile,strPhone)
Set objTextFile = objFso.OpenTextFile(objFolderItem.Path &"\Microsoft\Signatures\recompany.htm", ForWriting, False)
objTextFile.Write strTextFile
objTextFile.Close
'New Мобильный Телефон'
Set objTextFile = objFSO.OpenTextFile (objFolderItem.Path &"\Microsoft\Signatures\newcompany.htm", ForReading, False)
strTextFile = objTextFile.ReadAll
objTextFile.Close
objRegExp.Pattern = "<!--Mobile-->"
strMobile = InputBox ("Введите номер мобильного телефона или оставьте поле пустым, если он не нужен", "Мобильный телефон")
If strMobile <> "" then
strMobile = "<span style=""font-size:8.5pt;font-family:'Arial Narrow','sans-serif'; color:#C80000"">Моб.: " & strMobile & "</span><br>"
end if
strTextFile = objRegExp.Replace(strTextFile,strMobile)
Set objTextFile = objFso.OpenTextFile(objFolderItem.Path &"\Microsoft\Signatures\newcompany.htm", ForWriting, False)
objTextFile.Write strTextFile
objTextFile.Close
'Re Мобильный Телефон'
Set objTextFile = objFSO.OpenTextFile (objFolderItem.Path &"\Microsoft\Signatures\recompany.htm", ForReading, False)
strTextFile = objTextFile.ReadAll
objTextFile.Close
objRegExp.Pattern = "<!--Mobile-->"
strTextFile = objRegExp.Replace(strTextFile,strMobile)
Set objTextFile = objFso.OpenTextFile(objFolderItem.Path &"\Microsoft\Signatures\recompany.htm", ForWriting, False)
objTextFile.Write strTextFile
objTextFile.Close
'Прописываем подпись в реестре
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
'Получаем профиль по умолчанию'
strProfilesPath = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"
intRes = objReg.GetStringValue(HKEY_CURRENT_USER,strProfilesPath,"DefaultProfile",strValue)
'Заносим в реестр подписи'
strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\" & strValue & "\9375CFF0413111d3B88A00104B2A6676\00000002"
strValueName = "New Signature"
strValueName2 = "Reply-Forward Signature"
aValueData = Array(&H6e,&H00,&H65,&H00,&H77,&H00,&H6e,&H00,&H65,&H00,&H6f,&H00,&H70,&H00,&H72,&H00,&H69,&H00,&H6e,&H00,&H74,&H00)
aValueData2 = Array(&H72,&H00,&H65,&H00,&H6e,&H00,&H65,&H00,&H6f,&H00,&H70,&H00,&H72,&H00,&H69,&H00,&H6e,&H00,&H74,&H00,&H00,&H00)
objReg.SetBinaryValue HKEY_CURRENT_USER,strKeyPath,strValueName,aValueData
objReg.SetBinaryValue HKEY_CURRENT_USER,strKeyPath,strValueName2,aValueData2
MsgBox ("Подпись настроена. Перезапустите Outlook чтобы применились настройки")