+ Post New Thread
Page 2 of 6 FirstFirst 123456 LastLast
Results 16 to 30 of 89
Scripts Thread, Outlook profile setup logon script help in Coding and Web Development; Originally Posted by randle Having a little tinker myself I've tried the following modifications to try and do what I ...
  1. #16

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,853
    Thank Post
    3,369
    Thanked 1,065 Times in 984 Posts
    Rep Power
    367
    Quote Originally Posted by randle View Post
    Having a little tinker myself I've tried the following modifications to try and do what I ask but on running Outlook it simply looks like it's not set to first-run

    Code:
    Dim objNetwork, strUserName, WshShell, strDirectory, objFSO
    Dim objShell
    Dim Version
    ' Create Outlook object and Shell object
    set objShell = CreateObject("WScript.Shell")
    'Get user's name
    Set objNetwork = WScript.CreateObject("WScript.Network")
    strUserName = objNetwork.UserName 
    'See if the user needs Outlook configured
    'strDirectory = "C:\Users\" & strusername & "AppData\Local\Microsoft\Outlook"
    ' Create the various objects
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'Import PRF
    'If objFSO.FolderExists(strDirectory) Then
    If objFSO.FileExists("C:\Users\%username%\AppData\Local\Microsoft\Outlook\outlook.pst") Then
    'Wscript.Echo "Skipped the registry edits. Directory exists
    Else
    'Wscript.Echo "Start performing registry edits. Directory does not exist
    On Error Resume Next
    Err.Clear
    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.RegDelete "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\First-Run"
    WshShell.RegDelete "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\FirstRun"
    WshShell.RegWrite "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\ImportPRF","\\MyServer\Outlook Profiles\CVHS IMAP Profile.prf","REG_SZ"
    'Wscript.Echo "Finished modifying registry
    End IF
    The red is obviously my modifications but am I missing something?
    I think you would still have to use the strDirectory variable purely and simply because I think you would have to use expandenviroment to get the %username% ie

    Code:
    Set wshShell = CreateObject( "WScript.Shell" )
    Dim User
    User =  wshShell.ExpandEnvironmentStrings( "%username%" )
    MsgBox User
    Unless you concatenated it ie :

    Code:
    If objFSO.FileExists("C:\Users\" & objShell.ExpandEnvironmentStrings( "%username%" ) & "\AppData\Local\Microsoft\Outlook\outlook.pst") Then
    Site with ref to ExpandEnviromentStrings ( http://www.robvanderwoude.com/vbstec...nvironment.php )

    There are other ways of obtaining the currently logged on user ie using WMI --> http://blogs.technet.com/b/heyscript...tem-class.aspx
    Last edited by mac_shinobi; 6th February 2012 at 02:57 PM.

  2. #17
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,527
    Thank Post
    107
    Thanked 89 Times in 75 Posts
    Blog Entries
    46
    Rep Power
    40
    Quote Originally Posted by randle View Post
    Hi

    I'm using the below example script to apply an outlook profile at logon. It appears to do what I want however would like to be able to set this to run again for all users should I make a change to the prf file. I'm thinking of something along the lines of if a value in the script is incrememted, it will run again.

    Can this be done and if so what do I need to add?

    Code:
    ping 1.1.1.1 -n 1 -w 5000 >NUL
    IF EXIST h:\outlook_profile.txt goto end else
    Outlook_Profile_Created > h:\outlook_profile.txt
    attrib “h:\outlook_profile.txt” +h
    “c:\Program Files (x86)\Microsoft Office\OFFICE11\OUTLOOK.EXE” /importprf \\server\share\OutlookProfileSettings.PRF
    :end
    Although the answers have gone a different route, I would just like to point out. 'else' doesn't work in batch files.

    what you have to do is

    Code:
    if not exist c:\outlook_profile1.txt (
    do stuff
    echo hello > c:\outlook_profile1.txt)
    then if you want to apply a new profile just increment the number.

  3. #18
    Jamo's Avatar
    Join Date
    Jan 2009
    Posts
    1,354
    Thank Post
    66
    Thanked 175 Times in 147 Posts
    Rep Power
    60
    Quote Originally Posted by browolf View Post
    Although the answers have gone a different route, I would just like to point out. 'else' doesn't work in batch files.

    what you have to do is

    Code:
    if not exist c:\outlook_profile1.txt (
    do stuff
    echo hello > c:\outlook_profile1.txt)
    then if you want to apply a new profile just increment the number.
    ELSE works in batch files, you have to have it all on the same line though OR use ( brackets to enclose the IF statement

    If Else statements in batch files at Mark Needham

  4. 2 Thanks to Jamo:

    browolf (6th February 2012), mac_shinobi (6th February 2012)

  5. #19
    browolf's Avatar
    Join Date
    Jun 2005
    Location
    Mars
    Posts
    1,527
    Thank Post
    107
    Thanked 89 Times in 75 Posts
    Blog Entries
    46
    Rep Power
    40
    Quote Originally Posted by Jamo View Post
    ELSE works in batch files, you have to have it all on the same line though OR use ( brackets to enclose the IF statement

    If Else statements in batch files at Mark Needham
    I did not know that!

  6. #20
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    597
    Thank Post
    66
    Thanked 16 Times in 15 Posts
    Rep Power
    19
    Ok finally got round to having a go at this and my modifications didn't appear to make a difference however when running the originally provided code with minimal change to simply represent locations here, this also didn't take effect. I ran it from the bat file so cscript was called as part of this. No registry changes were made regardless of the specified folder not existing so not sure what needs tweaking.

    There were no errors displayed onscreen either so doesn't look to be the syntax....Am I doing something wrong?

  7. #21

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,853
    Thank Post
    3,369
    Thanked 1,065 Times in 984 Posts
    Rep Power
    367
    Quote Originally Posted by randle View Post
    Ok finally got round to having a go at this and my modifications didn't appear to make a difference however when running the originally provided code with minimal change to simply represent locations here, this also didn't take effect. I ran it from the bat file so cscript was called as part of this. No registry changes were made regardless of the specified folder not existing so not sure what needs tweaking.

    There were no errors displayed onscreen either so doesn't look to be the syntax....Am I doing something wrong?
    Try something like this :

    Code:
    Dim objNetwork, strUserName, strDirectory, objFSO
    Dim objShell
    Dim Version
    ' Create required objects ie Shell, FileSystemObject and Network
    set objShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objNetwork = WScript.CreateObject("WScript.Network")
    
    'Get user's name
    strUserName = objNetwork.UserName 
    
    'See if the user needs Outlook configured
    'strDirectory = "C:\Users\" & strusername & "AppData\Local\Microsoft\Outlook"
    
    'Import PRF
    If objFSO.FileExists("C:\Users\" & strUserName & "\AppData\Local\Microsoft\Outlook\outlook.pst") Then
    'Wscript.Echo "Skipped the registry edits. Directory exists
    Else
    'Wscript.Echo "Start performing registry edits. Directory does not exist
    On Error GoTo HandleError
    
    objShell.RegDelete "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\First-Run"
    objShell.RegDelete "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\FirstRun"
    objShell.RegWrite "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\ImportPRF","\\MyServer\Outlook Profiles\CVHS IMAP Profile.prf","REG_SZ"
    End IF
    HandleError:
        msgbox "Got error number " & Err.Number & ":" & Err.Description

  8. #22

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,853
    Thank Post
    3,369
    Thanked 1,065 Times in 984 Posts
    Rep Power
    367
    You had

    On Error Resume Next
    Err.Clear

    So I presume this was ignoring the errors and if there were any it was clearing them anyway so I have used an error handler which uses a messagebox to prompt you with any errors so if there are any errors in the coding it will hopefully highlight this by the line number or at least prompt you with an error.

    I also noticed that you had used the network object to obtain the username so Have used this instead of the other method ie

    Set objNetwork = Wscript.CreateObject("Wscript.Network")

    strUserName = objNetwork.UserName

  9. #23
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    597
    Thank Post
    66
    Thanked 16 Times in 15 Posts
    Rep Power
    19
    Slowly getting there. Thanks so much for the help

    Running this manually as a domain administrator gave me the message
    \\myserver\netlogon\ImportOutlookProfile.vbs(20, 15) Microsoft VBScript compilation error: Syntax error
    Are the numbers line and character references? If so this lands on the "On Error..." line!

  10. #24

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,853
    Thank Post
    3,369
    Thanked 1,065 Times in 984 Posts
    Rep Power
    367
    Quote Originally Posted by randle View Post
    Slowly getting there. Thanks so much for the help

    Running this manually as a domain administrator gave me the message
    Are the numbers line and character references? If so this lands on the "On Error..." line!
    Does it give you a more accurate error type ie --> Code 800 Error messages. VBScripts using WSH commands

    Just wondering if you adjust the code similar to how you had it before

    Code:
    If objFSO.FileExists("C:\Users\" & strUserName & "\AppData\Local\Microsoft\Outlook\outlook.pst") Then
    Becomes

    Code:
    Dim strFile
    
    strFile = "C:\Users\" & strUserName & "\AppData\Local\Microsoft\Outlook\outlook.pst"
    If objFSO.FileExists(strFile) Then
    ' rest of the code
    Last edited by mac_shinobi; 8th February 2012 at 12:29 PM.

  11. #25
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    597
    Thank Post
    66
    Thanked 16 Times in 15 Posts
    Rep Power
    19
    The only message is what was in my previous reply unfortunately although with the suggested change I now have the numbers (23, 15)!

  12. #26

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,853
    Thank Post
    3,369
    Thanked 1,065 Times in 984 Posts
    Rep Power
    367
    Quote Originally Posted by randle View Post
    The only message is what was in my previous reply unfortunately although with the suggested change I now have the numbers (23, 15)!
    Code:
    If objFSO.FileExists(strFile) Then
    Only thing I can think of is maybe there is a space in the path which is throwing it out so wondering if we use the Trim function ie

    Code:
    strFile = "C:\Users\" & Trim(strUserName) & "\AppData\Local\Microsoft\Outlook\outlook.pst"
    
    If objFSO.FileExists(Trim(strFile)) Then

  13. #27

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,705
    Thank Post
    335
    Thanked 517 Times in 485 Posts
    Rep Power
    180
    On Error GoTo HandleError is VB only, not VBS.

    Steve

  14. #28

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,853
    Thank Post
    3,369
    Thanked 1,065 Times in 984 Posts
    Rep Power
    367
    Quote Originally Posted by Steve21 View Post
    On Error GoTo HandleError is VB only, not VBS.

    Steve
    In that case delete the on error goto lines and also the HandleError: line as well ( when I googled it , it showed that you could use this on vbs ) obviously said site was wrong.

  15. #29
    randle's Avatar
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    597
    Thank Post
    66
    Thanked 16 Times in 15 Posts
    Rep Power
    19
    Still no joy unfortunately. Same as before. If I new a little vbs myself I wouldn't feel so useless. Maybe I should set some time aside!!

  16. #30

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,705
    Thank Post
    335
    Thanked 517 Times in 485 Posts
    Rep Power
    180
    Quote Originally Posted by randle View Post
    Still no joy unfortunately. Same as before. If I new a little vbs myself I wouldn't feel so useless. Maybe I should set some time aside!!

    Code:
    Dim objNetwork, strUserName, strDirectory, objFSO
    Dim objShell
    Dim Version
    ' Create required objects ie Shell, FileSystemObject and Network
    set objShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objNetwork = WScript.CreateObject("WScript.Network")
    
    'Get user's name
    strUserName = objNetwork.UserName 
    
    'See if the user needs Outlook configured
    'strDirectory = "C:\Users\" & strusername & "AppData\Local\Microsoft\Outlook"
    
    'Import PRF
    If objFSO.FileExists("C:\Users\" & strUserName & "\AppData\Local\Microsoft\Outlook\outlook.pst") Then
    'Wscript.Echo "Skipped the registry edits. Directory exists
    Else
    'Wscript.Echo "Start performing registry edits. Directory does not exist
    
    
    objShell.RegDelete "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\First-Run"
    objShell.RegDelete "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\FirstRun"
    objShell.RegWrite "HKCU\Software\Microsoft\Office\14.0\Outlook\Setup\ImportPRF","\\MyServer\Outlook Profiles\CVHS IMAP Profile.prf","REG_SZ"
    End IF
    Runs without errors here (Just commented out the regdeeltes so I didn't kill my pc, but should be fine).

    Does that work for you?

    Steve

SHARE:
+ Post New Thread
Page 2 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
  •