Insert the word in an email subject line into a vbscript

We have a policy that locks ad user account after so many failed attempts.  I want to be able to send myself an email which will execute a script to unlock a locked ad account.

I can unlock an account with a vbscript that I found but I have to enter the username into the script.  I want to be able to put the words "unlock %username%" into an email and send it to my self and then have the %username% inserted into my script to unlock the account.

I have not been able to find anything that will take the subject line and insert it into a script.

Can anyone point me in the right direction for this a doable thing?

Can anyone point me in the right direction as to where to begin?
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.

Helen FeddemaCommented:
We need more information.  What is the format of the email, in particular?  Presumably the subject includes the username, but probably more stuff as well.  How can you select the relevant messages?  You could write code on the Application_NewMail event to process incoming emails, select the appropriate ones, extract the username from them, and then run code to do the unlocking using that username.  I would recommend just using Outlook VBA, not a VBScript, because then you can work on everything right in the Outlook VB window.
Chris BottomleySoftware Quality Lead EngineerCommented:
Assuming an email isreceived by the outlook client that has the subject format:

"unlock %username%"

Where username is the string you want processing and the percent wrapper defines the whereabouts then we can take an email on receipt, test for the subject structure and extract the username.

From that point if your script is set up to take a parameter then it should be possible to call it from outlook or as Helen suggests port the code into outlook and do it all within the outlook client

michaelhooperAuthor Commented:
The format of the subject line will be "unlock username"

the script i have that will actually unlock the account is

Set objUser = GetObject("EDMS://CN=username,OU=UOU,OU=OU,DC=domainname,DC=domain,DC=net")
objUser.Put "edsaAccountLockedOut", False

....I would just like to be able to get the username from the email subject to insert into username on this script
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Chris BottomleySoftware Quality Lead EngineerCommented:

I see I have overlooked this question.  Is the request still current?

michaelhooperAuthor Commented:

Yes,  would appreciate any suggestions
Chris BottomleySoftware Quality Lead EngineerCommented:
The script that does the unlock ... is that a VBS or an outlook script.  Essentially I am thinking teh best answer is if it can be coded in outlook and then run the sub when a relevant email is received.

Therefore if you can supply the code sequence you run manually, (assuming there is more to it than the three llines above. we can try and integrate them.

Chris BottomleySoftware Quality Lead EngineerCommented:
Able to upload?

Chris BottomleySoftware Quality Lead EngineerCommented:
I'll assume for now that teh data in your earlier post is exactly what is required in a VBA script therefore:

Post the supplied code in a normal code module within outlook.
Create a rule for all incoming mails, (limit the set if you can - it'll do no harm)
Call a script as the action, selecting Q_25647638.

Test it but if the previously supplied action code is appropriate it should work as is, since the functionality for a script rule is pretty basic.

Sub Q_25647638(mai As Outlook.MailItem)
Dim arr() As String
Dim str As String
Dim objUser As Object
'mail subject format defined as: unlock username
    arr = Split(mai.Subject, " ")
    If LCase(arr(0)) = "unlock" Then
        If UBound(arr) = 1 Then
    'Assume correct email!
            str = Trim(arr(1))
            Set objUser = GetObject("EDMS://CN=" & str & ",OU=UOU,OU=OU,DC=domainname,DC=domain,DC=net")
            objUser.Put "edsaAccountLockedOut", False
        End If
    End If
End Sub

Open in new window

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

From novice to tech pro — start learning today.