Help with Outlook profile script



Hi!

I'm a beginner to vbscripting, so I hope someone can help me.

I would like to have a script (to add to my existing loginscript) that checks if the correct Outlook profile is configured in the users profile.

Outlook profiles are configured in the following registry key:
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\

I want to check if
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\NewProfile\
exist. (NewProfile is the name of the correct profile I apply to the user with a Outlook .prf file (See script below, profile name is configured in the .PRF file)).
I have found this script, but I can't make it work:

--------------------- Script begin -------------------------------------------

'************************************
'* Registry Key Exists (Function)
'* Returns a value (true / false)
'************************************
'This function checks to see if a passed registry key exists, and
'returns true if it does
'
'Requirements: The registry key you are looking for (RegistryKey)
'Note: RegistryKey MUST end in a backslash (\), or FALSE will be returned
Function RegistryKeyExists ("HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\NewProfile\")
'Ensure the last character is a backslash (\) - if it isn't, we aren't looking for a key
If (Right(RegistryKey, 1) <> "\") Then
'It's not a registry key we are looking for
RegistryKeyExists = false
Else
'If there isnt the key when we read it, it will return an error, so we need to resume
On Error Resume Next

'Try reading the key
WshShell.RegRead RegistryKey

'Catch the error
Select Case Err
'Error Code 0 = 'success'
Case 0:
RegistryKeyExists = true
'This checks for the (Default) value existing (but being blank); as well as key's not existing at all (same error code)
Case &h80070002:
'Read the error description, removing the registry key from that description
ErrDescription = Replace(Err.description, RegistryKey, "")

'Clear the error
Err.clear

'Read in a registry entry we know doesn't exist (to create an error description for something that doesnt exist)
WshShell.RegRead "HKEY_ERROR\"

'The registry key exists if the error description from the HKEY_ERROR RegRead attempt doesn't match the error
'description from our RegistryKey RegRead attempt
If (ErrDescription <> Replace(Err.description, "HKEY_ERROR\", "")) Then
RegistryKeyExists = true
Else
RegistryKeyExists = false
End If
'Any other error code is a failure code
Case Else:
RegistryKeyExists = false
End Select

'Turn error reporting back on
On Error Goto 0
End If
End Function
------------------- Script end --------------------------------------

If the key exist I want to continue running my loginscript, ie. map printers, drives etc. as that means the client is configured correct.

If the key does not exist I want to run the below script before mapping printers etc, which deletes the registry key HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\ and all keys, values etc. beneath it.
(This deletes all configured Outlook profiles in the users profile)

--------------------- Script begin -------------------------------------------
On Error Resume Next
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles"
Set objRegistry = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
DeleteSubkeys HKEY_CURRENT_USER, strKeypath
Sub DeleteSubkeys(HKEY_CURRENT_USER, strKeyPath)
objRegistry.EnumKey HKEY_CURRENT_USER, strKeyPath, arrSubkeys
If IsArray(arrSubkeys) Then
For Each strSubkey In arrSubkeys
DeleteSubkeys HKEY_CURRENT_USER, strKeyPath & "\" & strSubkey
Next
End If
objRegistry.DeleteKey HKEY_CURRENT_USER, strKeyPath
End Sub
------------------- Script end --------------------------------------


After that I want to run this script, which configures the correct Outlook profile by applying a .PRF file (A .prf file contains all information needed for configuring a Outlook profile):

--------------------- Script begin -------------------------------------------

' =====================================================================
'
' Purpose: Automatically sets up Microsoft Outlook from PRF file
' Written by: Chimera Computing Ltd
'
' =====================================================================
Option Explicit
On Error Resume Next

' =====================================================================
' Declare objects
' =====================================================================
Dim objWSHShell
Dim sFRKey, sFRSearch

' =====================================================================
' Set variables
' =====================================================================
sFRKey = "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Setup\First-Run"
Set objWSHShell = WScript.CreateObject("WScript.Shell")

' =====================================================================
' Get and check command line parameter for forcible reset
' =====================================================================
If Wscript.Arguments.Count > 0 Then
If Lcase(Wscript.Arguments(1)) = "forcereset" Then
objWSHShell.RegDelete "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Setup\First-Run"
End If
End If

' =====================================================================
' Search for registry key
' =====================================================================
sFRSearch = objWSHShell.RegRead(sFRKey)

' =====================================================================
' Does it exist? If not, set PRF location
' =====================================================================
If Err <> 0 Then
WScript.Echo "Importing PRF file into registry"
objWSHShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Setup\ImportPRF", "\\SERVER\NETLOGON\Outlook.PRF", "REG_SZ"
objWSHShell.RegDelete "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Setup\First-Run"
objWSHShell.RegDelete "HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Setup\FirstRun"
Else
WScript.Echo "Outlook PRF has already been imported"
End if

' =====================================================================
' Clear memory
' =====================================================================
set objWSHShell = Nothing

------------------- Script end --------------------------------------

The above script asumes that you only have Outlook 2003 installed on the client running the script (HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\ is the key that says it's Office 2003 (v11.0)).
I would like the script to check for Office version and only configure the correct version, because I have a mix of all clients in my network (And yes! I know that I should upgrade, but haven't had the time for that yet...).

HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\ = Office 2000
HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\ = Office XP
HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\ = Office 2003
HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\ = Office 2007

If have tested that the script works with all above versions of Outlook and it does (I modified the key from 11 to correct number).

Can anyone help me put together a script like mentioned below ?

Thanks in advance,

:-) Jens


.



Relevant Pages

  • RE: Fax Notificatin.. TIF file open error
    ... Right click the folder you want to create the file in, ... We modify the following registry key to force Outlook to use a specific ... Start Registry Editor. ...
    (microsoft.public.windows.server.sbs)
  • Re: OLE works in office but not at home.
    ... The problem was the line being left in the registry. ... the REXX sample program worked fine. ... AFAIK script blocker only exist for Outlook. ...
    (microsoft.public.outlook.program_vba)
  • Re: Identity Problems with Outlook Express
    ... the first time out - but if you forget to click "exit and log out" then ... Outlook Express, and after finally re-installing outlook express with ... the registry setting turned on to disable OE, ... script method to change the shortcuts to OE so that they forced the ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Re: Identity Problems with Outlook Express
    ... the first time out - but if you forget to click "exit and log out" then ... Outlook Express, and after finally re-installing outlook express with ... the registry setting turned on to disable OE, ... script method to change the shortcuts to OE so that they forced the ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • Identity Problems with Outlook Express
    ... Outlook Express, and after finally re-installing outlook express with ... the registry setting turned on to disable OE, ... kicked identities back in to life, and then applied the tomsterdam vbs ... script method to change the shortcuts to OE so that they forced the ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)