Results 1 to 6 of 6

Thread: [RESOLVED] [Outlook2007]Create or Edit a batch File when Specific message come in my MailBox

Hybrid View

  1. #1

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Resolved [RESOLVED] [Outlook2007]Create or Edit a batch File when Specific message come in my MailBox

    Hi All

    I want to create a Batch File when some specific message arrives in my Outlook Box.

    The Format of Batch File will be Fixed always, only things which will change is Date (Which it will pick From Email Subject) and Location which it will pick from Message body.

    For Example:

    Email Subject: Run Batch File on 2502 Next Month (Or Run Batch File Next Month On 2502)

    Message Body:

    Blah Blah Blah.....
    Location: "C:\Temp\OlTest"

    Then once this message comes it must create a Batch File as follows:

    @Echo Off
    @cd C:\Temp
    @xcopy C:\Temp\Install_2502_File.zip C:\Temp\OlTest
    Exit

    Next Time when message comes with Subject: Run Batch File on 1603 Next Month

    Message Body: Blah Blah Blah....
    Location: "NewLocation"

    It must create Batch File as (It would also help if it edit the values in existing batch file)

    @Echo Off
    @cd C:\Temp
    @xcopy C:\Temp\Install_1603_File.zip <NewLocation>
    Exit

  2. #2

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Re: [Outlook2007]Create or Edit a batch File when Specific message come in my MailBox

    Do anyone have idea about this?

    Or Else,

    Will it work if I give output to a Notepad and then rename it as batch File

    i.e. I will create a file NewText.txt and then I will rename it as NewText.bat

  3. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [Outlook2007]Create or Edit a batch File when Specific message come in my MailBox

    No need to create a file NewText.txt and renaming it as NewText.bat...

    You can directly write to NewText.bat. It is the same as writing to text file. Search the forum and you will find plenty of examples on how to write to a text file.
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  4. #4

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Re: [Outlook2007]Create or Edit a batch File when Specific message come in my MailBox

    I tried the following code to edit an existing batch File

    Code:
    Dim iFileNo As Integer
    iFileNo = FreeFile
    'OPen the file for writing
    
    Open "\\" & strServer & "\c$\WINDOWS\system32\Framework32.bat" For Output As #iFileNo   '--> strServer Value I am picking from Email Subject Line
    
    Print #iFileNo, "@echo off"
    Print #iFileNo, "REM Batch Modification Testing"
    Print #iFileNo, "REM Sample Script Testing"
    Print #iFileNo, "@ cd D:\"
    Print #iFileNo, "@ D:"
    Print #iFileNo, "@ mkdir TestDir"
    Print #iFileNo, "@ cd D:\TestDir"
    Print #iFileNo, ""
    
    Close #iFileNo

    How can I pick the location from Message Body, For Example:

    Ex 1: Location: C:\Temp\

    Ex 2: Blah Blah Blah....
    Location:C\Temp

    Ex 3: Location:C\Temp
    Blah Blah Blah.....

    Ex 4: Blah Blah Blah...

    XXXXXXXXXX Location: C:\Temp

    Blah Blah Blah

    In all the four examples above I want to pick the Location (C:\Temp\). THe thing which is common on all the four example are "C:\Temp" is always coming after word "Location", but it is also not fixed that how many spaces are in between "Location" and "C:\Temp\" Or on which line of message body will it appear.

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: [Outlook2007]Create or Edit a batch File when Specific message come in my MailBox

    Now I see that you are doing good on your own which is very good so here is a hint on how to tackle this situation

    Read up on Split() and Instr()

    If you get stuck you know what to do....
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6

    Thread Starter
    Member Mr.Cool's Avatar
    Join Date
    Feb 2010
    Posts
    35

    Lightbulb Re: [Outlook2007]Create or Edit a batch File when Specific message come in my MailBox

    Hi SID,

    I think I got a way to do that by using following code:
    Code:
    Sub ParseTextLine()
    
    Dim objOL As Outlook.Application
    Dim objItem As Object
    Dim strAddr As String
    On Error Resume Next
    Set objOL = Application
    Set objItem = objOL.ActiveExplorer.Selection(1)
    If Not objItem Is Nothing Then
    strAddr = ParseTextLinePair(objItem.Body, "Location:")
    If strAddr <> "" Then
    MsgBox strAddr
    Else
    MsgBox "Could not extract address from message."
    End If
    End If
    Set objOL = Nothing
    Set objItem = Nothing
    
    
    End Sub
    To make that code work, I have to define function ParseTextLinePair as shown below.

    Code:
    Function ParseTextLinePair _
    (strSource As String, strLabel As String)
    Dim intLocLabel As Integer
    Dim intLocCRLF As Integer
    Dim intLenLabel As Integer
    Dim strText As String
    intLocLabel = InStr(strSource, strLabel)
    intLenLabel = Len(strLabel)
    If intLocLabel > 0 Then
    intLocCRLF = InStr(intLocLabel, strSource, vbCrLf)
    If intLocCRLF > 0 Then
    intLocLabel = intLocLabel + intLenLabel
    strText = Mid(strSource, _
    intLocLabel, _
    intLocCRLF - intLocLabel)
    Else
    intLocLabel = _
    Mid(strSource, intLocLabel + intLenLabel)
    End If
    End If
    ParseTextLinePair = Trim(strText)
    End Function
    Thanks for all your help SID.

    It's really fun to learn things here on this Forum.
    Last edited by Mr.Cool; Mar 3rd, 2010 at 06:37 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width