Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Saving attachment & run bat
PostPosted: 2012-07-06 12:54 
New user
New user

Joined: 2010-05-11 14:31
Posts: 6
Hello!

I tried to write a simple script that saving attached file to HDD and then run bat file to process them. First part works fine, but I cant run bat from the script, it just wont start, need help! Check Syntax shows "correct!".

Code:
Function SaveAttachments(oMessage)
Set oShell = CreateObject("WScript.Shell")

for i = 1 to oMessage.attachments.count ' attachment

      oMessage.attachments.item(i-1).saveAs("C:\FOMS\FT\" & oMessage.attachments.item(i-1).filename)
      path = "c:\FOMS\decript.bat"
      Call oShell.Run(path, 0, TRUE)

next 'i - attachment
End Function


Code:
"DEBUG"   1944   "2012-07-06 14:18:35.211"   "Delivering message..."
"APPLICATION"   1944   "2012-07-06 14:18:35.211"   "SMTPDeliverer - Message 180520: Delivering message from oit@---.ru to Vitaliy@---.ru. File: C:\Program Files\hMailServer\Data\{D0FECF0E-4111-45E0-A5CC-4C715AAFB2DC}.eml"
"DEBUG"   1944   "2012-07-06 14:18:35.242"   "Applying rules"
"DEBUG"   1944   "2012-07-06 14:18:35.242"   "Applying rule"
"DEBUG"   1944   "2012-07-06 14:18:35.242"   "Performing local delivery"
"DEBUG"   1944   "2012-07-06 14:18:35.289"   "Applying rules"
"DEBUG"   1944   "2012-07-06 14:18:35.289"   "Applying rule"
"DEBUG"   1944   "2012-07-06 14:18:35.289"   "Performing rule action"
"DEBUG"   1944   "2012-07-06 14:18:35.289"   "ScriptServer:FireEvent"
"ERROR"   1944   "2012-07-06 14:18:35.336"   "Script Error: Source: "DEBUG"   1944   "2012-07-06 14:18:35.336"   "ScriptServer:~FireEvent"
"DEBUG"   1944   "2012-07-06 14:18:35.336"   "Saving message: C:\Program Files\hMailServer\Data\nmcs.ru\vitaliy\D0\{D0FECF0E-4111-45E0-A5CC-4C715AAFB2DC}.eml"
"DEBUG"   1944   "2012-07-06 14:18:35.367"   "AWStats::LogDeliverySuccess"
"DEBUG"   1944   "2012-07-06 14:18:35.367"   "Local delivery completed"


Top
 Profile  
 
 Post subject: Re: Saving attachment & run bat
PostPosted: 2012-07-06 13:01 
Site Admin
User avatar

Joined: 2005-07-29 16:18
Posts: 13648
Location: UK
Make sure your bat file can be run from a service account. hMail runs as a service so likely just permissions based.

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


Top
 Profile  
 
 Post subject: Re: Saving attachment & run bat
PostPosted: 2012-07-06 13:12 
New user
New user

Joined: 2010-05-11 14:31
Posts: 6
I run hmail service from admin account :(


Top
 Profile  
 
 Post subject: Re: Saving attachment & run bat
PostPosted: 2012-07-06 13:47 
Site Admin
User avatar

Joined: 2005-07-29 16:18
Posts: 13648
Location: UK
Well first off that's dumb, and second, that's dumb. Set it back to what it should be. Also verify that the bat works when ran from a non admin account.

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


Top
 Profile  
 
 Post subject: Re: Saving attachment & run bat
PostPosted: 2012-07-06 14:37 
New user
New user

Joined: 2010-05-11 14:31
Posts: 6
Ive just run it from admin accont to check working script or not, coz Im thinking that its cant run from SYSTEM account.
bat is runnig ok from any account (when I start it manually), I only try to extract files from zip attachment, permissions on folder are set OK too, but the bat is not even start from vbs script. I try to use "echo some cmds >> log.txt" in the bat-file but log.txt is empty.


Top
 Profile  
 
 Post subject: Re: Saving attachment & run bat
PostPosted: 2012-07-06 14:47 
Site Admin
User avatar

Joined: 2005-07-29 16:18
Posts: 13648
Location: UK
This is how MattG does it

viewtopic.php?p=124827#p124827

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


Top
 Profile  
 
 Post subject: Re: Saving attachment & run bat
PostPosted: 2012-07-06 15:40 
New user
New user

Joined: 2010-05-11 14:31
Posts: 6
He move code from bat directly to vbs =) Its not a solution, because I need to run 3rd party exe to process my files :( If I call exe from vbs it doesnt run too :( Maybe hmail have restrictions to run something from vbs?


Top
 Profile  
 
 Post subject: Re: Saving attachment & run bat
PostPosted: 2012-07-06 15:46 
Site Admin
User avatar

Joined: 2005-07-29 16:18
Posts: 13648
Location: UK
No he doesn't.

mattg wrote:
I do it like this
Code:
Function RunCommand(sCommand)
   Dim obShell
   Set obShell = CreateObject("WScript.Shell")
   obShell.Run sCommand, 0, true
   Set obShell = Nothing
End Function


In your situation I'd then do something like this in my script
Code:
   Call RunCommand("E:\hms\copy.bat")

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


Top
 Profile  
 
 Post subject: Re: Saving attachment & run bat
PostPosted: 2012-07-07 14:48 
Moderator
User avatar

Joined: 2007-06-14 05:12
Posts: 9562
Location: 'The Outback' Australia
Also, if your BAT uses anything that requires a GUI it won't work.
hMailserver is a service, and you can't start a GUI from a service

_________________
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: Saving attachment & run bat
PostPosted: 2012-07-09 08:04 
New user
New user

Joined: 2010-05-11 14:31
Posts: 6
hm... thanks a lot, it really works! But I cant understand why?! If I dont create a subfunctin it wont work :(


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 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