randle (27th February 2012)
Just found another potential problem!...Currently, at logon, if the file "outlook.pst" isn't present, the registry value is then imported meaning when Outlook is run, it performs a first-run using the specified prf file. In most scenarios this is fine however when they log onto a computer that doesn't have the outlook.pst file present but then don't open up Outlook, when they next log back on to a computer already set up, this will have retained the ImportPRF value set previously and so performed first-run again.
I'm now thinking that I could have a logoff script that would check whether the ImportPRF reg value still exists at this point and if so replace it with the First-Run value again meaning that previously setup computers are not affected. Any ideas on a script for this or whether there's a better way of doing this!?
I've had a little play about and so far have this:
This gets as far as telling me that the registry key value needs to be deleted but then doesn't appear to delete it. Can anyone tell me where I've gone wrong at all? Many places I'm sureCode:Const HKEY_CURRENT_USER = &H80000002 strComputer = "." Set objRegistry = GetObject("winmgmts:\\" & _ strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\Microsoft\Office\14.0\Outlook\Setup" strValueName = "ImportPRF" objRegistry.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue If NOT IsNull(strValueName) Then Wscript.Echo "The registry key value needs to be deleted." objRegistry.DeleteKey HKEY_CURRENT_USER,strKeyPath,strvalueName Else Wscript.Echo "The registry key exists." End If![]()
Ok a little jiggling about and now have:Which deletes the registry value if it exists but now need to add the First-Run value back in with hex data included....Any ideas?Code:set objShell = CreateObject("WScript.Shell") Const HKEY_CURRENT_USER = &H80000002 strComputer = "." Set objRegistry = GetObject("winmgmts:\\" & _ strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\Microsoft\Office\14.0\Outlook\Setup" strValueName = "ImportPRF" objRegistry.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue If NOT IsNull(dwValueName) Then Wscript.Echo "The registry key value needs to be deleted." objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF" Else Wscript.Echo "The registry key exists." End If
Before you delete the value with the hex value in your logon script, get it to write this value to the C: Drive in a hidden directory as a registry file and you can re merge this silently on your logoff script ?
Unless this hex value is the same for all of them regardless of machine / user logged on etc ?
Turns out the hex value isn't the same for everyone so isn't going to work although it also seems apparent that simply deleting the ImportPRF value on it's own is enough as the First-Run value re-creates itself automatically without issue......Hopefully.
I thought I was pretty much there but running this script at logoff through GPO has given me the error "Unable to remove registry key" HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ ImportPRF" Code: 80070002, Source: WshShell.RegDelete.
I thought the above script covered this if the value is not present!!? The final edition doesn't have the Wscript.Echo on the last but one line btw!
That is what I want it to do but the script does appear to do that when run manually already:
(Without the Wscript.Echo)
Should it be different to the above?Code:set objShell = CreateObject("WScript.Shell") Const HKEY_CURRENT_USER = &H80000002 strComputer = "." Set objRegistry = GetObject("winmgmts:\\" & _ strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\Microsoft\Office\14.0\Outlook\Setup" strValueName = "ImportPRF" objRegistry.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue If NOT IsNull(dwValueName) Then objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF" Else End If
Also I thought the above already handled if the value didn't exist!?
Right I've tidied it up....againand have something very similar to the original script now and appears to delete the value when present although still doesn't handle if the value isn't present:
Any ideas?Code:set objShell = CreateObject("WScript.Shell") Const HKEY_CURRENT_USER = &H80000001 strComputer = "." Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\Microsoft\Office\14.0\Outlook\Setup" strValueName = "ImportPRF" oReg.GetBinaryValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue If IsNull(dwValue) Then objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF" Else End If
Well think I finally have it:I'm still a little unsure why the original code couldn't handle the value not being there but seems the error handling has done the trick.Code:set objShell = CreateObject("WScript.Shell") Const HKEY_CURRENT_USER = &H80000001 strComputer = "." Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\Microsoft\Office\14.0\Outlook\Setup" strValueName = "ImportPRF" oReg.GetBinaryValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue On Error Resume Next If strValueName = "ImportPRF" Then objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF" If Err.Number = 0 Then Else Err.Clear End If End If

That's back to front logic I think (Unless it's just been a long day)Code:If IsNull(dwValue) Then objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF" Else End If
If is null, it doesn't exist so won't delete. (But you're trying to)
If it's not null, it exists, so won't delete. (As you're not trying to)
Steve
mac_shinobi (28th February 2012)
mac_shinobi (29th February 2012)
My original one had "NOT IfNull" but while I was playing about got changed to just "IfNull" instead. I understand what you're saying and is the wrong way round however my final script is now using "If strValueName = "ImportPRF" Then" instead as seemed more logical, for me anyway. If this is wrong feel free to correct as am still very getting to grips with VB.
However now that I have a logoff script that appears to work I now how another problem. The original logon script will delete the value "First-Run" from the setup key if present but now for some reason I'm getting First-Run string values instead of binary values appearing and the logon script doesn't appear to want to delete this value unless it's binary value.
I'm going to have a play but thought I'd explain in case you know why or have a quick fix!!?
There are currently 1 users browsing this thread. (0 members and 1 guests)