+ Post New Thread
Page 6 of 6 FirstFirst ... 23456
Results 76 to 89 of 89
Scripts Thread, Outlook profile setup logon script help in Coding and Web Development; Originally Posted by randle My original one had "NOT IfNull" but while I was playing about got changed to just ...
  1. #76

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    333
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Quote Originally Posted by randle View Post
    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

  2. #77

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,677
    Thank Post
    3,209
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Quote Originally Posted by Steve21 View Post
    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

  3. #78
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    594
    Thank Post
    66
    Thanked 16 Times in 15 Posts
    Rep Power
    19
    For the logon script, I've now changed the code in the logon script to:
    Code:
    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
    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
    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

  4. #79

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    333
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Quote Originally Posted by randle View Post
    For the logon script, I've now changed the code in the logon script to:
    Code:
    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

    Code:
    strValueName = "ImportPRF"
    oReg.GetBinaryValue HKEY_CURRENT_USER,strKeyPath,strValueName,dwValue
    On Error Resume Next
    If strValueName = "ImportPRF" Then
    It can never "not" be there.


    Steve

  5. #80
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    594
    Thank Post
    66
    Thanked 16 Times in 15 Posts
    Rep Power
    19
    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:
    Code:
    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?:
    Code:
    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
    Last edited by randle; 29th February 2012 at 11:46 AM.

  6. #81

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    333
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Quote Originally Posted by randle View Post
    For the section mentioned in the logoff script, would this be any better?:
    Code:
    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). 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

    Code:
    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
    Code:
    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

  7. #82
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    594
    Thank Post
    66
    Thanked 16 Times in 15 Posts
    Rep Power
    19
    Thanks for the explanation. I've changed it around again and I have:
    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
    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.

  8. #83

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    333
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Quote Originally Posted by randle View Post
    Thanks for the explanation. I've changed it around again and I have:
    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
    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

  9. #84

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    333
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Assuming it's this?

    Code:
    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:

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

  10. Thanks to Steve21 from:

    randle (29th February 2012)

  11. #85
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    594
    Thank Post
    66
    Thanked 16 Times in 15 Posts
    Rep Power
    19
    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?

  12. #86

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    333
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Quote Originally Posted by randle View Post
    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:

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

  13. #87
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    594
    Thank Post
    66
    Thanked 16 Times in 15 Posts
    Rep Power
    19
    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!?

  14. #88

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    333
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Quote Originally Posted by randle View Post
    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

  15. #89
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    594
    Thank Post
    66
    Thanked 16 Times in 15 Posts
    Rep Power
    19
    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.
    Code:
    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","\\ServerName\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.
    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.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
    Last edited by randle; 29th February 2012 at 01:45 PM.

  16. Thanks to randle from:

    mac_shinobi (29th February 2012)

SHARE:
+ Post New Thread
Page 6 of 6 FirstFirst ... 23456

Similar Threads

  1. Logon script help
    By brickwall53 in forum Windows Server 2008 R2
    Replies: 13
    Last Post: 17th June 2011, 11:48 AM
  2. Logon Script Help
    By neon in forum Coding
    Replies: 2
    Last Post: 16th September 2009, 10:48 AM
  3. Logon script not being called... HELP
    By AlexB in forum Windows
    Replies: 6
    Last Post: 28th April 2009, 10:42 AM
  4. HELP! - Logon Scripts
    By Hedghog in forum Windows
    Replies: 2
    Last Post: 26th September 2008, 10:50 AM
  5. Logon Script Help
    By djones in forum Scripts
    Replies: 17
    Last Post: 13th March 2008, 06:00 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •