Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: Re: VBScript to run a Batch file
PostPosted: 2009-12-22 01:57 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9369
Location: 'The Outback' Australia
I use a 'function' rather than a 'sub'. Unsure if the run function needs a 'function' though.

Why the 1 in the run line?
It's not really clear to me what changing true to false actually does in terms of difference in output. Is there a difference?

I have a function that I call from an account rule that works very well.
Code:
Function RemoveAttachments(oMessage)
   oMessage.attachments.clear()
   oMessage.save
End Function


I also have some scripts that that interact with the File System and the shell. My Shell script is below, and the parameter is the command to be run...
Again this works well (enough)
Code:
Function RunCommand(sCommand)
   Dim obShell
   Set obShell = CreateObject("WScript.Shell")
   obShell.Run sCommand, 0, true
   Set obShell = Nothing
End Function

Can you change this to be a script rather than a rule?

So what does your batch file do?

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: VBScript to run a Batch file
PostPosted: 2009-12-22 02:46 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9369
Location: 'The Outback' Australia
horndog wrote:
Can this be changed to run a Batch file?

It does run a batch file, or an executable, or a VBscript....

I generate mail all of the time using scripts...
One of the best examples is Martins notify of backup script here - viewtopic.php?f=20&t=14280

It will find the backup log file, open it, read it's contents, copy the contents to a new e-mail, and then empty the log file.
An e-mail is sent to the defined address with a copy of the backup log included...

So, what sort of messages are you trying to SMS to your phone...

Matt

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: VBScript to run a Batch file
PostPosted: 2009-12-22 07:43 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9369
Location: 'The Outback' Australia
horndog wrote:
Ok this is my path: c:\blat\blat.bat how would you integrate this into:
Code:
Function RunCommand(sCommand)
   Dim obShell
   Set obShell = CreateObject("WScript.Shell")
   obShell.Run sCommand, 0, true
   Set obShell = Nothing
End Function

have the above function exactly as detailed somewhere in the eventhandlers.vbs
And somewhere else in the event handlers, somewhere that gets triggered as needed, like say inside the sub OnDeliverMessage(), have

call runCommand("C:\blat\blat.bat")

This is how I'd do it....
Code:
Sub SendSMS()
   dim oApp, oMessage
   Set oApp = CreateObject("hMailServer.Application")
   MessageRecipientName = "Horndog"
   MessageRecipientAddress = "0000000000@txt.att.net"
   MessageSubject = "Email Alert"

   ' Give this script permission to access all
   ' hMailServer settings.
   Call oApp.Authenticate("Administrator", "SecretPassword")

   Set oMessage = CreateObject("hMailServer.Message")
   oMessage.From = "server  <server@yourdomain.com >"
   oMessage.FromAddress = "server@yourdomain.com"
   oMessage.Subject = MessageSubject
   oMessage.AddRecipient MessageRecipientName, MessageRecipientAddress
   oMessage.Body = "This is an auto generated alert." & vbNewLine & "Now to run the batch file!!"
   oMessage.Save
        call runCommand("C:\blat\blat.bat")
End Sub

Function RunCommand(sCommand)
   Dim obShell
   Set obShell = CreateObject("WScript.Shell")
   obShell.Run sCommand, 0, true
   Set obShell = Nothing
End Function


And then somewhere trigger the SendSMS Sub, perhaps even from your rule...

Not tested, but let me know how you get on.

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: VBScript to run a Batch file
PostPosted: 2009-12-22 10:19 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9369
Location: 'The Outback' Australia
horndog wrote:
Does the portion in red add duplicate information that is already in batch file? Blat.exe along with this batch file works by itself.

Yep, sorry. My script was to replace Blat and not use any external tools to send mail, just hMailserver... No need for an external executable

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: VBScript to run a Batch file
PostPosted: 2009-12-23 06:40 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9369
Location: 'The Outback' Australia
No worries mate. Glad to have helped

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: VBScript to run a Batch file [solved]
PostPosted: 2010-01-23 07:55 
New user
New user

Joined: 2010-01-23 07:45
Posts: 4
Hey, I'm sorry for being a complete noob, but I'm looking for how to run pretty much any command through a rule and the EventHandlers.vbs file. What would I have somewhat of an idea what to do, but not too much. Here's what I have:
  • Installed the server and configured it, of course.
  • Create a rule with the criteria
  • Set the Actions to run function (with nothing in the Script function box)
So, what exactly do I enter in the Script function box and what do I enter into the EventHandlers.vbs file?

Thank you all so much for any help. :D


Top
 Profile  
 
 Post subject: Re: VBScript to run a Batch file [solved]
PostPosted: 2010-01-23 16:08 
New user
New user

Joined: 2010-01-23 07:45
Posts: 4
What I'm trying to do is get my server to perform a certain action whenever I send it a text (SMS) message. For instance, if the server receives a message from 817913****@vtext.com that contains the word "shutdown," then the computer will know to shutdown, in other words, run the command "shutdown -s".

Is there any way to do this?


Top
 Profile  
 
 Post subject: Re: VBScript to run a Batch file [solved]
PostPosted: 2010-01-23 16:43 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9369
Location: 'The Outback' Australia
Yep.

I would just use a script.
Something like (and not tested btw)

Code:
Option Explicit
Const g_sCmdPath = "C:\winnt\system32\cmd.exe"
Private Const setting_username = "Administrator"
Private Const setting_password = "SecretPassword"

Sub OnAcceptMessage(oClient, oMessage)
   dim oApp
   Set oApp = CreateObject("hMailServer.Application")

   ' Give this script permission to access all
   ' hMailServer settings.
   Call oApp.Authenticate("Administrator", g_sAdminPassword)

   if oClient.Username = "817913****@vtext.com" and instr(oMessage.body, "Shutdown") > 0 then ' This is the message
      Call RunComand("shutdown /s")
   end if '

Function RunCommand(sCommand)
   Dim obShell
   Set obShell = CreateObject("WScript.Shell")
   obShell.Run sCommand, 0, true
   Set obShell = Nothing
End Function


Scripts need to be enabled, and this needs to be added to the eventhandlers.vbs, scripts reloaded etc...

_________________
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
Documentation


Top
 Profile  
 
 Post subject: Re: VBScript to run a Batch file [solved]
PostPosted: 2010-01-23 18:01 
New user
New user

Joined: 2010-01-23 07:45
Posts: 4
Thanks!

So, what would I enter in for the Script function box in the hMailServer rule? Or would I not mess with rules at all?


Top
 Profile  
 
 Post subject: Re: VBScript to run a Batch file [solved]
PostPosted: 2010-01-24 15:43 
New user
New user

Joined: 2010-01-23 07:45
Posts: 4
I'm sorry, I'm just really new at this. Gotta start somewhere... :oops:


Top
 Profile  
 
 Post subject: Re: VBScript to run a Batch file [solved]
PostPosted: 2010-01-24 15:44 
Site Admin

Joined: 2005-07-29 16:18
Posts: 13628
Location: UK
You do not need to use rules if you are using this script

_________________
If at first you don't succeed, bomb disposal probably isn't for you! ヅ


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 


Who is online

Users browsing this forum: No registered users and 1 guest



Search for:
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group