how to start and stop a function based on the mail - outlook

Is there any way to start a function once I receive an email and run for every one hour and stop when an email is received to stop.
This is the code with which im trying. here i can start the function and execute in each time interval but cannot stop as it stuck within the loop and not recognizing the stop email.
Healthcheck is the function i want to execute for every one hour. here i have given time interval as 2 mins.
HotKeySet("+!e", "_Exit") ;Shift-Alt-E to Exit the script
MsgBox(64, "ERS Health check", "Hotkey to exit the script: 'Shift-Alt-E'!")
Global $oOApp = ObjCreate("Outlook.Application")
Global $test = ObjEvent($oOApp, "oOApp_")
While 1
    Sleep(10)
WEnd
; Outlook 2007 - NewMailEx event - http://msdn.microsoft.com/en-us/library/bb147646%28v=office.12%29.aspx
Func oOApp_NewMailEx($sOL_EntryId)
    Local $oOL_Item = $oOApp.Session.GetItemFromID($sOL_EntryId, Default)
    MsgBox(64, "OutlookEX UDF Example Script", "New mail has arrived!" & #CRLF & #CRLF & _
            "From:    " & $oOL_Item.SenderName & #CRLF & _
            "Subject: " & $oOL_Item.Subject)
            If $oOL_Item.Subject = "Stop" Then
               Exit
            EndIf
    While $oOL_Item.Subject = "Start"
     HealthCheck()
     Sleep(120000)
     WEnd
EndFunc   

