Solved

Script to create PRF then Edit it.

Posted on 2008-06-20
3
660 Views
Last Modified: 2010-08-05
Hello all,
Our company is move to a new email domain name, and we need to create new email accounts within an existing email profile.  I have created a vbscript to edit a dummy PRF file and have the user info be populated by the user.  Below is my vbscript.

-------------------------------------------------------------------------------------------
Const ForReading = 1
Const ForWriting = 2


'Get the users name
sName = InputBox("What is your first and last name?")
sPOP = InputBox("Please enter the beginging of your email address, not @domain.com")
'Display the user's name
'MsgBox "Your first and last name is " &  sName
Wscript.Echo "Your first and last name is " &  sName
Wscript.Echo "Your email is " &  sPOP & "@domain.com"

Function Domain()
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\outlook\testprf.PRF", ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "@domain.com", "@Newdomain.com")

Set objFile = objFSO.OpenTextFile("C:\Scripts\outlook\testprf.PRF", ForWriting)
objFile.WriteLine strNewText
objFile.Close
End Function
Domain()

Function Name()
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\outlook\testprf.PRF", ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "ReplaceDisplayName", sName)

Set objFile = objFSO.OpenTextFile("C:\Scripts\outlook\testprf.PRF", ForWriting)
objFile.WriteLine strNewText
objFile.Close

End Function
Name()

Function POP3Name()
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\outlook\testprf.PRF", ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "POP3Name", sPOP)

Set objFile = objFSO.OpenTextFile("C:\Scripts\outlook\testprf.PRF", ForWriting)
objFile.WriteLine strNewText
objFile.Close

End Function
POP3Name()


Function Folder()
 Dim filesys, newfolder
 Dim objWSH
 Dim objUserVariables
 Dim objSystemVariables
 
 Set objWSH =  CreateObject("WScript.Shell")
'This actually returns all the User Variables, and you either loop through all, or simply print what you want
WScript.Echo "UserProfile=" & objWsh.Environment("PROCESS")("UserProfile")
 strUP = objWsh.Environment("PROCESS")("UserProfile") & "\My Documents\pst"
 WScript.Echo "PST location" & strUP
set filesys=CreateObject("Scripting.FileSystemObject")
If  Not filesys.FolderExists (strUP) Then
   WScript.StdOut.Write( vbCrlf )
   
   newfolder = filesys.CreateFolder (strUP)
   WScript.StdOut.Write "A new folder '" & newfolder & "' has been created"
End If

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\outlook\testprf.PRF", ForReading)

strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "ReplacePath", strUP)

Set objFile = objFSO.OpenTextFile("C:\Scripts\outlook\testprf.PRF", ForWriting)
objFile.WriteLine strNewText
objFile.Close

End Function
Folder()
-------------------------------------------------------------------------------------------

and here is the section of the PRF I am changing

-------------------------------------------------------------------------------------------
[Account1]
UniqueService=No
AccountName=Account1
POP3Server=server
SMTPServer=server
POP3UserName=POP3Name
EmailAddress=POP3Name@domain.com
POP3UseSPA=0
DisplayName=ReplaceDisplayName
ReplyEMailAddress=
SMTPUseAuth=1
SMTPAuthMethod=0
ConnectionType=0
LeaveOnServer=0x0
ConnectionOID=MyConnection
POP3Port=110
POP3UseSSL=0
ServerTimeOut=60
SMTPPort=25
SMTPUseSSL=0
Name=My Personal Folder
PathToPersonalFolders=ReplacePath\findme.pst
-------------------------------------------------------------------------------------------
I would like to completely automate this process, without the need for any user input.  Is there a way to script the creation of a PRF file containing the users info and then use my vbscript to edit it.

Thank you.
0
Comment
Question by:oritronen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 17

Accepted Solution

by:
Jared Luker earned 125 total points
ID: 21833019
You can read in the ReadAll method to read the entire text file, use the Replace method to find the string you want to change.  Finally, you can use the WriteLine method to write everything back out to the file.

Here's an example that changes a comman delimited file to tab delimited:
strComputer = "."
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim SizeCount
 
Const ForAppending = 8
Const ForWriting = 2
Const ForReading = 1
 
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("C:\test.txt")
If objFile.Size > 0 Then
    Set objReadFile = objFSO.OpenTextFile("C:\test.txt", 1)
    strContents = objReadFile.ReadAll
    tabFormat = Replace(strContents,",",vbTab)
    WScript.Echo tabFormat
    objReadFile.Close
Else
    Wscript.Echo "The file is empty."
End If
 
 
Set FixedFile = objfso.OpenTextFile("c:\fixedfile.txt",ForAppending,True)
fixedfile.WriteLine tabFormat
fixedfile.Close

Open in new window

0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

717 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