Outlooking on Outlook - your answers are here

Outlook Global Technical Support Team Blog

Change first day of the week in Outlook (FirstDov) through automatic script!

Change first day of the week in Outlook (FirstDov) through automatic script!

  • Comments 1
  • Likes

If you want to change the calendar Work Week for example from “ Sunday until Thursday” you can do that automatically by simple running the below sample script.
We took some time and we wrote this sample code which will help you to deploy this to all your users, but before doing this please read the statement below:

SETWorkDays sample script:

MICROSOFT MAKES NO WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE SAMPLE APPLICATION THAT HAS BEEN SENT TO YOU
PLEASE USE IT ON YOUR OWN RISK AND JUST AS A SAMPLE APPLICATION THAT ILUSTRATES HOW SUCH A FUNCTIONALITY CAN BE IMPLEMETED
This sample is not supported under any Microsoft standard support program or service. The sample code is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of  the sample code and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the code be liable for any  damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code or documentation.

Sample Script:
---------------------

call SetWorkDays


Sub SetWorkDays
Const REG_DWORD = 1
Const HKEY_CURRENT_USER = &H80000001
Const SOFTWAREMICROSOFTOFFICE = "Software\Microsoft\Office\"
Const OUTLOOKOPTIONSCALENDAR = "\Outlook\Options\Calendar"
Const olHiddenItems = 1
Const olFolderCalendar = 9
Const PR_ROAMING_XMLSTRREAM = "http://schemas.microsoft.com/mapi/proptag/0x7C080102"
Const FILTER = "[MessageClass] = 'IPM.Configuration.WorkHours'"
Const OWORKDAYS = "3C576F726B446179733E"      '<WorkDays>
Const CWORKDAYS = "3C2F576F726B446179733E"    '</WorkDays>
Const CTIMESLOT = "3C2F54696D65536C6F743E" '</TimeSlot>
Const SUNDAY = "53756E646179" 'Sunday
Const MONDAY = "4D6F6E646179" 'Monday
Const TUESDAY = "54756573646179" 'Tuesday
Const WEDNESDAY = "5765646E6573646179" 'Wednesday
Const THURSDAY = "5468757273646179" 'Thursday
Const FRIDAY = "467269646179" 'Friday
Const SATURDAY = "5361747572646179" 'Saturday
Const RETURNPLUSTABS = "0D0A0909"
Const SPACE = "20"
Const REGSUNDAY = &H80
Const REGMONDAY = &H40
Const REGTUESDAY = &H20
Const REGWEDNESDAY = &H10
Const REGTHURSDAY = &H8
Const REGFRIDAY = &H4
Const REGSATURDAY = &H2

'==========================================================================================================================================
'  modify the two values below to set the desired work days
NEWWORKDAYS = SUNDAY & SPACE & MONDAY & SPACE & TUESDAY & SPACE & WEDNESDAY & SPACE & THURSDAY '& SPACE & FRIDAY & SPACE & SATURDAY
REGWORKDAYS = REGSUNDAY + REGMONDAY + REGTUESDAY + REGWEDNESDAY + REGTHURSDAY '+ REGFRIDAY + REGSATURDAY
'
'==========================================================================================================================================

Dim oCalendarAssociatedContentTable 'As Outlook.Table
Dim oMsgWorkingHoursPrefs 'As Outlook.StorageItem
Dim oPropAcc 'As Outlook.PropertyAccessor
Dim olApp 'As Outlook.Application
Dim oCalendar 'As Outlook.Folder
Dim strXmlProp 'As String
Dim oRow 'As Outlook.Row
Dim strStart 'As Integer
Dim strEnd 'As Integer
Dim strHead 'As String
Dim strTail 'As String

 

Set olApp = CreateObject("Outlook.Application")
olApp.GetNameSpace("MAPI").Logon "","" ,False,True


Set oCalendar = olApp.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar)

Set oCalendarAssociatedContentTable = oCalendar.GetTable(FILTER, olHiddenItems)

'exit if message not found or more than one found
'TODO: if more than one, pick the latest one
If oCalendarAssociatedContentTable.GetRowCount <> 1 Then
                      Exit Sub
End If

'open the item
Set oRow = oCalendarAssociatedContentTable.GetNextRow()
Set oMsgWorkingHoursPrefs = olApp.Session.GetItemFromID(oRow.Item("EntryID"), "")


