$Rc = SetOption('NoVarsInString', 'On')
$Rc = SetOption('NoMacrosInString', 'On')
$RC = SetConsole('SHOW')
; Declaring Global Variables
DIM $FILE1 ; OutlookRan.txt on netshare share
DIM $FILE2 ; OutlookMessaging.reg on netshare share
DIM $FILE3 ; Office.reg on netshare share
DIM $FILE4 ; Default PRF file for profile setup
DIM $FILE5 ; OutlookRan.txt check file
DIM $PATH1 ; Path to Outlook folder on netshare
DIM $PATH2 ; Local Appdata path to Outlook settings
DIM $PATH3 ; Roaming Appdata path to Outlook settings
DIM $REGPATH1 ; Registry key path to Windows Messaging subsystem
DIM $REGPATH2 ; Registry key path to FirstRun Setup key
DIM $REGPATH3 ; Registry key path to First-Run Setup key
DIM $REGPATH4 ; Registry key path to ImportPRF Setup key
DIM $APP ; The EXE we want to run
DIM $KILLAPP1 ; script that makes sure Outlook is not running
DIM $REGEXPORTS ; script for registry exports
; Specify File and Path Variables
$FILE1 = '\\netshare\userconfigs$\' + @userid + '\PsCitrixConfig\Outlook\Outlookran.txt'
$FILE2 = '\\netshare\userconfigs$\' + @userid + '\PSCitrixConfig\Outlook\OutlookMessaging.reg'
$FILE3 = '\\netshare\userconfigs$\' + @userid + '\PSCitrixConfig\Outlook\Office.reg'
$FILE4 = 'c:\Progra~2\Micros~2\Custom14.prf'
$FILE5 = 'c:\Scripts\OutlookRan.txt'
$PATH1 = '\\netshare\userconfigs$\' + @userid + '\PSCitrixConfig\Outlook'
$PATH2 = 'c:\users\' + @userid + '\Appdata\Local\Microsoft\Outlook'
$PATH3 = 'c:\users\' + @userid + '\Appdata\Roaming\Microsoft\Outlook'
; Specify Registry Path Variables
$REGPATH1 = 'HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem'
$REGPATH2 = 'HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Setup'
$REGPATH3 = 'HKEY_CURRENT_USER\Software\Microsoft\Office'
; Provide the user a popup message asking them if they want to proceed with this script or to exit.
If MessageBox("This will rebuild your Outlook profile, Do you wish to continue? Press YES to rebuild your outlook profile, or press NO to cancel", " Rebuild Outlook profile", 36) = 6
; Now we're going to start deleteing data
$RC = MessageBox ("Once you click OK on this message the Outlook reset process will start. Please wait until you see another message informing you the rebuild has completed before using any office applications.", " Outlook profile rebuild started.....", 0, 10)
SHELL '%comspec% /c taskkill.exe /IM "outlook.exe" /F /T'
$RC = DELTREE($REGPATH1)
$RC = DELVALUE($REGPATH2, "FirstRun")
$RC = DELVALUE($REGPATH2, "First-Run")
$RC = DELVALUE($REGPATH2, "ImportPRF")
DEL $FILE1 /c
DEL $FILE2 /c
DEL $FILE3 /c
RD $PATH2 /S
RD $PATH3 /S
While (Exist($PATH2) OR Exist($PATH3)) Loop
MD $PATH2
MD $PATH3
$RC = WriteValue($REGPATH2, "FirstRun", "0", "REG_DWORD")
$RC = WriteValue($REGPATH2, "First-Run", "0", "REG_DWORD")
$RC = WriteValue($REGPATH2, "ImportPRF", $FILE4, "REG_SZ")
RUN "%ProgramFiles%\Microsoft\Office\Outlook.exe"
SLEEP 10 ; Pausing the let outlook sort out it's profile, next we kill Outlook.
SHELL '%comspec% /c taskkill.exe /IM "outlook.exe" /F /T'
SLEEP 5 ; Pause a moment to let Outlook close and clean up, then we copy our correct outlook profile settings out to our network share for safe keeping
COPY $FILE5 $PATH1
SHELL '%compspec% /c Reg Export "'+$REGPATH3+'" "'+$FILE3+'"'
SLEEP 5 ; Last pause before our final message box.
$RC = MessageBox ("Your Outlook profile has been Rebuilt, and your e-mail should now work properly. If you continue to have problems with using Outlook, please open a Helpdesk or contact extention 2500.", " Outlook Profile Rebuild Completed!", 0, 10)
ENDIF
EXIT