# Managing Outlook accounts in profile

## Recommended Posts

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 on other sites

Details about profiles can be found here or here.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:

##### Share on other sites

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

##### Share on other sites

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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:

##### Share on other sites

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

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 Thanks for sharing My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts Excel - Example Scripts - Wiki Word - Wiki PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support 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 • By water Extensive library to control and manipulate Microsoft Outlook. Theads: Development - General Help & Support - Example Scripts - Wiki BTW: If you like this UDF please click the "I like this" button. This tells me where to next put my development effort KNOWN BUGS (last changed: 2018-01-26) Function _OL_RuleConditionSet does not properly handle parameter rule condition type ($iRuleConditionType) when value $olConditionSentTo is passed. it is being processed the same way as$olConditionFrom.
Thanks to user Moonscarlet for reporting this bug.
Fixed with version 1.3.3.1 of the UDF.
• By cag8f
Hi all.  Does AutoIt have any functions/tools (either built-in or user defined) that can help me automate the process of exporting an OST mailbox to a PST file in Microsoft Outlook (2013)?
I know how to carry out the process manually.  At the Microsoft Forums, I have asked if it is possible to do the same via a script, but some have said it is not possible.  It may be possible if I was using Microsoft Exchange, but I am not.
I've seen some posts about an Outlook UDF on this site (here and here), but I don't see any mention of exporting a mailbox.
In my post at the Microsoft Forums, many paid third party applications were suggested.  But for now I would like to pursue the custom scripting route as far as I can.
The ultimate goal of this exercise is to automatically create a weekly backup of my Outlook mailbox for offline storage.

• By zetaimmersion
Hi all.
I am trying to do 2 things but i cannot seem to get any traction on how to read/implement this idea.
Premise: PowerPoint file in C\temp\presentation.pptx that contains on the first slide 2 entries as "<one>" and "<two>" which need to be replaced with "user1" and "user2", then a silent Outlook send mail containing the file with a predefined body and subject.
I narrowed it down to COM objects as the Office does not like intrusive open AutoIt functions. I installed OLE/COM Object Viewer to understand how to create the commands but i am still stuck. So far i am trying to user water's code but i suck
COM object i was originally trying to modify
Dim $oPPT,$oPres $oPPT = ObjCreate("PowerPoint.Application")$oPPT.Visible = True $oPres =$oPPT.Presentations.Read Water's code below (0.1% modified)
#include <File.au3> #include "PowerPoint.au3" #include <misc.au3> Global $sFile = "C:\temp\presentation.pptx" Global$sString2Search = "<username>", $sString2Replace = "Password",$iReplaceOnce = 1, $sFullLogFile = "C:\temp\pptxlog.txt" _ProcessPpt($sFile) Func _ProcessPpt($sFile)$oApp = _PPT_PowerPointApp() Local $bChange = False Local$oInterface = $oApp.Presentations Local$oPresentation = $oInterface.Open($sFile, False, False, False) If @error Then _FileWriteLog($sFullLogFile, "E Error " & @error & " opening File " &$sFile) Return SetError(1, 0, 0) EndIf ;it does not even open my file and from here not sure how to read the text and replace it EndFunc ;==>_ProcessPpt
• By Smigacznr1
I'm writing Outlook pst cleaner and now I'm stuck. Compiled script is crashing with OS crash message. When I tryied to run script from editor it's exiting itself (mabye it's some type of crash?) always when it's processing on 4-rd pst file. Here is my code:
#include <OutlookEX.au3> #include <Date.au3> #include <File.au3> #include <Array.au3> _cleanOutlook("Administrator") _cleanOutlook("Admin") Exit Func _cleanOutlook($user)$foldery = "Wiadomości-śmieci#?SPAM#?Junk E-mail#?Elementy usunięte#?Deleted Items" $tab_folderow = StringSplit($foldery, "#?", 1) $tab_pst = _FileListToArrayRec("c:\users\" &$user, "*.pst", 1+4+8, 1, 0, 2) ;~ _ArrayDisplay($tab_pst) For$d = 1 To UBound($tab_pst) -1 Step +1$outlook = _OL_Open(True) _OL_Close($outlook, True)$outlook = _OL_Open() Local $aStores = _OL_StoreGet($outlook) ;~ _ArrayDisplay($aStores) For$i = 1 to $aStores[0][0] If$aStores[$i][4] = True Then ;~ ConsoleWrite(@CRLF & "zamykam pst 2") _OL_PSTClose($outlook,$aStores[$i][0]) EndIf Next ;~ _OL_PSTAccess($outlook, "C:\Users\Administrator\Desktop\cos.pst") _OL_PSTAccess($outlook, $tab_pst[$d]) ConsoleWrite(@CRLF & $tab_pst[$d]) ;~ $tab_struktury = _OL_FolderTree($outlook, "*", 10) ;~ If @error Then ;~ ContinueLoop ;~ EndIf ;~ _ArrayDisplay($tab_struktury)$tab_ktory_pst = _OL_PSTGet($outlook) ;~ _ArrayDisplay($tab_ktory_pst) For $a = 0 To UBound($tab_ktory_pst) -1 Step +1 If $tab_ktory_pst[$a][2] = $tab_pst[$d] Then ;~ MsgBox(0, "", $tab_ktory_pst[$a][0]) $nazwa_bazy_pst =$tab_ktory_pst[$a][0] EndIf Next ;~ MsgBox(0, "", UBound($tab_folderow)) ;~ _ArrayDisplay($tab_folderow,$tab_pst[$d]) ConsoleWrite(@CRLF & "przed while")$a = 0 While $a < 2 ConsoleWrite(@CRLF & "while 1") For$b = 1 To UBound($tab_folderow) -1 Step +1 ConsoleWrite(@CRLF & "for 1")$tab_struktury = _OL_FolderTree($outlook,$nazwa_bazy_pst) ;~ _ArrayDisplay($tab_struktury,$nazwa_bazy_pst) ;~ $folder = _OL_FolderAccess($outlook, StringTrimLeft($tab_struktury[0], 2) & "\" &$tab_folderow[$b])$folder = _OL_FolderAccess($outlook,$nazwa_bazy_pst & "\" & $tab_folderow[$b]) ;~ ConsoleWrite(@CRLF & "eeee") If @error Then ;~ MsgBox(0, "", "\\" & $nazwa_bazy_pst & "\" &$tab_folderow[$b] & @CRLF & @error) ConsoleWrite(@CRLF & "przechodze do kolejnego " &$b+1) ContinueLoop EndIf ;~ _ArrayDisplay($folder,$nazwa_bazy_pst) ConsoleWrite(@CRLF & $tab_folderow[$b]) If $tab_folderow[$b] = "Deleted Items" Or $tab_folderow[$b] = "Elementy usunięte" Then ConsoleWrite(@CRLF & "usuwam kosze") _OL_FolderDelete($outlook,$folder[1], 1) _OL_FolderDelete($outlook,$folder[1], 2) _OL_FolderDelete($outlook,$folder[1], 3) _OL_FolderDelete($outlook,$folder[1], 4) ;~ _OL_FolderDelete($outlook,$folder[1], 5) EndIf If $a = 0 Then$tab_maile = "" $data_dzis = @YEAR & "/" & @MON & "/" & @MDAY & " 00:00" ;~$data_dzis = "2017/01/31 00:00" $data_szukana = _DateAdd("D", "-3",$data_dzis) $tab_maile = _OL_ItemFind($outlook, $folder[1],$olMail, "[Received]<'" & StringReplace($data_szukana, "/", "-") & "'", "", "", "EntryID", "", 1) If @error Then ContinueLoop EndIf ;~ If UBound($tab_maile) > 1 Then ;~ _ArrayDisplay($tab_maile) ;~ EndIf If UBound($tab_maile) > 1 Then For $c = 1 To UBound($tab_maile) -1 Step +1 ;~ ConsoleWrite(@CRLF & "usuwam stare maile") _OL_ItemDelete($outlook,$tab_maile[$c][0], "", False) Next EndIf EndIf Next$a = $a + 1 WEnd ;~ ConsoleWrite(@CRLF & "pokazuje") ;~$folder[1].Display $olFolderInbox.Display ;~ _OL_PSTClose($outlook, $olFolderInbox) ;~ If @error Then ;~ MsgBox(0, "", @error) ;~ EndIf Local$aStores = _OL_StoreGet($outlook) ;~ _ArrayDisplay($aStores) For $i = 1 to$aStores[0][0] If $aStores[$i][4] = True Then ;~ ConsoleWrite(@CRLF & "zamykam pst 1") _OL_PSTClose($outlook,$aStores[$i][0]) EndIf Next ;_OL_PSTClose($outlook, $folder[1]) _OL_Close($outlook, True) If @error Then MsgBox(0, "", @error) EndIf ConsoleWrite(@CRLF & "zamykam") ProcessWaitClose("outlook.exe", 30) ProcessClose("outlook.exe") Next EndFunc
Outlook and OS is updated. I'm usinn OutlooEX in ver. 1.3.1.0
Any ideas?

• By Gowrisankar
Dear members of the forum,
I'm new to AutoIt and I'm having a good time exploring and enjoying the features of AutoIt.
For one of my tasks, I've to open few particular mails from outlook based on subject of the mails and then print the mails. Can someone please guide me how to do it?
My question could be very silly for experts. But I'm just a beginner. Kindly advice.
Thanks and regards,
Gowrisankar R.
×

• Wiki

• Back

• Git