Jump to content

Recommended Posts

Posted (edited)

Hi guys

 

I am struggling to put together a script that determines the correct version of Office installed and then to add the appropriate registry key.

 

Basically I have a prf profile that I need to add to user Outlook accounts. The problem is that on some PCs the prf extension is associated with PicsRules of IE.

 

I have the regstry settings that make the correct file association:

 

Windows Registry Editor Version 5.00

 

[HKEY_CLASSES_ROOT\prffile\Shell\Open\Command]

@="\"C:\\Program Files\\Microsoft Office\\OFFICE12\\OUTLOOK.EXE\"

 

/PromptImportPRF \"%1\""

 

However we have a mix of Outlook 11.0 and 12.0.

 

so a second regisrty addition:

 

Windows Registry Editor Version 5.00

 

[HKEY_CLASSES_ROOT\prffile\Shell\Open\Command]

@="\"C:\\Program Files\\Microsoft Office\\OFFICE11\\OUTLOOK.EXE\"

 

/PromptImportPRF \"%1\""

These files are called 12.0.reg & 11.0.reg respectively

 

 

They are stored in the NETLOGON folder in a subdirectory call outlook.

 

I have stringed together a couple of scripts to

1 determine the correct version

 

and then

 

2. run the appropriate reg file

 

This is what I have (as a VBS):

 

Dim myVariable1

 

myVariable1 = objword

Set objWord = CreateObject("word.Application", "localhost")

Wscript.Echo "Version: " & objword.Version

objWord.Quit

 

Set WshShell = WScript.CreateObject("WScript.Shell")

LogonDC= WshShell.ExpandEnvironmentStrings("%logonserver%")

bWaitOnReturn = True

If myvariable1=12.0 Then wshshell.Run "regedit /s " & logonDC & "\NETLOGON\outlook\12.0.reg", _

0,bWaitOnReturn

If myvariable1=11.0 Then wshshell.Run "regedit /s " & logonDC & "\NETLOGON\outlook\11.0.reg", _

0,bWaitOnReturn

Wscript.Echo "SCRIPT COMPLETED "

 

Can any give any clues on errors or else provide a simpler way to do the job.

 

Thanks in advance

Edited by Lipjam
Posted (edited)

Now you'll have to forgive me for not rewriting your script, but I'm only learning also! :p

 

But yeah, a simpler way there is, no need to call regedit to write your registry values in, VBS can do it directly!

 

Here's a v.simple script I wrote using these features.

 

 

Dim WSHShell
Set WSHShell = WScript.CreateObject("WScript.Shell")
WSHShell.RegWrite "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoAutoTrayNotify",0,"REG_DWORD"
MsgBox "Your Notification Area has now been restored. Please logoff for the new settings to take effect.", vbokonly, "Finished!"
Wscript.Quit

 

http://msdn.microsoft.com/en-us/library/yfdfhz1b(VS.85).aspx

Edited by Slewis
  • Thanks 1
Posted

I think you're basically there; the only thing I can see wrong is you're testing "myvariable" but you're not giving it a value. You're also testing for 12.0 (etc); it's safer to test for something like that as a string (ie "12.0") - in maths, 12 is the same as 12.0; in this situation it might not be :-)

 

I think this should work:

 

set oShell = createobject("wscript.shell")
Set oExcel = CreateObject("Excel.Application")ll
iVer= oExcel.Version
oExcel.Quit

sCmd="regedit /s \\mydomainname\netlogon\outlook\" & iVer & ".reg"

oShell.run,,true

 

I've used Excel instead of Word because I can't get a Word object here (could be because I've got Office 2010 installed) - I'm sure you should be able to use Word.

 

I then just take the version number and store it in a variable - this is the key step you missed.

 

I then simplify the rest of your code - there's nothing wrong with what you've done; I'm just saving ink :-)

 

You're trying to use the name of the logon server; your code is wrong (example of what you can do below) but you don't need it - if your domain is called "school" then \\school\netlogon will take you to the netlogon share on a DC.

The next bit of my line just saves on an IF statement; you've made a folder called "11.0" or "12.0" so you can just take advantage of that in building the command.

Finally, I've marginally shortened the run command - yours is exactly right but you can just put "true" at the point it's needed and the ",," construct implies a zero (you could actually just do oShell.run sCmd; the 0 bit just says "run command in normal window" and the true bit says "wait for this to finish" - the regedit will be so quick you can do without both!)

 

Hope that helps.

 

If you want to specify the name of the domain controller then you've either got to extract it from the environment variable in vbscript or let the command shell expand it. Either of these would work:

logondc=oShell.ExpandEnvironmentStrings("%logonserver%")
sCmd=sCmd="regedit /s " & logondc & "\netlogon\outlook\" & iVer & ".reg"

sCmd="regedit /s %logonserver%\netlogon\outlook\" & iVer & ".reg"

  • Thanks 1
Posted

Thanks guys for the replies

 

slewis

That's a good script but because I have two possible variables it isn't ideal for my situation.

 

Steve

I have used your script but when I debug it it throws up an error at line 7 char 1:

 

Microsoft VBScript runtime error (7, 1) : Argument not optional: 'oShell.run'



 

***** script completed - exit code: 0 *****

 

 

Here is a copy of the script as I am using it:

 

set oShell = createobject("wscript.shell")

Set objWord = CreateObject("word.Application")

iVer= objWord.Version

objWord.Quit

 

sCmd="regedit /s %logonserver%\netlogon\outlook\" & iVer & ".reg"

oShell.run,,True

 

The actual application is OUTLOOK not word...

I want to import outlook.prf file from "%logonserver%\netlogon\outlook\"

 

I would be grateful if you could suggest a line to accomplish this.

Posted

 

Steve

I have used your script but when I debug it it throws up an error at line 7 char 1:

 

Microsoft VBScript runtime error (7, 1) : Argument not optional: 'oShell.run'



 

***** script completed - exit code: 0 *****

 

oops!

 

That line should be:

oShell.run sCmd,,True

 

Moral: always, always, try out the whole code, even the bits which you know are right because you use them all the time ...

 

This Technet page Customize Outlook profiles by using an Outlook Profile (PRF) file has some details of how to import the settings; the most transparent one for the user looks like you check to see if the "first-run" value is set; if not then you set a registry value.

 

I can't really check out the whole of the code below but it does set the right registry value so I think it's OK. I'm using the WMI registry provider to read the registry - that second line looks scary but you just have to copy it but shout if you get stuck.

 

Probably no help, but life gets much easier when you go to Office 2007 and Exchange 2007 - you pretty much just add "autodiscover" to your DNS and Outlook just works, no more profile settings etc.

 

Const HKEY_CURRENT_USER = &H80000001
Set oRegistry=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")

set oShell = createobject("wscript.shell")
'start Excel and get its version; should be same as Outlook
Set oExcel = CreateObject("Excel.Application")
iVer= oExcel.Version
oExcel.Quit

'import settings as appropriate for Outlook version
sCmd="regedit /s \\mydomainname\netlogon\outlook\" & iVer & ".reg"
oShell.run,,true

'need to check to see if Outlook setup already run
sPath="Software\Microsoft\Office\" & iVer & "\Outlook\Setup"
'get a list of values for correct version of Outlook
lRC = oRegistry.EnumValues(HKEY_CURRENT_USER, sPath, sKeys)
bFirstRun=false 'assume we've not run Outlook yet
if lRC=0 then
 'return value of zero means we didn't have an error reading reg
 for i=lbound(sKeys) to ubound(skeys)
 'step through each value in turn - convert to lower case (makes check easier)
   sKey=lcase(skeys(i))
   'technet article says look for either text
   if sKey="firstrun" or sKey="first-run" then 'we've already configured Outlook, don't do it again
     bFirstRun=true
     exit for
   end if
 next
end if

if bFirstRun=false then 'we've not run Outlook before so force profile settings import
 lRC=oRegistry.SetStringValue(HKEY_CURRENT_USER,sPath,"ImportPrf","\\domain\netlogon\outlook\outlook.prf")
end if

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 account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...