Cannot automate script, always stuck in running mode.

Use this forum if you have problems with a hMailServer script, such as hMailServer WebAdmin or code in an event handler.
Post Reply
black zero
Normal user
Normal user
Posts: 111
Joined: 2008-08-01 15:26

Cannot automate script, always stuck in running mode.

Post by black zero » 2015-03-10 04:32

The said script is here: viewtopic.php?f=20&t=15363&p=173161#p158795

Having been using this script for many days, I am certain it's good for me.

Now the question is, I can't seem to automate it every night with Windows' Task Scheduler. The script runs, but always stuck in 'running' mode and doesn't actually do anything when it's ran by scheduler.

When I double click the script myself, it runs just fine and ends just fine.

What gives?

Sorry for double post, I'll remove my post (if I could) in that thread pertaining the same problem.

User avatar
mattg
Moderator
Moderator
Posts: 21103
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Cannot automate script, always stuck in running mode.

Post by mattg » 2015-03-10 05:52

This is very likely Windows permission related

If you run the script in the task manager, you can set the permissions for the task.

Does your install use network storage, UNC paths etc?
Does your hMailserver service run under the default user, or a custom user.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
jimimaseye
Moderator
Moderator
Posts: 8777
Joined: 2011-09-08 17:48

Re: Cannot automate script, always stuck in running mode.

Post by jimimaseye » 2015-03-10 12:07

Do a simple test.

Start a fresh new VBS eqiuivalent to open a text file, write to it and close it.

Then set it in task scheduler to run.

Does it run?

If it doesnt then its your windows permissions. If it does, look at what is different and compare between the 2 task scheduler entries. (folder locations, permissions etc)

I suspect, however, you have the wrong program call. Make sure you are entering the program call correctly. It should be:

Program: cscript
Arguments: ..path..\YourEmailClearupScript.vbs //nologo
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

black zero
Normal user
Normal user
Posts: 111
Joined: 2008-08-01 15:26

Re: Cannot automate script, always stuck in running mode.

Post by black zero » 2015-03-12 04:11

Here's a bit more data to depict my situations.

I'm running everything on Administrator account.

The said script is located on: C:\Program Files (x86)\hMailServer\Addons\Utilities

Funny thing is, when I setup to Scheduler other script named "StartBackup.vbs", it runs just fine.

I compared StartBackup.vbs vs this problematic script (CleanOldMails.vbs) in question, the status in Scheduler is all the same! Including the path to the folder (obviously script name is different) and even the login information to run the scripts.

1. Run whether user is logged in or not is ticked.
2. Run with highest priveleges is ticked
3. Trigger - Daily 10 PM every day
4. Script being run: "C:\Program Files (x86)\hMailServer\Addons\Utilities\CleanOldMails.vbs" (booohooo not working) vs "C:\Program Files (x86)\hMailServer\Addons\Utilities\StartBackup.vbs" (yes working)
5. Conditions: both are Start the task only when AC Power

And yes, I've tried creating a new txt file from scratch (CleanOldMails.vbs) and saved it as vbs. I tested to run it with double mouse click and it ran just ok. When I scheduled CleanOldMails.vbs it... didn't work.

I'm out of ideas.

User avatar
mattg
Moderator
Moderator
Posts: 21103
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Cannot automate script, always stuck in running mode.

Post by mattg » 2015-03-12 07:07

Does the script try to open a Window or an echo?

Scripts run via Task Scheduler can't access the GUI generally
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

black zero
Normal user
Normal user
Posts: 111
Joined: 2008-08-01 15:26

Re: Cannot automate script, always stuck in running mode.

Post by black zero » 2015-03-12 08:53

Yes, single line

Code: Select all

WScript.Echo "Removed a total of " & GrandTotal & " message(s)."
At the very bottom.

I'm going to remove it.

User avatar
jimimaseye
Moderator
Moderator
Posts: 8777
Joined: 2011-09-08 17:48

Re: Cannot automate script, always stuck in running mode.

Post by jimimaseye » 2015-03-12 11:46

