randle Posted December 16, 2011 Posted December 16, 2011 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? [color=#008000]ping 1.1.1.1 -n 1 -w 5000 >NUL[/color] [color=#008000]IF EXIST h:\outlook_profile.txt goto end else[/color] [color=#008000]Outlook_Profile_Created > h:\outlook_profile.txt[/color] [color=#008000]attrib “h:\outlook_profile.txt” +h[/color] [color=#008000]“c:\Program Files (x86)\Microsoft Office\OFFICE11\OUTLOOK.EXE” /importprf \\server\share\OutlookProfileSettings.PRF[/color] [color=#008000]:end[/color]
AceDaz Posted December 16, 2011 Posted December 16, 2011 Hi. I am only starting with Outlook configs etc. But why would you ping a server first? Also, do you redirect the Application Data using Group Policy?
randle Posted December 16, 2011 Author Posted December 16, 2011 The ping command is meant to be an invalid IP address, not a server and is intended to delay the execution of a script [Batch file examples - Wait]. I have a hybrid RM CC4/Vanilla network but all users are managed through RM usertype policies meaning there is a unique setup of appdata storage/roaming behaviour however it can be redirected through GPO regardless if you require.
pcunite Posted January 6, 2012 Posted January 6, 2012 Another way, which I've found the be the easiest, is to use the Outlook Profiler tool. It's not free but saved my bacon when I had to make some crazy changes across different versions of Outlook. Also have roaming profiles gotten better? Seems there is always a profile getting trashed and causing weird errors.
randle Posted January 9, 2012 Author Posted January 9, 2012 I'm not looking at spending any money on this but thanks anyway. I'm storing the pst file in the local part of the profile so not relying on this roaming seeing as pst files over the network is a MS no, no. Does anyone have any ideas on my original question? I'd also be interested to know whether the profile can be imported without starting Outlook as this halts the login process until the password is entered and Outlook closed!
MattGibson Posted January 10, 2012 Posted January 10, 2012 Hi Guys, I use the following script and yes I found it on the web somewhere so I cant take full credit for this! Copy Code 1 to your logon.bat located in SYSVOL Copy Code 2 to notepad, Save as ".vbs" in SYSVOL Copy your pre-made .prf into SYSVOL The following script will look for the users directory to see if they already have an Outlook folder in Application Data, if not then the script will proceed with importing the .prf In you logon.bat file you'll need to add the following: CODE 1 cscript \\SERVER\netlogon\Outlook2007.vbs Now copy this to notepad and save as .VBS CODE 2 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:\Documents and Settings\" & strusername & "\Application Data\Microsoft\Outlook" ' Create the various objects Set objFSO = CreateObject("Scripting.FileSystemObject") 'Import PRF If objFSO.FolderExists(strDirectory) 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\12.0\Outlook\Setup\First-Run" WshShell.RegDelete "HKCU\Software\Microsoft\Office\12.0\Outlook\Setup\FirstRun" WshShell.RegWrite "HKCU\Software\Microsoft\Office\12.0\Outlook\Setup\ImportPRF","\\SERVER\netlogon\Outlook.PRF","REG_SZ" 'Wscript.Echo "Finished modifying registry End If
randle Posted January 24, 2012 Author Posted January 24, 2012 Thanks Matt. I haven't gotten round to testing this out yet so apologies for not thanking you sooner. I'll give it a go when I get the chance and get back to you with the results. An initial question though. Why are you using a bat file to call a vbs when the vbs can be set to run at logon on its own!? Am I missing something?
mac_shinobi Posted January 24, 2012 Posted January 24, 2012 Thanks Matt. I haven't gotten round to testing this out yet so apologies for not thanking you sooner. I'll give it a go when I get the chance and get back to you with the results. An initial question though. Why are you using a bat file to call a vbs when the vbs can be set to run at logon on its own!? Am I missing something? The bat file is calling the vbs to run using cscript which is different to wscript Although if the user launches outlook before said script finishes, does that mess it up some what ?? 1
randle Posted January 24, 2012 Author Posted January 24, 2012 Ah thanks. I could see that cscript was used but thought cscript could be called within the initial code of the vbs
garethEds Posted January 24, 2012 Posted January 24, 2012 Take a look at this post: http://www.edugeek.net/forums/office-software/86602-outlook-2010-autoconfiguration-issue.html We use an old version of RichProfile. The newer version needs paying for. Shame really as it's an excellent piece of software. I've been testing the free/old one for over 4 months now and am considering moving it out to staff. The only problem I've come across is that it doesn't hold your signatures. Gareth
randle Posted January 25, 2012 Author Posted January 25, 2012 Looks good although need to be able to add more details than it'll allow i.e. SMTP server. Also does this open Outlook during initial logon? I'm after something that ideally won't open Outlook during the profile creation as my original batch file did this and wouldn't bother looking for a different solution if I didn't want to change this behaviour. A little more info: Originally I had a different vb script which would load the profile to use, to set Outlook on first use, into the registry but this relied on detecting whether a profile had already been setup as whether to run or not. This didn't work here as the pst file for personal folders is stored in the local part of the profile due to using IMAP and not storing this type of file on a network drive. When a user then logged onto a different computer, the script would detect that the profile already existed and so not run but Outlook then couldn't access the pst file because this was not stored in the roaming part of the profile and not present on this computers local part meaning that errors are displayed and can't send emails...So based on that I'm after a similar script that will run depending on whether a defined folder or file exists. It looks like the script that MattGibson provided will do this but just need to test.
mac_shinobi Posted January 25, 2012 Posted January 25, 2012 It looks like the script that MattGibson provided will do this but just need to test. VB Script that MattGibson posted looks like it will do the trick, although like you mentioned it does not prompt for SMTP server or any of that. Script that MattGibson posted does not by the looks of it execute outlook in anyway as there is nothing that has run or exec in the script that points to the outlook exe
randle Posted January 25, 2012 Author Posted January 25, 2012 (edited) My outlook.prf file has all the necessary details to setup the account which looks like is loaded into the registry in the script so hopefully will work a dream If interested, the VB script i used orginally was the one at the bottom of this post: Deploy Outlook mail profile settings via GPO or script | HowTo-Outlook but as mentioned simply relied on whether a prfile had been setup rather than the existence of a file/folder. Seems that I could have tested this by now instead of replying to posts Edited January 25, 2012 by randle 1
randle Posted February 6, 2012 Author Posted February 6, 2012 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:\Documents and Settings\" & strusername & "\Application Data\Microsoft\Outlook" ' Create the various objects Set objFSO = CreateObject("Scripting.FileSystemObject") 'Import PRF If objFSO.FolderExists(strDirectory) 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\12.0\Outlook\Setup\First-Run" WshShell.RegDelete "HKCU\Software\Microsoft\Office\12.0\Outlook\Setup\FirstRun" WshShell.RegWrite "HKCU\Software\Microsoft\Office\12.0\Outlook\Setup\ImportPRF","\\SERVER\netlogon\Outlook.PRF","REG_SZ" 'Wscript.Echo "Finished modifying registry End If Can this be changed to check for a file rather than a directory?
randle Posted February 6, 2012 Author Posted February 6, 2012 (edited) 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 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 [color=#ff0000]'[/color]strDirectory = "C:\Users\" & strusername & "AppData\Local\Microsoft\Outlook" ' Create the various objects Set objFSO = CreateObject("Scripting.FileSystemObject") 'Import PRF [color=#ff0000]'[/color]If objFSO.FolderExists(strDirectory) Then [color=#ff0000]If objFSO.FileExists("C:\Users\%username%\AppData\Local\Microsoft\Outlook\outlook.pst") Then[/color] '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? Edited February 6, 2012 by randle
mac_shinobi Posted February 6, 2012 Posted February 6, 2012 (edited) 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 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 [color=#ff0000]'[/color]strDirectory = "C:\Users\" & strusername & "AppData\Local\Microsoft\Outlook" ' Create the various objects Set objFSO = CreateObject("Scripting.FileSystemObject") 'Import PRF [color=#ff0000]'[/color]If objFSO.FolderExists(strDirectory) Then [color=#ff0000]If objFSO.FileExists("C:\Users\%username%\AppData\Local\Microsoft\Outlook\outlook.pst") Then[/color] '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 Set wshShell = CreateObject( "WScript.Shell" ) Dim User User = wshShell.ExpandEnvironmentStrings( "%username%" ) MsgBox User Unless you concatenated it ie : [color=#ff0000]If objFSO.FileExists("C:\Users\" & [/color]objShell.ExpandEnvironmentStrings( "%username%" ) &[color=#ff0000] "\AppData\Local\Microsoft\Outlook\outlook.pst") Then[/color] Site with ref to ExpandEnviromentStrings ( http://www.robvanderwoude.com/vbstech_data_environment.php ) There are other ways of obtaining the currently logged on user ie using WMI --> http://blogs.technet.com/b/heyscriptingguy/archive/2005/05/26/how-can-i-get-just-the-user-name-when-using-the-win32-computersystem-class.aspx Edited February 6, 2012 by mac_shinobi
browolf Posted February 6, 2012 Posted February 6, 2012 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? [color=#008000]ping 1.1.1.1 -n 1 -w 5000 >NUL[/color] [color=#008000]IF EXIST h:\outlook_profile.txt goto end else[/color] [color=#008000]Outlook_Profile_Created > h:\outlook_profile.txt[/color] [color=#008000]attrib “h:\outlook_profile.txt” +h[/color] [color=#008000]“c:\Program Files (x86)\Microsoft Office\OFFICE11\OUTLOOK.EXE” /importprf \\server\share\OutlookProfileSettings.PRF[/color] [color=#008000]:end[/color] 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 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.
Jamo Posted February 6, 2012 Posted February 6, 2012 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 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 2
browolf Posted February 6, 2012 Posted February 6, 2012 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!
randle Posted February 7, 2012 Author Posted February 7, 2012 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?
mac_shinobi Posted February 7, 2012 Posted February 7, 2012 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 : 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
mac_shinobi Posted February 7, 2012 Posted February 7, 2012 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
randle Posted February 8, 2012 Author Posted February 8, 2012 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!
mac_shinobi Posted February 8, 2012 Posted February 8, 2012 (edited) 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 If objFSO.FileExists("C:\Users\" & strUserName & "\AppData\Local\Microsoft\Outlook\outlook.pst") Then Becomes Dim strFile strFile = "C:\Users\" & strUserName & "\AppData\Local\Microsoft\Outlook\outlook.pst" If objFSO.FileExists(strFile) Then ' rest of the code Edited February 8, 2012 by mac_shinobi
randle Posted February 8, 2012 Author Posted February 8, 2012 The only message is what was in my previous reply unfortunately although with the suggested change I now have the numbers (23, 15)!
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