+ Post New Thread
Page 5 of 6 FirstFirst 123456 LastLast
Results 61 to 75 of 89
Scripts Thread, Outlook profile setup logon script help in Coding and Web Development; Originally Posted by Steve21 Harr Cscript is for when it needs commandline items, like inputs/outputs e.g. if you're running it ...
  1. #61

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

  2. Thanks to mac_shinobi from:

    randle (27th February 2012)

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

  4. #63
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    594
    Thank Post
    66
    Thanked 16 Times in 15 Posts
    Rep Power
    19
    I've had a little play about and so far have this:

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

  5. #64
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    594
    Thank Post
    66
    Thanked 16 Times in 15 Posts
    Rep Power
    19
    Ok a little jiggling about and now have:
    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
    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?

  6. #65

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,680
    Thank Post
    3,210
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Quote Originally Posted by randle View Post
    Ok a little jiggling about and now have:
    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
    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 ?

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

  8. #67

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,680
    Thank Post
    3,210
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Quote Originally Posted by randle View Post
    Ok a little jiggling about and now have:
    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
    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.

  9. #68
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    594
    Thank Post
    66
    Thanked 16 Times in 15 Posts
    Rep Power
    19
    That is what I want it to do but the script does appear to do that when run manually already:

    (Without the Wscript.Echo)
    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
    Should it be different to the above?

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

  10. #69

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,680
    Thank Post
    3,210
    Thanked 1,030 Times in 955 Posts
    Rep Power
    361
    Quote Originally Posted by randle View Post
    That is what I want it to do but the script does appear to do that when run manually already:

    (Without the Wscript.Echo)
    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
    What is dwValueName , Just I can't see anything assigned to a variable named that

    --> If NOT IsNull(dwValueName) Then

  11. #70
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    594
    Thank Post
    66
    Thanked 16 Times in 15 Posts
    Rep Power
    19
    Right I've tidied it up....again 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:
    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
    Any ideas?

  12. #71
    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 think I finally have it:
    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'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.

  13. #72

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

  14. Thanks to Steve21 from:

    mac_shinobi (28th February 2012)

  15. #73

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

  16. #74

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

  17. Thanks to Steve21 from:

    mac_shinobi (29th February 2012)

  18. #75
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    594
    Thank Post
    66
    Thanked 16 Times in 15 Posts
    Rep Power
    19
    Quote Originally Posted by Steve21 View Post
    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 . 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!!?

SHARE:
+ Post New Thread
Page 5 of 6 FirstFirst 123456 LastLast

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
  •