I'm still quite new to this (working with applications like Outlook), so I might have missed something, but the following seems to work:
HotKeySet("+!e", "_Exit") ;Shift-Alt-E to Exit the script
MsgBox(64, "ERS Health check", "Hotkey to exit the script: 'Shift-Alt-E'!")
Global $oOApp = ObjCreate("Outlook.Application")
Global $test = ObjEvent($oOApp, "oOApp_")
Global $Status = "undefined"
While True
Switch $Status
Case "Start"
HealthCheck()
Case "Stop"
ConsoleWrite(#HOUR & ":" & #MIN & " StopMail received. Exiting." & #CRLF)
Exit
Case Else
; do nothing
EndSwitch
Sleep(100)
WEnd
; Outlook 2007 - NewMailEx event - http://msdn.microsoft.com/en-us/library/bb147646%28v=office.12%29.aspx
Func oOApp_NewMailEx($sOL_EntryId)
Local $oOL_Item = $oOApp.Session.GetItemFromID($sOL_EntryId, Default)
;~ MsgBox(64, "OutlookEX UDF Example Script", "New mail has arrived!" & #CRLF & #CRLF & _
;~ "From: " & $oOL_Item.SenderName & #CRLF & _
;~ "Subject: " & $oOL_Item.Subject)
$Status = $oOL_Item.Subject
EndFunc ;==>oOApp_NewMailEx
Func _Exit()
Exit
EndFunc ;==>_Exit
Func HealthCheck()
Local Static $htimer
If TimerDiff($htimer) < 120000 Then Return ; not enough time passed since last run
$htimer = TimerInit()
ConsoleWrite(#HOUR & ":" & #MIN & " HealthCheck." & #CRLF)
EndFunc ;==>HealthCheck

Related

AUTOIT GUI Management Pause Script when in Background

Hi all im currently writing a script to more easily manage (kill/delete) broken WTS Profiles. So in an attempt to make it easier for our support guys i came up with an autoit script to manage that.
I've got everything running smoothly except that my script is listening in on the "Enter" Key and if this is pressed he calls functions an so on.
But he also does this when my script is running in the background and the user wants to google something or anything, he always registers the Enter Key.
So my Question now, how can i fix this because if it is a complex search (with asterisk and so on) it generats unneceserry I/O on the netshares where the Profiles are stored.
The Code in Question:
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $SearchButton
$sSearchString = GUICtrlRead($SubmitField) & "*"
If $sSearchString = "*" Then ;
_OutputConsole_Updater()
GUICtrlSetData($ConsoleOutput, "[" & #HOUR & ":" & #MIN & ":" & #SEC & "] -" & " Keine Eingabe getätigt, bitte Suchbegriff eingeben")
Else
_ReloadBox()
_SearchAll()
EndIf
Case $DeleteButton
_DeleteSelection()
Case $DeleteAll
_DeleteAllCheck()
Case $nMsg = _IsPressed("0D")
$sSearchString = GUICtrlRead($SubmitField) & "*" ;
If $sSearchString = "*" Then ;
_OutputConsole_Updater()
GUICtrlSetData($ConsoleOutput, "[" & #HOUR & ":" & #MIN & ":" & #SEC & "] -" & " Keine Eingabe getätigt, bitte Suchbegriff eingeben")
Else
_ReloadBox()
_SearchAll()
EndIf
EndSwitch
WEnd
Do you operate with HotkeySet? Then activate the function only when your script is active
If WinActive($scriptTitle) = 0 Then
_setHotKeys()
Endif
Func _setHotKeys($state = 1)
If $state = 1 Then
HotKeySet('!1')
HotKeySet('!2')
HotKeySet('!3')
HotKeySet('!4')
HotKeySet('!5')
HotKeySet('!6')
HotKeySet('!7')
HotKeySet('!8')
ElseIf $state = 0 Then
HotKeySet('!1', '_setTab0')
HotKeySet('!2', '_setTab1')
HotKeySet('!3', '_setTab2')
HotKeySet('!4', '_setTab3')
HotKeySet('!5', '_setTab4')
HotKeySet('!6', '_setTab5')
HotKeySet('!7', '_setTab6')
HotKeySet('!8', '_setTab7')
EndIf
EndFunc ;==>_setHotKeys

SecureCRT: VBScript printing output to console

I have written script to connect from my local machine to Jump server using secure crt. i was able to execute the script and capture the output into Msgbox, But unable to print it to console.
Below is the code which i have written.
#$language = "VBScript"
#$interface = "1.0"
Set objTab = crt.GetScriptTab
Set g_shell = CreateObject("WScript.Shell")
Public szData
crt.Sleep 6000
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
crt.Screen.Synchronous = True
Dim pran
Sub Main
strVal = crt.Arguments(0)
crt.Screen.Send "pwd" & chr(13)
crt.Screen.WaitForString "[xyz#xlpv0002 ~]$"
crt.Screen.Send "sh test.sh" & chr(9) & chr(13)
**szData = CaptureOutputOfCommand("sh test.sh", "[xyz#xlpv0002 ~]") & vbCr**
'MsgBox(szData)
pran = szData
crt.Clipboard.Format = "CF_TEXT"
crt.Clipboard.Text = pran
crt.Dialog.MessageBox("Text is now in the clipboard: \n\n" + crt.Clipboard.Text)
'MessageBox.Show(szData)
If Not SendExpect("exit", "[xyz#xlpv0002 ~]") then exit sub
g_shell.Run "%comspec% /c taskkill /IM SecureCRT.exe /F"
End Sub
'=======================================================================
Function CaptureOutputOfCommand(szCommand, szPrompt)
if crt.Session.Connected <> True then
CaptureOutputOfCommand = "[ERROR: Not Connected.]"
exit function
end if
objTab.Screen.Send szCommand & vbcr
objTab.Screen.WaitForString vbcr
CaptureOutputOfCommand = objTab.Screen.ReadString(szPrompt)
End Function
'======================================================================
Function SendExpect(szSend, szExpect)
if objTab.Session.Connected <> True then exit function
objTab.Screen.Send szSend & vbcr
objTab.Screen.WaitForString szExpect
SendExpect = True
End Function
'========================================
I am capturing the script output into szData variable. Is there a way to print the same in the console?
You are already using the command
crt.Screen.Send
You just need to pass a valid command that will output to the console, if doing this on a Windows Server you should be able to use the Command Line program ECHO to output to the console.
crt.Screen.Send "echo Display in console!!!"
Output (untested, but should produce)
Display in console!!!
So you should just be able to do
crt.Screen.Send "echo " & szData
Useful Links
Scripting Essentials:
A Guide to Using
VBScript in SecureCRT (official documentation)

VBS: Call a URL pass HTMLString paramater to send as email

How to pass multiple variables to a link/href without having to open the browser using VBScript? The goal is to save/insert/update depending on the parameters that was passed on the URL, and the IIS Webserver would have to do the database change instead of the VBScript. The VBScript runs on schedule and would not want to open browser on the server each time it is executed.
My VBS code below:
Function HTMLEncode(Text)
Dim i
Dim acode
Dim repl
HTMLEncode = Text
For i = Len(HTMLEncode) To 1 Step -1
acode = Asc(Mid(HTMLEncode, i, 1))
Select Case acode
Case 32
repl = " "
Case 34
repl = """
Case 38
repl = "&"
Case 60
repl = "<"
Case 62
repl = ">"
Case acode => 32 AND acode <= 127
' don't touch alphanumeric chars
Case Else
repl = "&#" & CStr(acode) & ";"
End Select
If Len(repl) Then
HTMLEncode = Left(HTMLEncode, i - 1) & repl & Mid(HTMLEncode,+ 1)
repl = ""
End If
Next
End Function
strBody = "<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.0 Transitional//EN"">" & _
"<html>" & _
"<head>" & _
"<title>TEST</title>" & _
"</head>" & _
"<body bgcolor=""#FFFFFF"">" & _
"<p> The user bla bla bla </p>" & _
"<p><b> " & _
"<br><br><br><br> This message is sent from an un-monitored mailbox, please do not reply. " & _
"</p>" & _
"</body>" & _
"</html>"
strBody = HTMLEncode(strBody)
myURL = "http://www.test.com/sendmail.asp?body=" & strBody
Set req = CreateObject("MSXML2.XMLHTTP.6.0")
req.Open "GET", myURL, False
req.Send

Shapes.AddPicture adds only the last image - Excel VB macro for Mac

I have an excel macro, which populate images in an excel sheet from a server.
While this is straight forward for windows, for Mac, I get the images using the "curl" command, copy it over to a local folder ( if the imaage is existing), and use Shapes.AddPicture to insert the image and then delete the local image. For a single picture, this works great. But when I have to select a few columns and add multiple images, it only adds the last image. Can someone tell me why and how to fix this?
Below is the relevant code
=====================================
For Each objCell In objSelectedRange
If objCell.Value <> "" Then
UserPath = UserPath & "/" & objCell.Value & ImageType ' Add prefix and filename
ImagePath = ImageFolder & objCell.Value & ImageType
FTPpathtofile = ImagePath
scriptToCheck = "tell application " & Chr(34) & "Finder" & Chr(34) & " to do shell script " & Chr(34) & "curl " & FTPpathtofile & Chr(34)
retCode = MacScript(scriptToCheck)
str = (InStr(retCode, "404"))
If (str = 0) Then
scriptToRun = "tell application " & Chr(34) & "Finder" & Chr(34) & " to do shell script " & Chr(34) & "curl " & FTPpathtofile & " >" & UserPath & Chr(34)
MacScript (scriptToRun)
With ActiveSheet
PathtoHD = MacScript("path to startup disk as string")
localImagePath = Replace(UserPath, "/", ":")
localImagePath = PathtoHD & localImagePath
Set objImgMac = .Shapes.AddPicture(localImagePath, True, True, objCell.Left, objCell.Top, 30, 60)
If adjustCell Then
objCell.RowHeight = 78
If objCell.ColumnWidth < 12 Then
objCell.ColumnWidth = 12
End If
End If
If vAlign = "Top" Then
objCell.VerticalAlignment = xlVAlignTop
objImgMac.Top = objCell.Top + 15
objImgMac.Left = objCell.Left + 5
Else
If vAlign = "Bottom" Then
objCell.VerticalAlignment = xlVAlignBottom
objImgMac.Top = objCell.Top + 5
objImgMac.Left = objCell.Left + 5
End If
End If
End With
'delete file from the folder
DeleteFileOnMac (localImagePath)
End If
End If
Next objCell
=============================
You have
UserPath = UserPath & "/" & objCell.Value & ImageType
within your loop, but you don't seem to ever reset the value of UserPath between iterations, so it will just accumulate content.

vbs rasdial with phonebook entry

can somebody help me with my small project. I dont get the right code...
The rasdial with username and pass worked, when the standard phonebook is in use. The only thing is to bind another phonebook in the script to dial with this.
here my excample:
Set WshShell = WScript.CreateObject("WScript.Shell")
vbConnectionName = "test"
vbConnectionUser = "user"
vbConnectionPassword = "pass"
vbConnectWith = "rasdial" & " """ & vbConnectionName & """ """ & vbConnectionUser & """ """ & vbConnectionPassword & """ /phonebook:"%programfiles%\test program\rasphone.pbk""
I hope it is understandable.
The quoting of the last argument isn't correct. You have this:
... & """ /phonebook:"%programfiles%\test program\rasphone.pbk""
but you need this:
... & """ /phonebook:""%programfiles%\test program\rasphone.pbk"""
Using a quoting function helps avoiding quotefusion:
Function qq(str)
qq = Chr(34) & str & Chr(34)
End Function
'...
vbConnectWith = "rasdial " & qq(vbConnectionName) _
& " " & qq(vbConnectionUser) _
& " " & qq(vbConnectionPassword) _
& " /phonebook:" & qq("%programfiles%\test program\rasphone.pbk")

Resources