FUNCTION OUTLOOK()
DIM $prfrem,$waste,$explorview,$editorpref,$prf,$serverloc,
$exchgsvr,$prfloc,$prffile,$ppru,$exe,$ver,$idx,$keyname,$rc,
$outlook,$ns,$unread,$fldr,$x,$regexp,$MSOdir
$waste='FALSE' ; Empty Outlooks Deleted Items Folder on Exit
$explorview='Yes' ; Outlook Explorer View 'Yes' or Standard View 'No'
$editorpref=30001 ; Editor Preference 10001=Plain Text, 20001=HTML, and 30001=Rich Text
$prf='Outlook.prf'
$prffile='%temp%\'+$prf
$serverloc=@LSERVER+'\Netlogon\Profgen' ; Outlook Executables files location
$exchgsvr='EXCHANGE1' ; Main Exchange Server Location
IF @INWIN ;Windows NT/2k/XP/2003
$prfloc='HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles'
ELSE
;Windows 9x
$prfloc='HKCU\Software\Microsoft\Windows Messaging Subsystem\Profiles'
ENDIF
; -- Current User Profile
$ppru=$prfloc+'\'+@USERID
; -- Determine version of Outlook
$exe=ReadValue('HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE','')
$ver=SPLIT(GetFileVersion($exe),'.')[0]+'.0'
$MSOdir=SUBSTR($exe,1,Len($exe)-11)
; -- This is used for when you have people come into the company from another Exchange Server into yours
IF INGROUP('GROUPNAME') AND READVALUE($ppru+'\13dbb0c8aa05101a9bb000aa002fc45a','001e6602')<>$exchgsvr
$rc=WriteValue($ppru+'\13dbb0c8aa05101a9bb000aa002fc45a','001e6602',$exchgsvr,'REG_SZ')
$rc=WriteValue($ppru+'\13dbb0c8aa05101a9bb000aa002fc45a','001e6608',$exchgsvr,'REG_SZ')
ENDIF
; -- Look for Outlook Profile
;IF ReadValue($prfloc,'DefaultProfile')<>@USERID AND ReadValue($prfloc,'DefaultProfile')<>'MS Exchange Settings' OR @ERROR
IF (ReadValue($prfloc,'DefaultProfile')<>@USERID AND NOT INSTR(ReadValue($prfloc,'DefaultProfile'),'MS Exchange')) OR @ERROR
COPY $serverloc+'\'+$prf $prffile
$rc=WriteProfileString($prffile,'General','ProfileName',@USERID)
$rc=WriteProfileString($prffile,'General','DefaultProfile','Yes')
$rc=WriteProfileString($prffile,'General','OverwriteProfile','Yes')
$rc=WriteProfileString($prffile,'General','BackupProfile','No')
$rc=WriteProfileString($prffile,'Service1','AutoNameCheck','TRUE')
$rc=WriteProfileString($prffile,'Service1','EmptyWastebasket',$waste)
$rc=WriteProfileString($prffile,'Service1','CloseOriginalMessage','TRUE')
$rc=WriteProfileString($prffile,'Service2','HomeServer',$exchgsvr)
$rc=WriteProfileString($prffile,'Service2','MailboxName',@USERID)
SELECT
CASE
$ver='8.0' OR $ver='9.0' ;(e.g. 8.5.5104.0)
SHELL '%COMSPEC% /C '+$serverloc+'\newprof.exe -p '+$prffile+' -x'
$rc=WriteValue('HKCU\Software\Microsoft\Office\'+$ver+'\Outlook','Machine Name',@WKSTA,'REG_SZ')
$rc=WriteValue('HKCU\Software\Microsoft\Office\'+$ver+'\Outlook','CheckInternetAccounts',1,'REG_DWORD')
$rc=WriteValue('HKCU\Software\Microsoft\Office\'+$ver+'\Outlook','FirstRunDialog','False','REG_SZ')
$rc=WriteValue('HKCU\Software\Microsoft\Office\'+$ver+'\Outlook\Setup','PrimaryClient',1,'REG_DWORD')
$rc=WriteValue('HKLM\Software\Microsoft\Office\'+$ver+'\Outlook\Setup','MailSupport',1,'REG_DWORD')
$rc=WriteValue('HKLM\Software\Microsoft\Office\'+$ver+'\Outlook\Setup','First-Run','df83b12adc9cd511b57c0002a57ce19c','REG_BINARY')
IF $explorview='Yes'
$rc=WriteValue($prfloc+@userid+'\0a0d020000000000c000000000000046','001e0360','','REG_SZ')
$expview='010000002c0000000200000003000000ffffffffffffffffffffffffffffffff62000000270000003'
$expview=$expview+'c030000ac02000001000000000000000100000000000000c00000006400000003000000'
$rc=WriteValue('HKCU\Software\Microsoft\Office\'+$ver+'\Outlook\Office Explorer','Frame',$expview,'REG_BINARY')
ENDIF
CASE
$ver='10.0' OR $ver='11.0' OR $ver='12.0';(e.g. 10.0.2627.1)
$rc=DelValue('HKCU\Software\Microsoft\Office\'+$ver+'\Outlook\Setup','First-Run')
$rc=WriteValue('HKCU\Software\Microsoft\Office\'+$ver+'\Outlook\Setup','ImportPRF',$prffile,'REG_SZ')
IF $ver='10.0'
$rc=WriteValue('HKCU\Software\Microsoft\Office\'+$ver+'\Outlook\IM','Enabled',0,'REG_DWORD')
ENDIF
; -- This was added as we needed to generate Outlook Profiles in a Citrix Session - thanks Rad!
$outlook=CreateObject('Outlook.Application')
$ns=$outlook.getnamespace('MAPI')
$fldr=$ns.getdefaultfolder(6)
$unread=$fldr.unreaditemcount
$outlook=0
ENDSELECT
DEL $MSOdir+'welcome.msg'
ENDIF
ENDFUNCTION