+ Post New Thread
Results 1 to 5 of 5
Windows Thread, VBS Script in Technical; Hi guys I am struggling to put together a script that determines the correct version of Office installed and then ...
  1. #1
    Lipjam's Avatar
    Join Date
    May 2007
    Location
    Moreton
    Posts
    18
    Thank Post
    4
    Thanked 2 Times in 1 Post
    Blog Entries
    2
    Rep Power
    15

    VBS Script

    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
    Last edited by Lipjam; 1st December 2009 at 04:28 PM.

  2. #2
    Slewis's Avatar
    Join Date
    Jun 2007
    Location
    Bolton
    Posts
    48
    Thank Post
    2
    Thanked 11 Times in 9 Posts
    Rep Power
    16

    Talking

    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.


    Code:
    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/libr...1b(VS.85).aspx
    Last edited by Slewis; 1st December 2009 at 04:40 PM.

  3. Thanks to Slewis from:

    Lipjam (2nd December 2009)

  4. #3

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,156
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124
    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:

    Code:
    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:
    Code:
    logondc=oShell.ExpandEnvironmentStrings("%logonserver%")
    sCmd=sCmd="regedit /s " & logondc & "\netlogon\outlook\" & iVer & ".reg"
    Code:
    sCmd="regedit /s %logonserver%\netlogon\outlook\" & iVer & ".reg"

  5. Thanks to srochford from:

    Lipjam (2nd December 2009)

  6. #4
    Lipjam's Avatar
    Join Date
    May 2007
    Location
    Moreton
    Posts
    18
    Thank Post
    4
    Thanked 2 Times in 1 Post
    Blog Entries
    2
    Rep Power
    15

    VBScript runtime Error

    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.

  7. #5

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,156
    Thank Post
    116
    Thanked 529 Times in 452 Posts
    Blog Entries
    2
    Rep Power
    124
    Quote Originally Posted by Lipjam View Post

    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:
    Code:
    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.

    Code:
    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

SHARE:
+ Post New Thread

Similar Threads

  1. Writing to Excel from .vbs script
    By Samson in forum Windows
    Replies: 6
    Last Post: 15th October 2008, 07:34 AM
  2. Sub within a sub - VBS Script
    By FN-GM in forum Scripts
    Replies: 5
    Last Post: 18th May 2008, 06:30 PM
  3. Trace a VBS Script
    By chalkwellstu in forum Scripts
    Replies: 2
    Last Post: 25th January 2008, 10:53 AM
  4. VBS Drive script is running from
    By Samson in forum Scripts
    Replies: 5
    Last Post: 10th May 2007, 03:29 PM
  5. VBS script for prestaging computers anyone?
    By ChrisH in forum Scripts
    Replies: 7
    Last Post: 23rd June 2006, 09:59 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •