Jump to content

Outlook profile setup logon script help


Recommended Posts

Posted

Hold the line!!!! Steve21's script has only gone and done it. I've tested a fair bit now and seems to be performing as desired when no outlook.pst file is detected i.e. deleting the First-Run regvalue and adding the ImportPRF value and simply taking no action when the file is present.

 

The only change I had to make was to remove the trailing "\" as these are values rather than keys.

 

Thanks so much for your help guys. You've been so patient and given so much of your time even if I didn't have a clue at times ;)

 

I'm going to test this a little more so will let you know if I hit any more hurdles but initial testing looks good.

 

Thanks again.

Posted
Hold the line!!!! Steve21's script has only gone and done it. I've tested a fair bit now and seems to be performing as desired when no outlook.pst file is detected i.e. deleting the First-Run regvalue and adding the ImportPRF value and simply taking no action when the file is present.

 

The only change I had to make was to remove the trailing "\" as these are values rather than keys.

 

Thanks so much for your help guys. You've been so patient and given so much of your time even if I didn't have a clue at times ;)

 

I'm going to test this a little more so will let you know if I hit any more hurdles but initial testing looks good.

 

Thanks again.

 

Huzzah :) If you get any problems give us a shout, sure someone can work it through

 

Steve

  • Thanks 1
Posted
Huzzah :) If you get any problems give us a shout, sure someone can work it through

 

Steve

 

More thanks to Steve21 as I have only had a little time to post links / examples etc. Thumbs up to Steve

  • 2 weeks later...
Posted

Just bringing this alive again. Is there any way that this script can be set to run using the wscript interpreter? Is there a reason why it has to be run using cscript?

 

I understand cscript runs entirely in the command line whereas wscript is used more so for when popup windows are required but in this case there's no user interaction within the script so shouldn't be an issue or am I missing something here?

 

The reason I want to do this is that I have a mixed environment of vanilla and RM CC4 computers. The Vanilla computers will run this script fine during logon but the CC4 computers won't (Currently investigating why with RM Support) which makes me think cscript has been restricted for some reason but if this script can be made to run from wscript then this shouldn't be an issue.

 

Any ideas?

Posted
Just bringing this alive again. Is there any way that this script can be set to run using the wscript interpreter? Is there a reason why it has to be run using cscript?

 

I understand cscript runs entirely in the command line whereas wscript is used more so for when popup windows are required but in this case there's no user interaction within the script so shouldn't be an issue or am I missing something here?

 

The reason I want to do this is that I have a mixed environment of vanilla and RM CC4 computers. The Vanilla computers will run this script fine during logon but the CC4 computers won't (Currently investigating why with RM Support) which makes me think cscript has been restricted for some reason but if this script can be made to run from wscript then this shouldn't be an issue.

 

Any ideas?

 

Same way you did to run it in cscript with regards to creating a bat file but instead of using cscript you would use wscript ie

 


wscript \\SERVER\netlogon\Outlook2007.vbs

Posted
Sorry, what I meant was so I could simply run the vbs file directly rather than calling an interpreteur.

 

Shouldn't be a reason you can't. There's nothing special that's command line only on the version I posted above (That I remember anyway), just remember most student accounts can't run scripts, unless it's a logon script under admin etc.

 

Steve

Posted
Shouldn't be a reason you can't. There's nothing special that's command line only on the version I posted above (That I remember anyway), just remember most student accounts can't run scripts, unless it's a logon script under admin etc.

 

Steve

 

Unless the command has been run succesfully on the machine to set it to cscript then from what I am aware wscript is the default one so if you just literally set it as a startup or logon script then it should run using wscript ( assuming you don't execute the vb script from the bat file )

Posted

Well that's embarrassing :redface:...When I previously tried running the script directly, nothing happened and so thought it was because cscript needed to be called upon. Running it directly now appears to work fine!!

 

Out of interest why was cscript required initially?

Posted
Well that's embarrassing :redface:...When I previously tried running the script directly, nothing happened and so thought it was because cscript needed to be called upon. Running it directly now appears to work fine!!

 

Out of interest why was cscript required initially?

 

Harr :) Cscript is for when it needs commandline items, like inputs/outputs e.g. if you're running it in cmd and want to input a variable etc

 

But for running normal script shouldn't need it.

 

Steve

  • Thanks 1
Posted
Harr :) Cscript is for when it needs commandline items, like inputs/outputs e.g. if you're running it in cmd and want to input a variable etc

 

But for running normal script shouldn't need it.

 

Steve

 

Presume this is when you do something like using the shell to execute a command in the command prompt ie

 

objshell.run "cmd /k ping hostname"

 

I know you can ping using wmi and other methods etc

  • Thanks 1
Posted

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!?

Posted

I've had a little play about and so far have this:

 

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

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 sure ;)

Posted
Ok a little jiggling about and now have:
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

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?

Posted
Ok a little jiggling about and now have:
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

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?

 

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 ?

Posted

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!

Posted
Ok a little jiggling about and now have:
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

 

Isn't the above the wrong way around, if the key does not exist then there is no need to try and delete it, if it does exist ( the 2nd part of the If Else Statement ) then delete the key.

Posted

That is what I want it to do but the script does appear to do that when run manually already:

 

(Without the Wscript.Echo)

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

Should it be different to the above?

 

Also I thought the above already handled if the value didn't exist!?

Posted
That is what I want it to do but the script does appear to do that when run manually already:

 

(Without the Wscript.Echo)

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

 

What is dwValueName , Just I can't see anything assigned to a variable named that

 

--> If NOT IsNull(dwValueName) Then

Posted

Right I've tidied it up....again :suicide: and 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:

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

 

Any ideas?

Posted
Well think I finally have it:
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

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.

Posted
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.

 

If IsNull(dwValue) Then
  objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF"
Else
  
End If

 

That's back to front logic I think (Unless it's just been a long day)

 

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

  • Thanks 1
Posted
If IsNull(dwValue) Then
  objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF"
Else
  
End If

 

That's back to front logic I think (Unless it's just been a long day)

 

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

 

It did seem a bit back to front but I don't think i've ever used the IsNull function, Think I should do now seeing as it is easier then using an if statement to check if it is equal to "" which is the same as IsNull.

Posted
It did seem a bit back to front but I don't think i've ever used the IsNull function, Think I should do now seeing as it is easier then using an if statement to check if it is equal to "" which is the same as IsNull.

 

Aye, Generally I do too, only issue is sometimes "" is still linked to a memory spot so can have something assigned to it even though it should be nothing as such. Null doesn't as such. But yeah, either works normally.

 

Steve

  • Thanks 1
Posted

That's back to front logic I think (Unless it's just been a long day)

 

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

 

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 :doh:. 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!!?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...