|
-
Aug 13th, 2008, 08:12 PM
#1
Thread Starter
New Member
VBS to detect what version of Outlook and Overwrite a file
Ok, figured I would throw this one up as well, and I think this is the correct thread. If not, sorry, and its cool to move.
VB version: 6
Ok, this is what is going on. I am trying to write a VBS that will:
1) Detect what version of outlook you are running
2) Over write a specified file with a diffrent specified file (on a server) depending on what version of Outlook you are running
Current Progress:
We where using a old script that was like this, back when a single "normal.dot" was all we needed. This simply overwrote the old normal.dot with the one that was hosted on a server. It also closed out any running version of Outlook and Word that was running.
Code:
@echo off
echo Please save any documents in Microsoft Word or Outlook before proceeding.
echo *************************************************************************
pause
echo This will take a few seconds
rem ** The following will force kill processes for Microsoft Word and Outlook **
C:\WINDOWS\SYSTEM32\TASKKILL.EXE /f /im WINWORD.exe
C:\WINDOWS\SYSTEM32\TASKKILL.EXE /f /im OUTLOOK.exe
rem ** The following will overwrite the local normal.dot file **
copy /y "\\server\normal.dot" "%USERPROFILE%\Application Data\Microsoft\Templates\"
Then we also had a script that we used that detected what version of outlook you where using via regkeys, and it would detect to see if you have a particular regkey we needed, and if you didn't, it created it.
Code:
' OutlookDelegateWastebasketchange.vbs
'
'
' This script will determine if the Outlook installation is 2k, 2k2, 2k3, or 2k7
' And will add / change the DelegateWastebasketStyle reg key in the approproate
' registry path depending upon the Outlook version.
Dim WSHShell, checkdspKey, outook2000ver, outlook2002ver, outlook2003ver, outlook2007ver, otherVersion
Set objShell = WScript.CreateObject("WScript.Shell")
' If any regread fails, continue executing
On Error Resume Next
' Check to see if this script has the block key
' If the block key is entered, end script
RegKey = objShell.regread("HKCU\Software\DarksideProductions\Outlook\DelegateWasteBasket_block")
' set the checkdspKey variable based on the regread outcome
if Err.Number then
checkdspKey = "1"
else checkdspKey = "2"
end if
' Log that nothing will be changed
if checkdspKey = "2" then
WScript.echo "****DSP Block Key detected, script exiting****"
end if
' Quit the script
if checkdspkey = "2" then
WScript.Quit
end if
' Change / add the key depending upon the Outlook version detected
' Outlook 2007 Script
On Error Resume Next
RegKey = objShell.regread("HKCU\Software\Microsoft\Office\12.0\Outlook\Options\General\Security Zone")
if Err.Number then
outlook2007ver = "0"
else
objShell.RegWrite "HKCU\Software\Microsoft\Office\12.0\Outlook\Options\General\DelegateWastebasketStyle", 4, "REG_DWORD"
outlook2007ver = "1"
end if
On Error Resume Next
' Outlook 2003 Script
RegKey = objShell.regread("HKCU\Software\Microsoft\Office\11.0\Outlook\Options\General\Security Zone")
if Err.Number then
outlook2003ver = "0"
else
objShell.RegWrite "HKCU\Software\Microsoft\Office\11.0\Outlook\Options\General\DelegateWastebasketStyle", 4, "REG_DWORD"
outlook2003ver = "1"
end if
On Error Resume Next
' Outlook 2002 Script
RegKey = objShell.regread("HKCU\Software\Microsoft\Office\10.0\Outlook\Options\General\Security Zone")
if Err.Number then
outlook2002ver = "0"
else
objShell.RegWrite "HKCU\Software\Microsoft\Office\10.0\Outlook\Options\General\DelegateWastebasketStyle", 4, "REG_DWORD"
outlook2002ver = "1"
end if
On Error Resume Next
' Outlook 2000 Script
' For Outlook 2k, we check a different key for the presence of Outlook due to inconsistent registry
' appearance on the terminal servers.
RegKey = objShell.regread("HKCU\Software\Microsoft\Office\9.0\Outlook\Options\MSHTML\International\LastIEVersion")
if Err.Number then
outlook2000ver = "0"
else
objShell.RegWrite "HKCU\Software\Microsoft\Office\9.0\Outlook\Options\General\DelegateWastebasketStyle", 4, "REG_DWORD"
outlook2000ver = "1"
end if
' If none of the three keys are found, log the following info and quit
otherVersion = "0"
if outlook2007ver = "1" then
otherVersion= "1"
end if
if outlook2003ver = "1" then
otherVersion = "1"
end if
if outlook2002ver = "1" then
otherVersion = "1"
end if
if outlook2000ver = "1" then
otherVersion = "1"
end if
if otherVersion = "0" then
WScript.echo "Client is not running Outlook 2000, 2002, 2003, 2007, or has not setup email yet."
WScript.Quit
end if
' log the key update and apparent Outlook version
if outlook2000ver = "1" then
WScript.echo "Client appears to be running Outlook 2000"
end if
if outlook2002ver = "1" then
WScript.echo "Client appears to be running Outlook 2002"
end if
if outlook2003ver = "1" then
WScript.echo "Client appears to be running Outlook 2003"
end if
if outlook2007ver = "1" then
WScript.echo "Client appears to be running Outlook 2007"
end if
if checkdspKey = "1" then
WScript.echo "Updated DelegateWastebaskey Reg Key"
end if
WScript.Quit(0)
This worked wonderfually for what we needed it for.
Issue: I have been trying to kinda combine these codes to some extent to detact what version of outlook you where running to make sure it over wrote the correct version of the normal.dot. So far, no luck. Anyone got any ideas?
-
Aug 14th, 2008, 01:07 PM
#2
Thread Starter
New Member
Re: VBS to detect what version of Outlook and Overwrite a file
I have been playing around with it more, and so far, no luck. It just runs thru, almost like it isnt even checking the registries. Meh. perhaps there is a diffrent way to tell what verison of outlook the machine is running?
-
Aug 14th, 2008, 05:34 PM
#3
Thread Starter
New Member
Re: VBS to detect what version of Outlook and Overwrite a file
Ok, here is what I have thus far. Works great until it goes to copy the new file, and then it just kinda stops. Not sure why. It isnt coping over the file.
Code:
' Macro_update.vbs
'
'
Dim WSHShell, checkdspKey, outook2000ver, outlook2002ver, outlook2003ver, outlook2007ver, otherVersion
Set objShell = WScript.CreateObject("WScript.Shell")
Const OverwriteExisting = True
' If any regread fails, continue executing
On Error Resume Next
' Check to see if this script has the block key
' If the block key is entered, end script
RegKey = objShell.regread("HKCU\Software\DarksideProductions\Outlook\filedoesnotexist")
' set the checkdspKey variable based on the regread outcome
if Err.Number then
checkdspKey = "1"
else checkdspKey = "2"
end if
' Log that nothing will be changed
if checkdspKey = "2" then
WScript.echo "****DSP Block Key detected, script exiting****"
end if
' Quit the script
if checkdspkey = "2" then
WScript.Quit
end if
' Change / add the key depending upon the Outlook version detected
' Outlook 2003 Script
RegKey = objShell.regread("HKCU\Software\Microsoft\Office\11.0\Outlook\Options\General\Security Zone")
if Err.Number then
outlook2003ver = "0"
else
outlook2003ver = "1"
Dim FSO2k3
Set FSO2k3 = CreateObject("Scripting.FileSystemObject")
FSO2k3.CopyFile "\\server1\Autoresponses\Macro\2003\normal.dot", "%USERPROFILE%\Application Data\Microsoft\Templates\"
end if
On Error Resume Next
' Outlook 2002 Script
RegKey = objShell.regread("HKCU\Software\Microsoft\Office\10.0\Outlook\Options\General\Security Zone")
if Err.Number then
outlook2002ver = "0"
else
outlook2002ver = "1"
Dim FSO2k2
Set FSO2k2 = CreateObject("Scripting.FileSystemObject")
FSO2k2.CopyFile "\\server1\Autoresponses\Macro\2002\normal.dot", "%USERPROFILE%\Application Data\Microsoft\Templates\"
end if
On Error Resume Next
' Outlook 2000 Script
' For Outlook 2k, we check a different key for the presence of Outlook due to inconsistent registry
' appearance on the terminal servers.
RegKey = objShell.regread("HKCU\Software\Microsoft\Office\9.0\Outlook\Options\MSHTML\International\LastIEVersion")
if Err.Number then
outlook2000ver = "0"
else
outlook2000ver = "1"
Dim FSO2k
Set FSO2k = CreateObject("Scripting.FileSystemObject")
FSO2k.CopyFile "\\server1\Autoresponses\Macro\2000\normal.dot", "%USERPROFILE%\Application Data\Microsoft\Templates\"
end if
' If none of the three keys are found, log the following info and quit
otherVersion = "0"
if outlook2007ver = "1" then
otherVersion= "1"
end if
if outlook2003ver = "1" then
otherVersion = "1"
end if
if outlook2002ver = "1" then
otherVersion = "1"
end if
if outlook2000ver = "1" then
otherVersion = "1"
end if
if otherVersion = "0" then
WScript.echo "Client is not running Outlook 2000, 2002, 2003, 2007, or has not setup email yet."
WScript.Quit
end if
' log the key update and apparent Outlook version
if outlook2000ver = "1" then
WScript.echo "Client appears to be running Outlook 2000"
end if
if outlook2002ver = "1" then
WScript.echo "Client appears to be running Outlook 2002"
end if
if outlook2003ver = "1" then
WScript.echo "Client appears to be running Outlook 2003"
end if
if checkdspKey = "1" then
WScript.echo "Updated Macros"
end if
WScript.Quit(0)
Last edited by daffed13; Aug 15th, 2008 at 12:15 PM.
-
Aug 15th, 2008, 02:10 PM
#4
Thread Starter
New Member
Re: VBS to detect what version of Outlook and Overwrite a file
Got it. I had to correct the .Copy statements. Now it works GREAT!!!!!
Code:
' Macro_update.vbs
'
'
Dim WSHShell, checkdspKey, outook2000ver, outlook2002ver, outlook2003ver, outlook2007ver, otherVersion
Set objShell = WScript.CreateObject("WScript.Shell")
Set objNet = CreateObject("WScript.NetWork")
strUser = objNet.UserName
Const OverwriteExisting = True
' If any regread fails, continue executing
On Error Resume Next
' Check to see if this script has the block key
' If the block key is entered, end script
RegKey = objShell.regread("HKCU\Software\DarksideProductions\Outlook\filedoesnotexist")
' set the checkdspKey variable based on the regread outcome
if Err.Number then
checkdspKey = "1"
else checkdspKey = "2"
end if
' Log that nothing will be changed
if checkdspKey = "2" then
WScript.echo "****DSP Block Key detected, script exiting****"
end if
' Quit the script
if checkdspkey = "2" then
WScript.Quit
end if
' Change / add the key depending upon the Outlook version detected
' Outlook 2003 Script
RegKey = objShell.regread("HKCU\Software\Microsoft\Office\11.0\Outlook\Options\General\Security Zone")
if Err.Number then
outlook2003ver = "0"
else
outlook2003ver = "1"
Dim FSO2k3
Set FSO2k3 = CreateObject("Scripting.FileSystemObject")
FSO2k3.CopyFile "\\server1\Autoresponses\Macro\2003\normal.dot", "C:\Documents and Settings\" & strUser & "\Application Data\Microsoft\Templates\"
end if
On Error Resume Next
' Outlook 2002 Script
RegKey = objShell.regread("HKCU\Software\Microsoft\Office\10.0\Outlook\Options\General\Security Zone")
if Err.Number then
outlook2002ver = "0"
else
outlook2002ver = "1"
Dim FSO2k2
Set FSO2k2 = CreateObject("Scripting.FileSystemObject")
FSO2k2.CopyFile "\\server1\Autoresponses\Macro\2002\normal.dot", "C:\Documents and Settings\" & strUser & "\Application Data\Microsoft\Templates\"
end if
On Error Resume Next
' Outlook 2000 Script
' For Outlook 2k, we check a different key for the presence of Outlook due to inconsistent registry
' appearance on the terminal servers.
RegKey = objShell.regread("HKCU\Software\Microsoft\Office\9.0\Outlook\Options\MSHTML\International\LastIEVersion")
if Err.Number then
outlook2000ver = "0"
else
outlook2000ver = "1"
Dim FSO2k
Set FSO2k = CreateObject("Scripting.FileSystemObject")
FSO2k.CopyFile "\\server1\Autoresponses\Macro\2000\normal.dot", "C:\Documents and Settings\" & strUser & "\Application Data\Microsoft\Templates\"
end if
' If none of the three keys are found, log the following info and quit
otherVersion = "0"
if outlook2007ver = "1" then
otherVersion= "1"
end if
if outlook2003ver = "1" then
otherVersion = "1"
end if
if outlook2002ver = "1" then
otherVersion = "1"
end if
if outlook2000ver = "1" then
otherVersion = "1"
end if
if otherVersion = "0" then
WScript.echo "Client is not running Outlook 2000, 2002, 2003, or has not setup email yet."
WScript.Quit
end if
' log the key update and apparent Outlook version
if outlook2000ver = "1" then
WScript.echo "Client appears to be running Outlook 2000"
end if
if outlook2002ver = "1" then
WScript.echo "Client appears to be running Outlook 2002"
end if
if outlook2003ver = "1" then
WScript.echo "Client appears to be running Outlook 2003"
end if
if checkdspKey = "1" then
WScript.echo "Updated Macros"
end if
WScript.Quit(0)
-
Aug 18th, 2008, 07:02 AM
#5
Re: VBS to detect what version of Outlook and Overwrite a file
an alternative to this is to automate outlook from the script an work within an instance of outlook
like
Code:
set objol = creatobject("outlook.application")
msgbox objol.version
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|