'open the PR_ROAMING_XMLSTREAM property
Set oPropAcc = oMsgWorkingHoursPrefs.PropertyAccessor
strXmlProp = oPropAcc.BinaryToString(oPropAcc.GetProperty(PR_ROAMING_XMLSTRREAM))

strStart = InStr(1, strXmlProp, OWORKDAYS)
If (strStart = 0) Then
                        'handle case where no day is selected
                       strStart = InStr(1, strXmlProp, CTIMESLOT) - 1
                      If (strStart = 0) Then Exit Sub'this prop is bad
                      strHead = Mid(strXmlProp, 1, strStart + Len(CTIMESLOT)) + RETURNPLUSTABS + OWORKDAYS
                      strTail = Mid(strXmlProp, strStart + Len(CTIMESLOT) + 1, Len(strXmlProp) - (strStart + Len(CTIMESLOT)) + 1)   
   
Else
                        strStart = strStart + Len(OWORKDAYS) - 1
                        strEnd = InStr(strStart, strXmlProp, CWORKDAYS)

                        If (strEnd = 0) Then Exit Sub
                        strHead = Mid(strXmlProp, 1, strStart)
                        strTail = Mid(strXmlProp, strEnd, Len(strXmlProp) - strEnd + 1)
end if


'inject the new WorkDays
strXmlProp = strHead & NEWWORKDAYS & strTail

'set the prop
oPropAcc.SetProperty PR_ROAMING_XMLSTRREAM, oPropAcc.StringToBinary(strXmlProp)

'save the message
oMsgWorkingHoursPrefs.Save


'we must also now set the registry value to ensure that Outlook remembers everything
Dim objRegistry
Dim olVersion 'As String
Dim ret 'As Integer
olVersion = Left(olApp.Version, 4)

Set objRegistry = GetObject("winmgmts:root\default:stdregprov")
ret = objRegistry.SetDWordValue(HKEY_CURRENT_USER, SOFTWAREMICROSOFTOFFICE & olVersion & OUTLOOKOPTIONSCALENDAR, "WorkDay", REGWORKDAYS)
If ret <> 0 Then
'TODO: error handling
End If

olApp.GetNameSpace("MAPI").Logoff
olApp.Quit

Set oCalendarAssociatedContentTable = Nothing
Set oMsgWorkingHoursPrefs = Nothing
Set objRegistry = Nothing
Set oCalendar = Nothing
Set oPropAcc = Nothing
Set oRow = Nothing
Set olApp = Nothing
End Sub

 

Explanation:
--------------------
You have two things to change in the script if you want to use something else:


'==========================================================================================================================================
'  modify the two values below to set the desired work days
NEWWORKDAYS = SUNDAY & SPACE & MONDAY & SPACE & TUESDAY & SPACE & WEDNESDAY & SPACE & THURSDAY & SPACE & FRIDAY & SPACE & SATURDAY
REGWORKDAYS = REGSUNDAY + REGMONDAY + REGTUESDAY + REGWEDNESDAY + REGTHURSDAY + REGFRIDAY + REGSATURDAY
'==========================================================================================================================================

Here all days will be checked. If you want to only check Sunday through Thursday you can add a ' to comment the end of the lines:

NEWWORKDAYS = SUNDAY & SPACE & MONDAY & SPACE & TUESDAY & SPACE & WEDNESDAY & SPACE & THURSDAY ' & SPACE & FRIDAY & SPACE & SATURDAY
REGWORKDAYS = REGSUNDAY + REGMONDAY + REGTUESDAY + REGWEDNESDAY + REGTHURSDAY ' + REGFRIDAY + REGSATURDAY

Or simply delete the end of the lines

NEWWORKDAYS = SUNDAY & SPACE & MONDAY & SPACE & TUESDAY & SPACE & WEDNESDAY & SPACE & THURSDAY
REGWORKDAYS = REGSUNDAY + REGMONDAY + REGTUESDAY + REGWEDNESDAY + REGTHURSDAY


 

Through sample ADM:

Also you can also achieve this trough GPO - if you edit the ADM template - but the menus will become grayed out for the users:
You cannot do that if you only add the keys under the normal path because at the next boot, you’ll get what’s stored in the message, unless you have set it via GPO

Software\Microsoft\Office\XX.0\Outlook\Options\Calendar
 DWORD – Workday – values:
 Sets the value in the option ''Calendar work week'.
124 |                       120 |                               60 |                           126 |                              30 |                                
Monday to Friday | Monday to Thursday | Tuesday to Friday | Monday to Saturday | Wednesday to Saturday |


 142 |                            252 |                        254|
