Solved

Outlook.exe /Importprf only run once via logon script

Posted on 2014-03-24
3
1,721 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
ID: 39953064
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
ID: 39953250
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
ID: 39953595
Excellent response - exactly what I was looking for.
0

Featured Post

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This Micro Tutorial will give you a basic overview of Windows Live Photo Gallery and show you various editing filters and touches to photos you can apply. This will be demonstrated using Windows Live Photo Gallery on Windows 7 operating system.

773 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