Jump to content
Chris866

Managing Outlook accounts in profile

Recommended Posts

Chris866

I'm trying to script a way to add and remove accounts to a users Outlook profile.  I _think_ adding can be done by creating PRF files but how can you delete an account without Exchange?

 

We already have in place a web interface where we can say what users should be reading what email accounts, the output of the webpage writes a txt config file.  Currently we use Thunderbird but users are wanting Outlook (for some reason, we don't run Exchange).  In Thunderbird, when it starts, via an autoit script, it checks the webpage config file, looks to see what email accounts the user should be reading, each account has an ID we set in the web php, the script them looks in the users pref.js file for the ID's they should be ready and those that they shouldn't be reading anymore.  The users pref.js is then edited, the lines with the ID they don't need to read are removed, for accounts that need adding, a template segment of pref.js file is copied locally, the ID number is inserted and the file is cat'ed to the users prefs.js.  Thunderbird is then started and displays the email accounts that user should be reading, job done.  This is what I'm trying to reproduce but with Outlook. 

 

Thoughts....

 

thanks.  Chris

Share this post


Link to post
Share on other sites
water

Details about profiles can be found here or here.
Happy reading :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Chris866

Thanks for the links.  I don't seem to find anything about how to remove a profile so is this possible?  :'(

Share this post


Link to post
Share on other sites
water

Unfortunately I have absolutely no idea and didn't find anything related on the web. Best bet seems to be to create a new profile and drop the unneeded account.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
Chris866

OK, for anyone finding this page who is also looking how to add and remove Outlook accounts without using exchange, here's how you can do it.

 

All of the information is in the registry, it's just a matter of knowing where and what to delete.  To add an account, construct a .prf file and start Outlook with the /importprf option.  In my case I used Autoit to read the txt based config file that was generated from a web page.  The config lines looked like:
 

Quote

90009,cadmin,C Group Secretary,ca@xxxx.cam.ac.uk,CA ,cm214

90010,hrpeople,HR Office,hr@xxxx.cam.ac.uk,HR,cm214

....

 

I created a PRF template file like the one attached - template.txt.  It's the same format as the PRF file that is exported when you run Office setup.exe with the /admin switch.  For the areas in the template that will change for each Outlook account I want to add, I add a string of text that I use _ReplaceStringInFile to replace that string with some proper lines that Outlook will understand when it imports the PRF file.  It seems that you can't start Outlook with more than one /importprf [filename] therefore you need to create on PRF file with all the Outlook accounts and any LDAP settings.  To test the PRF file you need to delete any existing Outlook profiles, this is where the learning starts.  I'm working with Outlook 2010, the registry keys may be different with different versions of Outlook but for 2010, delete the key:

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\cm214

 

(cm214 is my Outlook profile name)

Also delete any files in:

C:\Users\cm214\Appdata\Local\Microsoft\Outlook\

 

Now Outlook can be started and configured:

"c:\Program Files (x86)\Microsoft Office\Office14\OUTLOOK.EXE" /importprf [path to the edited template file with replaced text]

 

That's the easy bit and well documented on the web.  What doesn't seem to be so well documented is how to remove one or more of your Outlook accounts.  Yes, you can just delete the profile under \Windows Messaging Subsystem\Profiles\ in the registry and remove the .pst files but you then loose all of your Outlook accounts.  The following is what I do and seems to work!

 

For each account you want to delete you need to delete 4 registry keys and change two values in another key.  All the accounts are listed in the registry:

 

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\cm214\9375CFF0413111d3B88A00104B2A6676\

 

9375CFF0413111d3B88A00104B2A6676 seems to always be used for Outlook 2010 anyway.  The keys below this look like:

 

00000001

00000002

00000005

00000008

For this text we'll call them 'accountids'.  These accountids are quite meaningless until you look at the key called 'Account Name' within each of the 'accountids' keys.  The value of 'Account Name' is in hex and using the following will show you which account 0000001, 00000002 etc refer to in English:

$outlook_registry_pro_root="HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"
$func_username="cm214"
$outlook_registry_pro_key="9375CFF0413111d3B88A00104B2A6676"


For $i = 1 To 100
  $sSubKey = RegEnumKey($outlook_registry_pro_root & "\" & $func_username & "\" & $outlook_registry_pro_key, $i)
  If @error Then ExitLoop
  If $sSubKey <> "" Then
    $prof_regread = RegRead($outlook_registry_pro_root & "\" & $func_username & "\" & $outlook_registry_pro_key & "\" & $sSubKey, "Account Name")
    $prof_regread = StringReplace($prof_regread, "00", "")
    $prof_reg_key = BinaryToString($prof_regread)
    ConsoleWrite ($prof_reg_key & " (" & "\" & $func_username & "\" & $outlook_registry_pro_key & "\" & $sSubKey & ")" & @CRLF)
  EndIf
Next

So, for the account (accountids) you want to delete, look in each 9375CFF0413111d3B88A00104B2A6676\(accountids)\ and look for the value of 'Preferences UID'  This is the name of the another key below 'HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\cm214\ ', delete this key.

 

Next, look at the value of 'Service UID' within 9375CFF0413111d3B88A00104B2A6676\(accountids)\.  This too points to another key under 'HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\cm214\' but before deleting it, look in this key and note the value of '01023d00'.  This points to another key under '\Windows Messaging Subsystem\Profiles\cm214\', delete this key and then delete the key you read the value of '01023d00' in.  That's three registry keys deleted, the last registry key to delete is 9375CFF0413111d3B88A00104B2A6676\(accountids)\.  Do this for each account you want to delete.

 

We then need to change the value of the key 9375CFF0413111d3B88A00104B2A6676\{ED475418-B0D6-11D2-8C3B-00104B2A6676} and 9375CFF0413111d3B88A00104B2A6676\{ED475420-B0D6-11D2-8C3B-00104B2A6676}.  These are binary values and they contain the values of the 'accountids', 0000001, 00000002 etc.  For each account you delete you also need to delete the value of 'accountids' from the two keys but each value of 'accountids' has to be split into four groups of two values and each of the four groups reversed and put back to one group of eight.  00000001 > 00 00 00 01(split into four groups) > 01000000 (joined together starting with the last pair).  To make it clearer, lets say the value of 'accountids' = 12345678.  Make four groups of two = 12 34 56 78.  Then make one group starting with the last of the pairs = 78563412.  For each account we delete remove this accounts 'accountids' from both {ED475418-B0D6-11D2-8C3B-00104B2A6676} and {ED475420-B0D6-11D2-8C3B-00104B2A6676}.  That completes the registry work.

 

The last thing to do is to remove any files within C:\Users\[username]\Appdata\Local\Microsoft\Outlook.  To work out what files to delete, look for anything with the value of 'Account Name' that we worked out earlier when we found what 'accountids' to delete.  Done, you've now removed an account without blatting all your accounts.

 

For my users they start what they think is the Outlook exe but it's been replaced with my Autoit code that works out what accounts they should be reading as set in the web generated config txt file.  It then works out the accounts that are in the registry.  For any accounts that need adding a new PRF file is created.  Any account they shouldn't be read are removed from the registry.  Lastly Outlook is started with the /importprt [filename] argument.  My new exe can also be passed two variables, 'clean' or 'list'.  Clean will delete the registry below HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\cm214\ and remove files in \Appdata\Local\Microsoft\Outlook\.  List will show the readable version of the accounts under \CurrentVersion\Windows Messaging Subsystem\Profiles\cm214\9375CFF0413111d3B88A00104B2A6676\.

 

Hopefully this will help someone who's trying to work out how to remove / delete Outlook accounts.

template.txt

Share this post


Link to post
Share on other sites
water

Thanks for sharing :)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Friends,
      I am having a requirement where i have to automate outllook.I have to send mail using outlook.Whe i went through the forum i got OutLookEx.au3 but when i am trying to use this i am getting error can anyone help me in using this? @water
    • Gowrisankar
      By Gowrisankar
      Dear members of the forum,
      I'm working on a project where incoming emails are to be analyzed based on the subject line and moved to various folders in a shared mailbox.
      I'm using "OutlookEx.au3" of @water. The macro can can move emails  to any folder that I newly create. But the macro couldn't move emails to specific folders that are already existing.
      I checked the permission levels of those folders and found that nothing is wrong with that. The function I use is _OL_ItemMove.
      Please guide me how to proceed further. Thanks in advance.
      -Gowrisankar.
       
    • nooneclose
      By nooneclose
      Good morning everyone, I thought I had already solved this issue but it turns out I did not. 
      My code finds unread emails with this specific subject line of "request" but when I change the subject to SKIPPED + "request" = ("SKIPPED request") the program still finds the email and tries to process it. I only want to process emails with the exact match subject of "request".
      Here is my code that "finds" the unread emails with the subject of "request" or so I thought. 
      Func ListUnreadEmails() ;******************************************************************************* ; Lists all unread E-mails from the folder Outlook-UDF-Test ;******************************************************************************* ; Stores all the unRead emails into an array Global $aItems = _OL_ItemFind($oOutlook, "*\Outlook-UDF-Test", $olMail, _ "[UnRead]=True", "Subject", "request", "EntryID,Subject", "", 1) ; Displays the array of unRead emails If IsArray($aItems) Then ;_ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind - Unread mails") Else MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", _ "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended) EndIf ; Gets the number of unread emails Global $numberOfUnRead = UBound($aItems, $UBOUND_ROWS) - 1 ;MsgBox("", "Number of Unread emails", $numberOfUnRead) EndFunc It acts as if any part of the subject containing the word "request" and the email is unread that it will try to process it. (I think)
    • nooneclose
      By nooneclose
      Good afternoon, I am in need of some help. I am sure this is a stupid question requiring only one or two lines of code. However, I would greatly appreciate the help I cannot figure this out. I also tried searching for the answer on the internet but no one except me apparently seems to be having a hard time figuring this out and or is asking about it. 
      I simply want to change the "status" of an email from unread to read once I have processed it. My code is over 500 lines and I would like not to clutter this post with it. Assume I have all my includes and connections properly defined and stuff. 
      Here is the bit of code where I am trying to change the email that was used from unread to read:
      Func ChangeEmailStatus() ;******************************************************************************* ; changes the status of an email from unread to Read ;******************************************************************************* Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (Before Change)", $iRows) _OL_ItemModify($oOutlook,$aItems[$i][0], Default, "Read=True") MsgBox("", "Array Display 1", $aItems[1][0]) MsgBox("", "Array Display 2", $aItems[2][0]) Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (After Change)", $iRows) EndFunc  
    • nooneclose
      By nooneclose
      Hello again everyone, I am trying to make a simple bot/AI to help me at work. I need it to read the subject line of emails, open them if a certain subject line is found, and then copy the contents of the said email and paste it in a different program. 
      Can the Autoit outlook UDF help me achieve this? 
      Also, I have tried the Outlook UDF and so far I have only figured out how to find all the unread emails (thanks to one of water's example scripts. @water you are a genius just saying).
      I am very new to this UDF and would love any help that would guide me into making this bot/AI a reality at work.   
×