Thursday to Sunday | Sunday to Friday | All seven days


 Software\Microsoft\Office\XX.0\Outlook\Options\Calendar
 DWORD - FirstDOW - values:
    0 |             1 |           2 |                   3 |                 4 |           5 |            6|
 Sunday | Monday | Tuesday | Wednesday | Thursday | Friday | Saturday

Explanation:
------------------
We store those settings in the Calendar folder itself, and load it from there and cache it to registry when we boot.
We store it in the associated content message IPM.Configuration.WorkHours.
As I mentioned when you only set the registry key, you don’t update the message in the folder. Therefore at next boot, you’ll get what’s stored in the message, unless you have set it via GPO.

a. Download MFCMAPI from:
http://www.microsoft.com/en-us/download/details.aspx?id=2953
b. Install it on the user’s computer
c. Open MFCMAPI
d. hit 'OK' to clear the 'About MFCMAPI' information dialog.
e. Select 'Session' from the drop-down menu and click ‘Logon and Display Store Table.’
f. right click on the calendar – Open Associated Contents Folder
g. select from under the Subject field - IPM.Configuration.WorkHours.
I. Go to PR_ROAMING_XMLSTREAM
j. Open this Property and you will see all the settings saved here

 

MICROSOFT MAKES NO WARRANTIES ABOUT THE SUITABILITY, RELIABILITY OR ACCURACY OF THE SAMPLE APPLICATION THAT HAS BEEN SENT TO YOU
PLEASE USE IT ON YOUR OWN RISK AND JUST AS A SAMPLE APPLICATION THAT ILUSTRATES HOW SUCH A FUNCTIONALITY CAN BE IMPLEMETED
This sample is not supported under any Microsoft standard support program or service. The sample code is provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of  the sample code and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the code be liable for any  damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code or documentation.

Sample Script:

const HKEY_CURRENT_USER = &H80000001
strComputer = "."

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_
strComputer & "\root\default:StdRegProv")

strKeyPath = "Software\Policies\Microsoft\Office\xx.0\Outlook\Options\Calendar"
strKeyValue = "WorkDay"
oReg.CreateKey HKEY_CURRENT_USER,strKeyPath
oReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strKeyValue,248

strKeyPath = "Software\Policies\Microsoft\Office\xx.0\Outlook\Options\Calendar"
strKeyValue = "CalDefStart"
oReg.CreateKey HKEY_CURRENT_USER,strKeyPath
oReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strKeyValue,480

strKeyPath = "Software\Policies\Microsoft\Office\xx.0\Outlook\Options\Calendar"
strKeyValue = "CalDefEnd"
oReg.CreateKey HKEY_CURRENT_USER,strKeyPath
oReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strKeyValue,1020

strKeyPath = "Software\Policies\Microsoft\Office\xx.0\Outlook\Options\Calendar"
strKeyValue = "Alter Calendar Type"
oReg.CreateKey HKEY_CURRENT_USER,strKeyPath
oReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strKeyValue,1

strKeyPath = "Software\Policies\Microsoft\Office\xx.0\Outlook\Options\Calendar"
strKeyValue = "Alter Calendar Lang"
oReg.CreateKey HKEY_CURRENT_USER,strKeyPath
oReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strKeyValue,1033


strKeyPath = "Software\Policies\Microsoft\Office\xx.0\Outlook\Options\Calendar"
strKeyValue = "FirstWOY"
oReg.CreateKey HKEY_CURRENT_USER,strKeyPath
oReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strKeyValue,0

strKeyPath = "Software\Policies\Microsoft\Office\xx.0\Outlook\Options\Calendar"
strKeyValue = "FirstDOW"
oReg.CreateKey HKEY_CURRENT_USER,strKeyPath
oReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strKeyValue,0

strKeyPath = "Software\Policies\Microsoft\Office\xx.0\Outlook\Options\Calendar"
strKeyValue = "WeekNum"
oReg.CreateKey HKEY_CURRENT_USER,strKeyPath
oReg.SetDWORDValue HKEY_CURRENT_USER,strKeyPath,strKeyValue,0


'wscript.echo "success!"

Where "xx" is the version from Outlook 12 or 14.


 

I hope this helps you, and I’m glad to receive any comments or suggestions.

 

Comments
  • Hi,
    many thanks for this great article, it would be good idea if you can create custom ADM file and ready to execute script file and attache them to this article.

    regards,

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment