+ Post New Thread
Page 4 of 6 FirstFirst 123456 LastLast
Results 46 to 60 of 89
Scripts Thread, Outlook profile setup logon script help in Coding and Web Development; That was the first article I found when searching and looked good but couldn't see what bit I needed. I've ...
  1. #46
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    603
    Thank Post
    68
    Thanked 17 Times in 16 Posts
    Rep Power
    19
    That was the first article I found when searching and looked good but couldn't see what bit I needed. I've taken the part you suggested and added it to the script so now have
    Code:
    'Wscript.Echo "Start performing registry edits. Directory does not exist
    Function RegistryItemExists ("HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Setup\First-Run")
      'If there isnt the item when we read it, it will return an error, so we need to resume
      On Error Resume Next
    objShell.RegDelete "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Setup\First-Run"
    Function RegistryItemExists ("HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Setup\FirstRun")
      'If there isnt the item when we read it, it will return an error, so we need to resume
      On Error Resume Next
    objShell.RegDelete "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Setup\FirstRun"
    objShell.RegWrite "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Setup\ImportPRF","\\MyServer\Outlook Profiles\CVHS IMAP Profile.prf","REG_SZ"
    End IF
    However I know this is wrong because "On Error Resume Next" is going to simply run the next line which isn't what should happen so how do I implement this. Apologies for my ignorance once more.

  2. #47

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,933
    Thank Post
    3,465
    Thanked 1,090 Times in 1,005 Posts
    Rep Power
    371
    I would look at the 2nd link I posted ( edited ) as that has a shorter version.

    Depending on if you are checking for values or just the keys will determine which chunk of code you would use

    http://yorch.org/2011/10/two-ways-to...sing-vbscript/

    If it doesn't work ( due to the resume next ) I will create a reg key on my machine and have a play around with it.

    Code:
    Function RegKeyExists(Key)  Dim oShell, entry  On Error Resume Next Set oShell = CreateObject("WScript.Shell")  entry = oShell.RegRead(Key)  If Err.Number <> 0 Then    Err.Clear    RegKeyExists = False Else    Err.Clear    RegKeyExists = True End IfEnd Function
    The first one is using the method RegRead from WScript.Shell.If the given key is not found, it will rise an error, so we need to use an On Error Resume Next (which I don’t really like).

    We would need to pass to the function a string like HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Exp lorer\ (note the trailing \) if we are looking for a Registry Key (those that look like a folder). If we want to check if a value inside a key exists, we would remove the trailing \, like HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Int ernet Settings\Zones\3\CurrentLevel.

    Last edited by mac_shinobi; 9th February 2012 at 01:15 PM.

  3. Thanks to mac_shinobi from:

    randle (9th February 2012)

  4. #48

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,731
    Thank Post
    344
    Thanked 520 Times in 488 Posts
    Rep Power
    180
    Can't really test it but this logic should work, not sure if I missed anything out but:

    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
    
    
    objShell.RegWrite "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\ImportPRF","\\MyServer\Outlook Profiles\CVHS IMAP Profile.prf","REG_SZ"
    
    
    
    End IF
    *Edit - Did a quick check with echo's instead of deletes and seems to work for me. Any luck Randle?

    Steve
    Last edited by Steve21; 9th February 2012 at 01:40 PM.

  5. Thanks to Steve21 from:

    randle (9th February 2012)

  6. #49
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    603
    Thank Post
    68
    Thanked 17 Times in 16 Posts
    Rep Power
    19
    I've populated it as follows with the key, which I'm taking it I need to do!?
    Code:
    Function RegKeyExists("HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Outlook\Setup\First-Run")
      Dim oShell, entry
      On Error Resume Next
      Set oShell = CreateObject("WScript.Shell")
      entry = oShell.RegRead(Key)
      If Err.Number <> 0 Then
        Err.Clear
        RegKeyExists = False
      Else
        Err.Clear
        RegKeyExists = True
      End If
    End Function
    but how/where do I implement this into the existing script?

  7. #50

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,933
    Thank Post
    3,465
    Thanked 1,090 Times in 1,005 Posts
    Rep Power
    371
    That function will either return true ( for it exists ) or false for when it does not so you could do an if statement on the function , I would personally assign each registry key to a constant or a string ie

    Const RegOne = "HKCU\Software\....."
    Const RegTwo = "HKCU\Software\Microsoft\...."
    Const RegThree etc

    If RegKeyExists(RegOne) = "True" Then
    'do what you need if the key exists
    else
    'do what you need if it does not exist
    End If

    Steve21 has posted a script above with ref to the registry side already

  8. Thanks to mac_shinobi from:

    randle (9th February 2012)

  9. #51
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    603
    Thank Post
    68
    Thanked 17 Times in 16 Posts
    Rep Power
    19
    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.

  10. #52

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,731
    Thank Post
    344
    Thanked 520 Times in 488 Posts
    Rep Power
    180
    Quote Originally Posted by randle View Post
    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

  11. Thanks to Steve21 from:

    mac_shinobi (9th February 2012)

  12. #53

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,933
    Thank Post
    3,465
    Thanked 1,090 Times in 1,005 Posts
    Rep Power
    371
    Quote Originally Posted by Steve21 View Post
    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

  13. #54
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    603
    Thank Post
    68
    Thanked 17 Times in 16 Posts
    Rep Power
    19
    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?

  14. #55

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,933
    Thank Post
    3,465
    Thanked 1,090 Times in 1,005 Posts
    Rep Power
    371
    Quote Originally Posted by randle View Post
    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

    Code:
    wscript \\SERVER\netlogon\Outlook2007.vbs

  15. #56
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    603
    Thank Post
    68
    Thanked 17 Times in 16 Posts
    Rep Power
    19
    Sorry, what I meant was so I could simply run the vbs file directly rather than calling an interpreteur.

  16. #57

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,731
    Thank Post
    344
    Thanked 520 Times in 488 Posts
    Rep Power
    180
    Quote Originally Posted by randle View Post
    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

  17. #58

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,933
    Thank Post
    3,465
    Thanked 1,090 Times in 1,005 Posts
    Rep Power
    371
    Quote Originally Posted by Steve21 View Post
    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 )

  18. #59
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    603
    Thank Post
    68
    Thanked 17 Times in 16 Posts
    Rep Power
    19
    Well that's embarrassing ...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?

  19. #60

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,731
    Thank Post
    344
    Thanked 520 Times in 488 Posts
    Rep Power
    180
    Quote Originally Posted by randle View Post
    Well that's embarrassing ...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

  20. Thanks to Steve21 from:

    randle (22nd February 2012)



SHARE:
+ Post New Thread
Page 4 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, 12:48 PM
  2. Logon Script Help
    By neon in forum Coding
    Replies: 2
    Last Post: 16th September 2009, 11:48 AM
  3. Logon script not being called... HELP
    By AlexB in forum Windows
    Replies: 6
    Last Post: 28th April 2009, 11:42 AM
  4. HELP! - Logon Scripts
    By Hedghog in forum Windows
    Replies: 2
    Last Post: 26th September 2008, 11:50 AM
  5. Logon Script Help
    By djones in forum Scripts
    Replies: 17
    Last Post: 13th March 2008, 07: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
  •