Using a basic x64 Win2008 system I've tested scripts that merely try to
write to the event log or display output. Here's what I've found so far.
(1) I can successfully run a script that does nothing or writes to the event
log, using the default host or the 32-bit cscript; script writes to the
event log and then shuts down on its own.
(2) I can guarantee a hung script if the following two conditions are met:
- If I do something that would cause graphical element display (a MsgBox
statement, or a WScript.Echo display or error while using wscript.exe as the
host), and
- if the task is either set to be invisible or running without me logged on.
(3) If the script hangs, a timeout doesn't stop it, whether specified within
the script or on the commandline (e.g., by adding //T:60 to try causing
timeout in 60 seconds or less).
(4) The //B switch for batch mode works (which means that the script will
suppress graphical elements if possible, and die if not).
This feels more and more like a traditional Task Scheduler problem involving
_something_ trying to show itself and having nowhere to go. If you look at
the hung task in the Task Manager, I believe you will find it is running in
a separate session from you. Unfortunately, given that null scripts you've
tried also hang, it's clearly a problem happening before the script even
starts.
I'm now fairly certain that the script is being blocked by either
antivirus/antispyware software - either silently or some kind of prompt
which isn't being displayed - or there's a profile-specific policy
preventing execution.
"Alex K. Angelopoulos" <alex(dot) k(dot again)angelopoulos(at)gmail.com>
Post by unknownI don't have 2008 SBS, but I'm using a standard x64 Windows 2008 server
running in a virtual machine and ran a basic test script as shown at
bottom of my response here. For me, it ran with no problems whatsoever;
based on what you've reported, I suspect the problem you've been having is
that script execution is being intercepted.
I'm going to try a couple of other tests, including a script that just
sits and spins and a couple of test runs where I run as myself but logged
off, and also running as a system account, just to see if I can find any
"normal" configurations where it breaks on my system (and I'll also see if
I can track down SBS2008 to check for an out-of-box problem). Could you
check the following?
(1) In your "null" script, insert this as the line following Option
WScript.TimeOut = 10
and re-run, if you haven't already done so. This is simply to confirm that
the script isn't even starting up. If it shows as Running still after 10
seconds, we know that the script didn't even start executing. I think we
already know that, but this should confirm it.
(2) Check on the antivirus/antispyware applications you use. What are
they, what versions, and do they have any settings exposed for script
execution control? This seems the most likely source of problems.
(3) If (2) doesn't apply, is there anything you can think of that you've
customized in the configuration that affects security? I don't recall any
settings for 2008 that _should_ affect scheduled script execution alone,
so I still lean towards this being AV/antispyware related.
' demo script with logged events
Option Explicit
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.LogEvent 4, "Beginning script"
WshShell.LogEvent 4, "Ending script"
Post by BernieAl,
The dir in a batch was looking for someway to troubleshoot schedule task
to ever stopping. The real scrips do a database access and then send
result out as an email. I stripped all that out to eliminate the odbc
access or cdo usage as possible causes of the problem. I pick a simple
.bat file to simplify the troubleshooting but obviously picked a back one.
I'm changed my test to now run the following vbs file;
Option Explicit
Dim a
a = 0
I put this as the action in the scheduled task, right click and run. The
task in Task Scheduler continues to show Running. Obviously the script
will have completed in a second or two and it's now 90 seconds later and
the status is still running.
Does this eliminate your theory of the problem?
Bernie
Post by Al DunbarPost by Berniehahahaha,
Alex,
My entire script is;
Option Explicit
WScript.Echo "Script running"
WScript.Echo "Script Complete"
I can't add any more documentation points. The entire script is
documentation points, hahahaha.
I made a batch file called test.bat. Its entire contents are the single
command "dir". I created a scheduled task using the Basic Scheduled Task
wizard. I right click on the task and choose run. A command box opens and
displays the output of the dir command. In Task Manager I see cmd.exe start
and then stop when the output is over. In the Task Scheduler I see scheduled
task status as still "Running". I left on in running overnight last night as
a test and it still says running.
The task is run with the SBSAdmin user account which is the
administrator
account setup when the server was loaded.
Any suggestions on what to consider?
I suspect the your script is attempting to display the "script running"
message in a dialog box and waiting for you to click on the OK button.
Since scheduled tasks do not have a graphical interface, this dialog is
never displayed, but results in a hang.
If you want the script's output to behave like the output from your
batch task, you will have to schedule a task that causes CSCRIPT.exe to
run the script. The simplest way would be to schedule a batch file that
@cscript.exe //nologo "%~dpn0.vbs"
This would attempt to run a vbs file of the same name as the batch
script located in the same folder.
I usually use scheduled tasks to do things that generally do not include
any interactive display. Most of the time these things run when nobody
is logged on. If there is some need to verify the work of the script,
that is usually done with some form of logging, whether to a file or the
event log.
/Al
Post by BernieThanks,
Bernie
"Alex K. Angelopoulos" <alex(dot) k(dot
Post by unknownThere's no task scheduler forum, so you'll end up circling back to
here. ; )
What I suspect is that one of the things you do in your script makes
it hang when running scheduled, which is why I was suggesting using
the event log to capture information. You don't need to insert logging
statements everywhere to start checking it, even. If you simply insert
2-4 statements at critical points, you'll be able to bracket the
location where the failure occurs and then focus on that.
What I suspect is that you have a problem when using a particular
component or accessing a resource; it may occur because something else
has blocking access to the resource (I'm assuming you don't have On
Error Resume Next statements in the code; that widens the problem area
a bit).
Post by BernieWell, I made a copy of my script I useing to test and started
removing items until I got a working combination. I how have;
Option Explicit
WScript.Echo "Script running"
WScript.Echo "Script Complete"
I then turned my focus on the Scheduled Task settings and removed the
32 bit launch. It now just runs;
C:\Scripts\bdtest.vbs
Which is the above three line script. So this points to a Scheduled
Task problem.
I change the target to execute to a batch file called test.bat with
only the "dir" command in it. I right click on the tash in scheduler
and select run. The bat file runs, I see the directory output in a
command window. The command window closes, but the status in task
scheduler continues to say run. So I have a task schedule problem for
sure.
Thanks for your help Alex. It looks like I'm now in the wrong forum.
I'll go in search of a Task Scheduler forum, hahaha.
Bernie
"Alex K. Angelopoulos" <alex(dot) k(dot
Post by unknownAnd you don't have a hint about where the error is showing up, of
course, with that kind of result. Two possible ways to follow up on
(1) Post the script as-is (munging database passwords of course) so
we can take a look at possible issues. That could be troublesome if
it's lengthy, and it would be almost unmanageable unless all lines
are less than 76 chars long since the script would get serious
mangling.
(2) Insert some logevent statements in the script at specific
locations so that you can get specific information dumped out to the
event log. This should help localize where the scheduled task is
running into problems. If you're not familiar with LogEvent, it's a
method exposed by WScript.Shell. You'll need to supply it with an
event type numeric (use 4 for Information) and with an argument that
is a text string which will be logged. Events logged this way should
show up in the Application log and will show WSH as their source.
Set WshShell = CreateObject("WScript.Shell")
WshShell.LogEvent 4, "script starting"
' do stuff
WshShell.LogEvent 4, "about to connect to database"
' do stuff
WshShell.LogEvent 4, "Finished with database connection"
I recommend inserting a line immediately before and after each
individual point when you access a resource - file, database, even
mapping a drive. This should tell us precisely where the problem is
occurring.
Post by BernieI moved the script and it's support files to c:\scripts. I can
still run the file from command prompt, but I could do that before.
The hanging while running continues in the new location.
Bernie
"Alex K. Angelopoulos" <alex(dot) k(dot
Post by unknownI suggest moving the script and any support files it uses to
another location, with NO spaces in its path. The problem you're
describing could come from anything from the task scheduler having
stripped quotes from the path to a misinterpretation of the Program
Files path based on bitness-specific redirection to permission
errors due to tighter security on the version of Windows you're
using. Alternatively, try re-checking this by running the script
directly yourself and seeing whether it succeeds or not - and if
so, where it fails.
Post by BernieI'm making some progress on this issue. I have the task setup with;
Program/script - %windir%\SysWOW64\wscript.exe
Add arguments - "C:\Program Files (x86)\Scripts\Birthday List.vbs"
The script does a db query, makes a list of birthdays, and sends
it in an email. The script has worked for years in a SBS 2003
environment as a scheduled task.
I can right click on the task and select run. The script will run
and the emal will be sent. The status in Task Scheduler stays at
"Running" and
there are two entries in the History section. One for Action
Completed and the other for Task Completed. Both have an
Operational Code of 2. I couldn't find a exact listing of all the
Operational Codes. DAGS shows may people repeating the same
limited list of 3 or 4, but not a list showing (2). I found this;
http://msdn.microsoft.com/en-us/library/ms681382(VS.85).aspx
and some implications that these are the same errors. If that's
true then my error is File Not Found. Hmmmmm.
I can maually run the script in both CMD from Start|Run and from
Command Prompt with or without admin status and no errors
detected. I'm using a command line of;
%windir%\SysWOW64\wscript.exe "C:\Program Files
(x86)\Scripts\Birthday List.vbs"
Any suggestions or directions?
Thanks,
Bernie
Post by BernieThanks to Mark and Alex I have all my scripts back working again
on my SBS 2008 64 bit server. Because the database ODBC
connection is only 32 bit, I have to run in 32 bit mode. On the
old server all these scripts ran as scheduled tasks. Is there a
way to run in 32 bit mode out of a Scheduled Task?
Thanks,
Bernie