Solved

Outlook.exe /Importprf only run once via logon script

Posted on 2014-03-24
3
1,683 Views
Last Modified: 2014-03-25
Hi,

I have Win7 users located in DomainB Active Directory who access their mailbox which is located in DomainA.  The mailboxes are getting migrated onto an exchange server in DomainB.  Therefore I needed to run the outlook.exe /importprf for the existing users to update the outlook profile (these are not users who haven't logged on before).  I did this by using a small vbs script execute at user logon via Group Policy (user policy):

Dim objShell : Set objShell = CreateObject("Wscript.Shell")
strProgramPath = "Outlook.exe /importprf \\server.domain.local\share\new.prf"
objShell.Run strProgramPath

This works really well & the user is then pointed to the mailbox on DomainB.  My only problem is that this script runs on every user logon, but I only need this to run once for all the users.

Is anyone aware of the syntax I need to add into my script so that this updates the FirstRun / First-Run reg key so that it won't run again after initial execution?

Sorry - I'm not a scripter so you may have to tell me the actual lines I need to add.

Thanks.
0
Comment
Question by:meepmaker
  • 2
3 Comments
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
Comment Utility
i dont believe the firstrun process will work for you as the login script would just keep deleting the key after Outlook added it back again.


i would have to check for a  dummy text file on running the script. if file does not exist, then the update hasnt run yet.... so create the text file and run update

something like this code.  The login script would continue to be applied until all users were migrated across.
'-------------------------------------------------	
option explicit
' Constants for opening files
''''''''''''''''''''''''''''''''''
Const OpenFileForReading = 1
Const OpenFileForWriting = 2
Const OpenFileForAppending = 8

	dim prflocation, lf

	prflocation="\\server.domain.local\share\new.prf"
	lf = "Outlook_profile.Update"

	dim oNet, objShell, fso
	dim profile_path, lfl, tslf
	dim datetime, strProgramPath
	
	Set oNet = CreateObject("WScript.Network")
	Set objShell = CreateObject("WScript.Shell")
	datetime=Year(now()) & Right("0" & Month(now()), 2) & Right("0" & Day(now()), 2) & "=" & Right("0" & Hour(now()), 2) & Right("0" & Minute(now()), 2) '& Right("0" & Second(now()), 2)

	Set fso = CreateObject("Scripting.FileSystemObject")  
	'sysfld = fso.GetSpecialFolder(1)    'the system folder
	'winfld =  fso.GetSpecialFolder(0)   'the windows folder
	profile_path = objShell.ExpandEnvironmentStrings("%USERPROFILE%") & "\"
	
	if(fso.FileExists(profile_path & lf)) Then
		'already done this profile
		wscript.echo "Already process profile update"
	else
		strProgramPath = "Outlook.exe /importprf " & prfLocation
		wscript.echo strProgramPath '<<<TESTING>>>>
		'objShell.Run strProgramPath
		
		' 
		Set tslf = fso.CreateTextFile(profile_path & lf,true)	

		tslf.Write (Onet.ComputerName & " , " & "BEGIN" & " , " & Datetime & vbCrLf)
		tslf.Close()
	
	end if

	set onet = nothing
	Set FSO = Nothing


	

Open in new window

0
 

Author Comment

by:meepmaker
Comment Utility
Hi  Robberbaron,

Thats brilliant - thanks very much, I really appreciate your help.  I can now see the marker file being created at c:\Users\%Username%\Outlook_profile.Update

I don't actually need the Windows Script Host dialogue boxes stating "\\server.domain.local\share\new.prf" & "Already process profile update" & as I don't want the end user to see these - on relection I can see the wscript.echo at lines 29 & 32 - I guess you just need to comment these lines out?  I've done that now & I'm no longer presented with the Windows Script Host dialogue boxes.

Unfortuntely the importprf function within the script didn't work - this was simply due to line 33 being commented out.  After removing this comment - it works perfectly.

Thanks,
M
0
 

Author Closing Comment

by:meepmaker
Comment Utility
Excellent response - exactly what I was looking for.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you basic overview of the control panel section on Windows 7. It will depth in Network and Internet, Hardware and Sound, etc. This will be demonstrated using Windows 7 operating system.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now