jimimaseye wrote: I suspect, however, you have the wrong program call. Make sure you are entering the program call correctly. It should be:

Program: cscript
Arguments: ..path..\YourEmailClearupScript.vbs //nologo
Believe me.
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

User avatar
mattg
Moderator
Moderator
Posts: 21103
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Cannot automate script, always stuck in running mode.

Post by mattg » 2015-03-12 13:40

jimimaseye wrote:
jimimaseye wrote: I suspect, however, you have the wrong program call. Make sure you are entering the program call correctly. It should be:

Program: cscript
Arguments: ..path..\YourEmailClearupScript.vbs //nologo
Believe me.
I normally just select 'start a program', then just point to the .vbs

This has always worked for me.
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

User avatar
SorenR
Senior user
Senior user
Posts: 3818
Joined: 2006-08-21 15:38
Location: Denmark

Re: Cannot automate script, always stuck in running mode.

Post by SorenR » 2015-03-12 15:02

I believe if you run this "cscript //h:cscript //s" in a CMD prompt, you set the default scripting engine to "Console".

If the default scripting engine is "wscript" all output will appear as message boxes. It's really hard to click OK on a message box if the script is running unattended :wink:

"cscript //?" will display help and parameters for your scripting engine.

When running unattended it may be more productive to use "//B" and not "//NoLogo".
SørenR.

“Those who don't know history are doomed to repeat it.”
― Edmund Burke

User avatar
jimimaseye
Moderator
Moderator
Posts: 8777
Joined: 2011-09-08 17:48

Re: Cannot automate script, always stuck in running mode.

Post by jimimaseye » 2015-03-12 15:54

I wa able to reproduce the OP's error exactly as he described.

I fixed the problem by doing what I said.
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

black zero
Normal user
Normal user
Posts: 111
Joined: 2008-08-01 15:26

Re: Cannot automate script, always stuck in running mode.

Post by black zero » 2015-03-13 04:33

jimimaseye wrote:I wa able to reproduce the OP's error exactly as he described.

I fixed the problem by doing what I said.
Yes, your solution fixed mine as well. Thank you very much, really appreciate it.

But still, it doesn't explain why my other script works (simply by pointing out the .vbs file from Task Scheduler) while this one in question does not work (although your solution did fix it).

I'm puzzled.

Any technical explanation about that?

User avatar
jimimaseye
Moderator
Moderator
Posts: 8777
Joined: 2011-09-08 17:48

Re: Cannot automate script, always stuck in running mode.

Post by jimimaseye » 2015-03-13 12:06

Nope. It baffles me too.

I also have another VBS script that works just fine by a direct call with Task Scheduler. The only difference is that that script (that works) doesnt have the Hmailserver ComAPI object being called (its a disk checking routine). Maybe thats the reason.

In any case, if you read up, it is always strongly recommended you call VBS scripts (from a calling script eg BAT file or scheduler) either with WSCRIPT or CSCRIPT rather than direct association to VBS.
5.7 on test.
SpamassassinForWindows 3.4.0 spamd service
AV: Clamwin + Clamd service + sanesecurity defs : https://www.hmailserver.com/forum/viewtopic.php?f=21&t=26829

User avatar
mattg
Moderator
Moderator
Posts: 21103
Joined: 2007-06-14 05:12
Location: 'The Outback' Australia

Re: Cannot automate script, always stuck in running mode.

Post by mattg » 2015-03-13 12:13

SorenR wrote:I believe if you run this "cscript //h:cscript //s" in a CMD prompt, you set the default scripting engine to "Console".

If the default scripting engine is "wscript" all output will appear as message boxes. It's really hard to click OK on a message box if the script is running unattended :wink:

"cscript //?" will display help and parameters for your scripting engine.

When running unattended it may be more productive to use "//B" and not "//NoLogo".
As Soren says, the default script engine on that system is probably wScript, and it should be cSrcipt to run theses scripts from a scheduled task.

Thinking about this, I do remember this issue a decade or more back.
Good pick up Jimimaseye
Just 'cause I link to a page and say little else doesn't mean I am not being nice.
https://www.hmailserver.com/documentation

Post Reply