How to import a rule (rwz) into outlook thru automated script

I have an outlook rule that i've exported to rwz file. The next step is deployment. I need to add this rule to over 500 client machines. Is it possible to write a script or something to do this?
glenn_rAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
There is no way to programmatically, so not sure there is a way to deploy the RWZ automatically and load it.

You can create rules in Outlook via VBA script though, so take a look at some earlier questions related, like:

http://www.experts-exchange.com/Software/Office_Productivity/Groupware/Outlook/Q_28345013.html

~bp
0
David LeeCommented:
Hi, glenn_r.

So long as you're using Outlook 2010 or later, we can create the rule via a script just as in the question that @Bill Prew linked to.  To do that, I'll need to know what the rule does.
0
glenn_rAuthor Commented:
why outlook 2010 and later will creating a rule via script not work with 2007?

my rule is pretty simple
when a subject contains a matching string run an external process
i've got this working via a rule
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Bill PrewCommented:
This should also be doable in Outlook 2007, just not any version earlier than that.  The reason for this is because in order to create a rule from VBA code in Outlook, Microsoft had to add that capability to the Outlook Object Model.  The Rules collection that allows this is not exposed to VBA until Outlook 2007.

~bp
0
glenn_rAuthor Commented:
ok last question is how do i deploy this script to client machines running outlook so it gets added to their 'thisoutlooksession' module? Need to push this out to 500 machines.
0
David LeeCommented:
I couldn't remember for sure if it was Outlook 2007 or 2010 that first exposed rules, so I played it safe and said 2010.  

You wouldn't want to deploy VBA code to every computer.  that would be more painful than deploying the .rwz file and giving them all instructions on how to import it.  Instead, you'd want to write the code in VBscript since it runs outside of Outlook.  You could then either call that script from another script (e.g. a login script) or send everyone a link to the script.  Clicking that link would run the script and add the rule.
0
glenn_rAuthor Commented:
i tested and works with both 2007 and 2010

i need to deploy this silently
thinking via login script
u have a link to an example on what to run to get that script added to 'thisoutlooksession' module?
once i get that code i can handle rolling it out thru a login script
0
David LeeCommented:
"u have a link to an example on what to run to get that script added to 'thisoutlooksession' module?"

That's not possible.  There is no way to add a macro to Outlook other than to do it manually (i.e. type it in or copy and paste).  That's what I was saying in my last comment: you don't want to deploy VBA code.  If the macro is ready (i.e. it creates the rule you want), then we need to convert the macro to VBscript.  I'll be glad to help you do that.  I just need the code.
0
glenn_rAuthor Commented:
confused
"no way to add a macro to Outlook"
"need to convert the macro to VBscript"

for clarification do we have 3 items here?
1) macro
2) vba
3) vbscript

simple rule

'Option Explicit
'
'Private WithEvents olInboxItems As Items
'
'Private Sub Application_Startup()
'  Dim objNS As NameSpace
'  Set objNS = Application.Session
'  Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
'  Set objNS = Nothing
'End Sub
'
'Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
'
'  On Error Resume Next
'
'  Const searchString As String = "lockdown" ' put your search criteria here
'  Dim testPos As Integer
'
'  testPos = InStr(Item.Subject, searchString)
'
'  ' search string found run your ppt
'  If testPos > 0 Then
'    ' displays messagebox for now but replace the statement below with your ppt invokation
'    MsgBox (searchString & " found")
'  End If
'
'  Set Item = Nothing
'
'End Sub
'
0
David LeeCommented:
glenn_r,

Let me see if I can clear up the confusion.  VBA is a programming language.  Microsoft Office macros are written in VBA.  The terms "macro" and "script" are synonymous in the context of writing some code in VBA to run inside of an Office application (e.g. Outlook, Word, Excel, etc.)  There is no automated way to add/create/install a macro in Outlook.  The only way to add macro code in Outlook is to do it manually.  By "manually", I mean open the VB editor in Outlook and either type in the code or copy and paste the code in.  In the context of what you want to accomplish, if you write the code in VBA, then you'll have to send the code and detailed instructions on how to add it to Outlook to everyone that's going to use it.  On receiving the code and the instructions, they will then have to

1.  Open Outlook
2.  Open the VB editor in Outlook
3.  Copy and paste the code into the VB editor
4.  Save the changes
5.  Close the editor
6.  Open Security
7.  Go to the section on Macro security
8.  change the default security settings to allow macros to run
9.  Run the macro they copied in on step #3

That's a lot of steps to perform and working through them all completely eliminates the point of the script, which is to make adding the rule easy.  You'd be better off sending them the rule file with instructions on how to import it, or sending them instructions on how to create the rule from scratch.

Fortunately, there's an alternative.  That is to write the code in VBscript, another programming language that is similar to VBA, but runs from outside of Office apps rather than from inside of them (as VBA does).  With VBscript there's no code to add/install in Outlook, so there's no need to send the users the code or instructions on how to add it to Outlook.  All you need to send them is a link.  Clicking the link will run the script and add the rule to Outlook.  As I mentioned, VBscript is like VBA, but it has some key differences which require changing the code.

Does that make things clearer?

The code you included in your last comment does not create a rule.  So, my question is, have you already written the VBA version of the code to add your rule?  If so, then post that code and I'll convert it to VBscript for you.  If you have not written the code, then I'll write the VBscript from scratch.  To do that, I need to know exactly what the rule does.
0
glenn_rAuthor Commented:
simple example - i posted sample code in the last response
when the keyword 'lockdown' is found in the email display a msgbox
show me a vbscript example for the above and i can take it from there
0
David LeeCommented:
Here's the code for creating the rule. To use this

1.  Open Notepad
2.  Copy and paste the code below into Notepad
3.  Edit the code per the comments I included in it
4.  Save the file.  You may name it anything you like so long as the file extension is .vbs
5.  Double-click the file to run the script and add the rule

To deploy this on other computers, either call this script from another script (e.g. a login script) or place the script on a network share that everyone has access to and send them a link to it.  When they click the link the script will run and add the rule to Outlook.

'--> Create some constants
Const RULE_NAME = "Glenn's Rule"  '<-- Edit the name of the rule
Const olRuleReceive = 0

'--> Create some variables
Dim olkApp, olkSes, olkCol, olkRul, olkCon, olkAct

'--> Connect to Outlook
Set olkApp = CreateObject("Outlook.Application")
Set olkSes = olkApp.GetNamespace("MAPI")
olkSes.Logon olkApp.DefaultProfileName

'--> Get the rules collection
Set olkCol = olkSes.DefaultStore.GetRules()

'--> Create a new receive rule
Set olkRul = olkCol.Create(RULE_NAME, olRuleReceive)

'--> Set the rule's condition to look for a specific word in the subject
Set olkCon = olkRul.Conditions.Subject
With olkCon
    .Text = Array("lockdown")
    .Enabled = True
End With

'--> Set the rule's action to display a desktop alert
Set olkAct = olkRul.Actions.DesktopAlert
With olkAct
    .Enabled = True
End With

'--> Save the rule
olkCol.Save False

'--> Disconnect from Outlook
olkSes.Logoff
Set olkCon = Nothing
Set olkAct = Nothing
Set olkRul = Nothing
Set olkCol = Nothing
Set olkSes = Nothing
Set olkApp = Nothing

'--> Terminate the script
WScript.Quit                 

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
glenn_rAuthor Commented:
Thanks for all your help
for deployment i ended up just copying out the otm file for outlook macros as i can control security and not have to fool around with adjusting GPO's etc.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Outlook

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.