' {{FileName}} ' ' This script will setup an Email account in Windows Live Mail ' ' {{DateCreated}} - Initial write. Option Explicit Dim strIncServerAddress, strOutServerAddress, strServerMailPort, strAccount, strSecureConnection, strFolderNotFoundText, _ strProgramNotFoundText, strCloseText, boolPop, strServerSmtpPort, strFileNotFoundText, boolArchive ' ************************************************************************* ' Configurable Variables ' ************************************************************************* strIncServerAddress = "{{strIncServerAddress}}" ' This is the address for the mail server strOutServerAddress = "{{strOutServerAddress}}" ' This is the address for the mail server strServerMailPort = "{{strServerMailPort}}" ' The port on the server to which to connect ' Imap: Secure = 000003e1 Unsecure = 0000008f ' Pop: Secure = 000003e3 Unsecure = 0000006e strAccount = "{{strAccount}}" ' Mail account to connect as strSecureConnection = "{{strSecureConnection}}" ' Use a secure connection - 00000001 for true, 00000000 for false strCloseText = "Please close Windows Live Mail before continuing." strFolderNotFoundText = "Windows Live Mail may not be installed; the following directory was not found:" strProgramNotFoundText = "Windows Live Mail may not be installed; the following file was not found:" strFileNotFoundText = "File not found." strServerSmtpPort = "{{strServerSmtpPort}}" ' Smtp port on the server boolPop = {{boolPop}} ' Whether to setup Imap or Pop boolArchive = False ' Whether or not to use the special folders ' ************************************************************************* ' Write out the Account File for Windows Live Mail ' ************************************************************************* Function WriteFile Dim objShell, objFSO, objAccountFile, strBaseFilePath, strFullFilePath ' Generate a first file name for the account file Set objShell = CreateObject("WScript.Shell") strBaseFilePath = objShell.ExpandEnvironmentStrings("%USERPROFILE%\AppData\Local\Microsoft\Windows Live Mail") Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FolderExists(strBaseFilePath) = False Then MsgBox strFolderNotFoundText & ": " & strBaseFilePath, 16, strFileNotFoundText Set objShell = Nothing WScript.Quit End if strFullFilePath = GenerateAccountFileName(strBaseFilePath) ' See if the account file already exists and keep trying new ones until we find one that isn't there Do While objFSO.FileExists(strFullFilePath) strFullFilePath = GenerateAccountFileName(strBaseFilePath) Loop ' Write the account file Set objAccountFile = objFSO.CreateTextFile(strFullFilePath, False) objAccountFile.WriteLine "" objAccountFile.WriteLine "" objAccountFile.WriteLine " " & strAccount & "" objAccountFile.WriteLine " 00000003" If boolPop = True Then objAccountFile.WriteLine " " & strIncServerAddress & "" objAccountFile.WriteLine " " & strAccount & "" objAccountFile.WriteLine " 00000000" objAccountFile.WriteLine " " & strServerMailPort & "" objAccountFile.WriteLine " " & strSecureConnection & "" objAccountFile.WriteLine " 00000001" objAccountFile.WriteLine " 00000001" objAccountFile.WriteLine " 00000001" objAccountFile.WriteLine " 00000000" Else objAccountFile.WriteLine " " & strIncServerAddress & "" objAccountFile.WriteLine " " & strAccount & "" objAccountFile.WriteLine " " & strServerMailPort & "" objAccountFile.WriteLine " " & strSecureConnection & "" objAccountFile.WriteLine " 0000003c" objAccountFile.WriteLine " 00000001" objAccountFile.WriteLine " 00000001" objAccountFile.WriteLine " 00000000" objAccountFile.WriteLine " 00000001" objAccountFile.WriteLine " 00000001" If boolArchive = True Then objAccountFile.WriteLine " 00000000" objAccountFile.WriteLine " 00000000" objAccountFile.WriteLine " 00000000" objAccountFile.WriteLine " 00000000" objAccountFile.WriteLine " 00000000" Else objAccountFile.WriteLine " 00000001" objAccountFile.WriteLine " 00000001" objAccountFile.WriteLine " 00000001" objAccountFile.WriteLine " 00000001" objAccountFile.WriteLine " 00000001" End if End if objAccountFile.WriteLine " " & strOutServerAddress & "" objAccountFile.WriteLine " 00000002" objAccountFile.WriteLine " " & strServerSmtpPort & "" objAccountFile.WriteLine " " & strSecureConnection & "" objAccountFile.WriteLine " " & strAccount & "" objAccountFile.WriteLine " " & strAccount & "" objAccountFile.WriteLine "" objAccountFile.Close ' Clean up Set objAccountFile = Nothing Set objFSO = Nothing Set objShell = Nothing End Function ' ************************************************************************* ' Generates a new Windows Live Mail account file name ' ************************************************************************* Function GenerateAccountFileName(strBasePath) GenerateAccountFileName = strBasePath & "\account" & NewGuid & ".oeaccount" End Function ' ************************************************************************* ' Returns a new guid in brace notation e.g. {00000000-0000-0000-0000-000000000000} ' ************************************************************************* Function NewGuid Dim TypeLib Set TypeLib = CreateObject("Scriptlet.TypeLib") NewGuid = Left(TypeLib.Guid, 38) End Function ' ************************************************************************* ' Warns the user if Windows Live Mail is in the process list and exits if so ' ************************************************************************* Function WarnIfWindowsLiveMailIsRunning Do While IsWindowsLiveMailRunning = True Dim return return = MsgBox(strCloseText, 49) If return = vbCancel Then WScript.Quit End if WScript.Sleep 5000 ' Sleep for 5 seconds Loop End Function Function IsWindowsLiveMailRunning Dim objShell, objWmiService, objProcessList, boolFound ' See if Windows Live Mail is running boolFound = False Set objShell = CreateObject("WScript.Shell") Set objWmiService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2") Set objProcessList = objWmiService.ExecQuery ( _ "Select * from Win32_Process where Name = 'wlmail.exe'") If objProcessList.Count >= 1 Then boolFound = True End if ' Clean up Set objWmiService = Nothing Set objProcessList = Nothing Set objShell = Nothing IsWindowsLiveMailRunning = boolFound End Function ' ************************************************************************* ' Launches Windows Live Mail ' ************************************************************************* Function LaunchWindowsLiveMail Dim objShell, objFSO, strLiveMailPath ' Start Windows Live Mail Set objShell = CreateObject("WScript.Shell") strLiveMailPath = objShell.ExpandEnvironmentStrings( _ "%PROGRAMFILES(x86)%\Windows Live\Mail\wlmail.exe") Set objFSO = CreateObject("Scripting.FileSystemObject") If objFSO.FileExists(strLiveMailPath) = False Then strLiveMailPath = objShell.ExpandEnvironmentStrings( _ "%PROGRAMFILES%\Windows Live\Mail\wlmail.exe") If objFSO.FileExists(strLiveMailPath) = False Then MsgBox strProgramNotFoundText & ": " & strLiveMailPath, 16, strFileNotFoundText Set objShell = Nothing WScript.Quit End if End if objShell.Run("""" & strLiveMailPath & """") Set objShell = Nothing Set objFSO = Nothing End Function WarnIfWindowsLiveMailIsRunning WriteFile LaunchWindowsLiveMail