Steve21 Posted February 29, 2012 Posted February 29, 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!!? Can you post which one is the original? It's just going to be a case of when you're reading, you need to open a string, or binary depending which it is. If you're opening binary, and its' string it won't work etc. Steve
mac_shinobi Posted February 29, 2012 Posted February 29, 2012 Can you post which one is the original? It's just going to be a case of when you're reading, you need to open a string, or binary depending which it is. If you're opening binary, and its' string it won't work etc. Steve Will leave this to you @Steve21 as I don't really have the time and posting the odd bits and pieces is more then likely confusing @randle
randle Posted February 29, 2012 Author Posted February 29, 2012 For the logon script, I've now changed the code in the logon script to: On Error Resume Next If IsNull(strValueName) Then Else objShell.RegDelete "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\First-Run" If Err.Number = 0 Then End If Which is now deleting any value type called "First-Run" and handles the error if not present . I'm not sure why changing from "(dwValue)" to "(strValueName)" meant that it could no longer handle if the value wasn't present but the "On Error..." command seems to have taken care of this. My final logoff script is 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'll do some more testing to make sure this has definitely fixed all my problems and will then post back with both final scripts for others who may require the same type of process
Steve21 Posted February 29, 2012 Posted February 29, 2012 For the logon script, I've now changed the code in the logon script to: On Error Resume Next If IsNull(strValueName) Then Else objShell.RegDelete "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\First-Run" If Err.Number = 0 Then End If Which is now deleting any value type called "First-Run" and handles the error if not present . I'm not sure why changing from "(dwValue)" to "(strValueName)" meant that it could no longer handle if the value wasn't present but the "On Error..." command seems to have taken care of this. Your strValueName is a value you're setting isn't it? So how can it be null? (Assuming your script has the bits above it you've not pasted). Seems a bit of the logon script is missing. Same as your logoff script, You're effectively cheating and not actually finding the code at all, you're just forcing a delete always, and if it's not there ignoring the error [color="#FF0000"]strValueName = "ImportPRF" [/color]oReg.GetBinaryValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue On Error Resume Next [color="#FF0000"]If strValueName = "ImportPRF" Then[/color] It can never "not" be there. Steve
randle Posted February 29, 2012 Author Posted February 29, 2012 (edited) Yes it is what I'm setting but as mentioned, using "dwValue" won't delete all types of this value. The full logon script is: Dim objNetwork, strUserName, strDirectory, objFSO Dim objShell Dim Version set objShell = CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objNetwork = WScript.CreateObject("WScript.Network") strUserName = objNetwork.UserName If objFSO.FileExists("C:\Users\" & strUserName & "\AppData\Local\Microsoft\Outlook\outlook.pst") Then Else 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 = "First-Run" oReg.GetBinaryValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue On Error Resume Next If IsNull(strValueName) Then Else objShell.RegDelete "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\First-Run" If Err.Number = 0 Then End If strValueName = "FirstRun" oReg.GetBinaryValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue2 If IsNull(dwValue2) Then Else objShell.RegDelete "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\FirstRun" End If objShell.RegWrite "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\ImportPRF","\\MyFRDC\Outlook Profiles\CVHS IMAP Profile.prf","REG_SZ" End If End IF Is that any better? For the section mentioned in the logoff script, would this be any better?:strValueName = "ImportPRF" oReg.GetBinaryValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue If IsNull(strValueName) Then Else objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF" End If Edited February 29, 2012 by randle
Steve21 Posted February 29, 2012 Posted February 29, 2012 For the section mentioned in the logoff script, would this be any better?:strValueName = "ImportPRF" oReg.GetBinaryValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue If IsNull(strValueName) Then Else objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF" End If The problem you'll get (but you can leave it if you want, it'll still do what you want, just always force kill it ) is you are never going to "not" delete it. Here's an example: oReg.Get Binary Value A, B, C, D A = HKLM/HKCU B = Path to Key C = KeyName D = Return Value from registry So A,B,C are values you give the command, and it returns D. However you're saying is IsNull©. C is never null as you set it the line above it. Which is working as it'll always delete it, however it kind of makes a lot of it pointless strValueName = "ImportPRF" oReg.GetBinaryValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue If IsNull(strValueName) Then Else objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF" End If objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF" Those two pieces of code are identitical basically. If that makes sense? As you can never fail the If statement. Steve
randle Posted February 29, 2012 Author Posted February 29, 2012 Thanks for the explanation. I've changed it around again and I have: 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 Else objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF" End If However from what i understand this is checking whether the value is empty and only deleting it if it is but how do I get this to delete the actual value item if it simply exists and also handle if the file isn't present at all? The current code still shows an error if the item doesn't exist!! Also the strange thing is that like this, if the value is present it will not delete the file yet if I change it to "NOT IsNull" it will delete the value!! Apologies if I'm missing the point.
Steve21 Posted February 29, 2012 Posted February 29, 2012 Thanks for the explanation. I've changed it around again and I have: 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 Else objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF" End If However from what i understand this is checking whether the value is empty and only deleting it if it is but how do I get this to delete the actual value item if it simply exists and also handle if the file isn't present at all? The current code still shows an error if the item doesn't exist!! Also the strange thing is that like this, if the value is present it will not delete the file yet if I change it to "NOT IsNull" it will delete the value!! Apologies if I'm missing the point. You're getting an error on the above? Works fine here. Assuming it's still a BinaryValue, or are you using a String for ImportPRF? If so need to change it, but it should be binary? Also I assume "file" you mean as reg key? As this isn't deleting any files. Steve
Steve21 Posted February 29, 2012 Posted February 29, 2012 Assuming it's this? 2.In the HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Setup subkey, set the value of ImportPRF to a string value that specifies the name and path of the PRF file. For example, set ImportPRF to \\server1\share\outlook.prf. If so try this one: 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.getStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue If IsNull(dwValue) Then Else objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF" End If That's if it's a String Value. Steve 1
randle Posted February 29, 2012 Author Posted February 29, 2012 It's actually a string value rather than binary so is probably why it's not deleting it. I'm pretty sure it needs to be string as Outlook acts correctly when this value is present. What do I change in the script for string rather than binary? Yes sorry I meant "value name" rather than "file". Doesn't Reg Key refer to the folder in the Left-hand pane rather than the item in the Right-hand one?
Steve21 Posted February 29, 2012 Posted February 29, 2012 It's actually a string value rather than binary so is probably why it's not deleting it. I'm pretty sure it needs to be string as Outlook acts correctly when this value is present. What do I change in the script for string rather than binary? Yes sorry I meant "value name" rather than "file". Doesn't Reg Key refer to the folder in the Left-hand pane rather than the item in the Right-hand one? Yeah officially it's "insert name" value, but reg is easier! Try this for string value: 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.getStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue If IsNull(dwValue) Then Else objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF" End If Should work. Steve
randle Posted February 29, 2012 Author Posted February 29, 2012 Hahaaaa that's the badger. Just the one word "GetStringValue) makes all the difference Works as expected and doesn't error when run again. Super job thanks. I take it I can also add to my logon script to additionally check for "First-Run" of either type by simply changing this too and then can take out my on error handling!?
Steve21 Posted February 29, 2012 Posted February 29, 2012 Hahaaaa that's the badger. Just the one word "GetStringValue) makes all the difference Works as expected and doesn't error when run again. Super job thanks. I take it I can also add to my logon script to additionally check for "First-Run" of either type by simply changing this too and then can take out my on error handling!? Pretty much yes It's silly how it can't just pick whichever type you want and use Get"Thingy"Value, but it's fussy Steve
randle Posted February 29, 2012 Author Posted February 29, 2012 (edited) Well a massive thank you to you for your time, patience and help. I can't thank you enough. I've learnt so much about vbs in this thread alone . Thank you too mac_shinobi for your input. Maybe no-one else has this requirement or gives two hoots but the final scripts are as follows. Logon: Checks for a local outlook.pst file which is added when the prf file is initially run and if not present, will delete first-run reg values and insert an ImportPRF value pointing to the specified prf location ready to setup Outlook on first run per computer.Dim objNetwork, strUserName, strDirectory, objFSO Dim objShell Dim Version set objShell = CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") Set objNetwork = WScript.CreateObject("WScript.Network") strUserName = objNetwork.UserName If objFSO.FileExists("C:\Users\" & strUserName & "\AppData\Local\Microsoft\Outlook\outlook.pst") Then Else 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 = "First-Run" oReg.GetBinaryValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue If IsNull(dwValue) Then Else objShell.RegDelete "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\First-Run" End If strValueName = "FirstRun" oReg.GetBinaryValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue2 If IsNull(dwValue2) Then Else objShell.RegDelete "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\FirstRun" End If strValueName = "First-Run" oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue3 If IsNull(dwValue3) Then Else objShell.RegDelete "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\First-Run" End If objShell.RegWrite "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\ImportPRF","\\[color=#ff0000]ServerName[/color]\Outlook Profiles\IMAP Profile.prf","REG_SZ" End If Logoff: Checks for presence of "ImportPRF" String value which if still present at logoff means Outlook hasn't been run on this computer. This value will be removed so that when logging onto computers that have already been setup, it isn't set to run again. 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.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue If IsNull(dwValue) Then Else objShell.RegDelete "HKCU\SOFTWARE\Microsoft\Office\14.0\Outlook\Setup\ImportPRF" End If Right....off to cause trouble elsewhere Edited February 29, 2012 by randle 1
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now