Discussion:
Can't Run Excel From A Cron Job Under Windows 7
(too old to reply)
Kertz, Denis (D)** CTR **
2014-11-11 17:28:24 UTC
Permalink
I am trying to port a cygwin application that uses cron from a WinXP PC to a Win7 Pro PC and I find some cron jobs won't run. Specifically, I need to run an Excel program from a cron job and this doesn't work on my Win7 PC.

In order to run an Excel program from cygwin I have this run.excel bash script with an embedded VB script that executes an Excel program:

excel=$1
vbscript=/usr/tmp/$$.vbs
cat <<-! >$vbscript
Dim xlApp
Set xlApp = CreateObject("Excel.application")
Set xlWb = xlApp.workbooks.Open("$excel")
xlApp.Quit
Set xlWb = Nothing
Set xlApp = Nothing
!
chmod 777 $vbscript
c:/Windows/System32/wscript.exe 'c:\cygwin64\usr\tmp\$$.vbs'

An excel program is run like this:

run.excel 'c:\Shared\Bin\Create_Daily_Scorecard.xls'

When I run an Excel program interactively with this run.excel script it runs just fine but when I run it via a cron job Excel just hangs. When Excel hangs I can look at the processes running on the PC using the Windows Task Manager and I don't see the EXCEL.EXE process. But when I check the option to show processes from all users I see the hung EXCEL.EXE process, AND the user name displayed is my login. So I am running this under the Upar2 login and Task Manager doesn't display EXCEL.EXE as a Upar2 process but when I check 'Show processes from all users' it shows EXCEL.EXE running under user name Upar2 - a contradiction.

What I suspect is happening is Excel is attempting to do something that requires Upar2 permission but it isn't really running as Upar2 so Excel displays some error message and is waiting for the user to respond. But Excel is running invisibly so this can't be seen.

I also suspect this Upar2 "confusion" isn't limited to running an Excel program. I can run a cron job with regular UNIX commands (cut, sort, etc) and see they are running with the ps command. But when I try to kill them (kill -9) I get permission denied. If I want to kill a process running via the cron I have to start cygwin with 'Run as administrator' and then I can kill processes running under the cron.

So, does anyone know what's going on here and what I need to do get these cron jobs running. As I noted at the beginning this is being ported from WinXP, where all this works fine, to Win7.

I set up cron using cron-config like this:

$ cron-config
Do you want to install the cron daemon as a service? (yes/no) yes
Enter the value of CYGWIN for the daemon: [ ]

Do you want the cron daemon to run as yourself? (yes/no) yes

Please enter the password for user 'Upar2':
Reenter:
Running cron_diagnose ...
... no problem found.

Do you want to start the cron daemon as a service now? (yes/no) yes
OK. The cron daemon is now running.

Denis
Andrey Repin
2014-11-11 19:17:49 UTC
Permalink
Greetings, Kertz, Denis (D)** CTR **!
Post by Kertz, Denis (D)** CTR **
I am trying to port a cygwin application that uses cron from a WinXP PC to
a Win7 Pro PC and I find some cron jobs won't run. Specifically, I need to
run an Excel program from a cron job and this doesn't work on my Win7 PC.
In order to run an Excel program from cygwin I have this run.excel bash
excel=$1
vbscript=/usr/tmp/$$.vbs
cat <<-! >$vbscript
Dim xlApp
Set xlApp = CreateObject("Excel.application")
Set xlWb = xlApp.workbooks.Open("$excel")
xlApp.Quit
Set xlWb = Nothing
Set xlApp = Nothing
!
chmod 777 $vbscript
c:/Windows/System32/wscript.exe 'c:\cygwin64\usr\tmp\$$.vbs'
run.excel 'c:\Shared\Bin\Create_Daily_Scorecard.xls'
When I run an Excel program interactively with this run.excel script it
runs just fine but when I run it via a cron job Excel just hangs.
Define "runs fine" please?
What exactly that excel script is doing?
Post by Kertz, Denis (D)** CTR **
When Excel hangs I can look at the processes running on the PC using the
Windows Task Manager and I don't see the EXCEL.EXE process. But when I
check the option to show processes from all users I see the hung EXCEL.EXE
process, AND the user name displayed is my login. So I am running this under the
Upar2 login and Task Manager doesn't display EXCEL.EXE as a Upar2 process
but when I check 'Show processes from all users' it shows EXCEL.EXE running
under user name Upar2 - a contradiction.
Task manager display processes started in your current session.
Not processes started under your credentials. That's an important difference.
Post by Kertz, Denis (D)** CTR **
What I suspect is happening is Excel is attempting to do something that
requires Upar2 permission but it isn't really running as Upar2 so Excel
displays some error message and is waiting for the user to respond. But
Excel is running invisibly so this can't be seen.
More like you expect to run Excel interactively from service.
Not possible. Period.
Post by Kertz, Denis (D)** CTR **
I also suspect this Upar2 "confusion" isn't limited to running an Excel
program. I can run a cron job with regular UNIX commands (cut, sort, etc)
and see they are running with the ps command. But when I try to kill them
(kill -9) I get permission denied. If I want to kill a process running via
the cron I have to start cygwin with 'Run as administrator' and then I can
kill processes running under the cron.
Of course.


--
WBR,
Andrey Repin (***@yandex.ru) 11.11.2014, <22:14>

Sorry for my terrible english...


--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Kertz, Denis (D)** CTR **
2014-11-12 16:20:05 UTC
Permalink
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
run.excel 'c:\Shared\Bin\Create_Daily_Scorecard.xls'
When I run an Excel program interactively with this run.excel script it
runs just fine but when I run it via a cron job Excel just hangs.
Define "runs fine" please?
What exactly that excel script is doing?
This run.excel script simply starts up Excel with the .xls file it is given. In this example Excel opens c:\Shared\Bin\Create_Daily_Scorecard.xls. This .xls has a Workbook_Open macro, which is automatically run whenever this .xls is opened, that reads some data files and creates another .xls as its output.

What I mean by runs fine is that when I type this command at a bash prompt:
run.excel 'c:\Shared\Bin\Create_Daily_Scorecard.xls'
it runs to completion and creates a new .xls as its output. When I run this run.excel script from a cron job it hangs.
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
When Excel hangs I can look at the processes running on the PC using the
Windows Task Manager and I don't see the EXCEL.EXE process. But when I
check the option to show processes from all users I see the hung EXCEL.EXE
process, AND the user name displayed is my login. So I am running this under the
Upar2 login and Task Manager doesn't display EXCEL.EXE as a Upar2 process
but when I check 'Show processes from all users' it shows EXCEL.EXE running
under user name Upar2 - a contradiction.
Task manager display processes started in your current session.
Not processes started under your credentials. That's an important difference.
Then this is just a difference between WinXP and Win7? Under WinXP it shows EXCEL.EXE in my process list even when the "Show processes from all users" isn't checked.
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
What I suspect is happening is Excel is attempting to do something that
requires Upar2 permission but it isn't really running as Upar2 so Excel
displays some error message and is waiting for the user to respond. But
Excel is running invisibly so this can't be seen.
More like you expect to run Excel interactively from service.
Not possible. Period.
I'm not trying to run Excel interactively from a cron job. One of the limitations with using Excel from a cron job is Excel has to run error free. If Excel does run into some error it will typically generate an error message and wait for a user response. Since Excel is running invisibly from a cron job, there is no user to give a response and Excel just sits there waiting for a response that will never come.
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
I also suspect this Upar2 "confusion" isn't limited to running an Excel
program. I can run a cron job with regular UNIX commands (cut, sort, etc)
and see they are running with the ps command. But when I try to kill them
(kill -9) I get permission denied. If I want to kill a process running via
the cron I have to start cygwin with 'Run as administrator' and then I can
kill processes running under the cron.
Of course.
Why "of course"? Shouldn't I be able to kill my own processes? I can certainly do that under WinXP. But this isn't a major issue for me. I only pointed it out in case it was related to the issue why my Excel cron jobs hang.

--
Post by Andrey Repin
WBR,
Sorry for my terrible english...
Nothing wrong with your English...

Denis


--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Andrey Repin
2014-11-12 20:12:25 UTC
Permalink
Greetings, Kertz, Denis (D)** CTR **!
Post by Kertz, Denis (D)** CTR **
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
run.excel 'c:\Shared\Bin\Create_Daily_Scorecard.xls'
When I run an Excel program interactively with this run.excel script it
runs just fine but when I run it via a cron job Excel just hangs.
Define "runs fine" please?
What exactly that excel script is doing?
This run.excel script simply starts up Excel with the .xls file it is
given. In this example Excel opens
c:\Shared\Bin\Create_Daily_Scorecard.xls. This .xls has a Workbook_Open
macro, which is automatically run whenever this .xls is opened, that reads
some data files and creates another .xls as its output.
run.excel 'c:\Shared\Bin\Create_Daily_Scorecard.xls'
it runs to completion and creates a new .xls as its output. When I run
this run.excel script from a cron job it hangs.
Hangs as in - do not create new file?
Post by Kertz, Denis (D)** CTR **
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
When Excel hangs I can look at the processes running on the PC using the
Windows Task Manager and I don't see the EXCEL.EXE process. But when I
check the option to show processes from all users I see the hung EXCEL.EXE
process, AND the user name displayed is my login. So I am running this under the
Upar2 login and Task Manager doesn't display EXCEL.EXE as a Upar2 process
but when I check 'Show processes from all users' it shows EXCEL.EXE running
under user name Upar2 - a contradiction.
Task manager display processes started in your current session.
Not processes started under your credentials. That's an important difference.
Then this is just a difference between WinXP and Win7?
It was the case in Vista already.
Post by Kertz, Denis (D)** CTR **
Under WinXP it shows EXCEL.EXE in my process list even when the "Show
processes from all users" isn't checked.
Only if you logged in as admin.
Post by Kertz, Denis (D)** CTR **
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
What I suspect is happening is Excel is attempting to do something that
requires Upar2 permission but it isn't really running as Upar2 so Excel
displays some error message and is waiting for the user to respond. But
Excel is running invisibly so this can't be seen.
More like you expect to run Excel interactively from service.
Not possible. Period.
I'm not trying to run Excel interactively from a cron job. One of the
limitations with using Excel from a cron job is Excel has to run error free.
If Excel does run into some error it will typically generate an error
message and wait for a user response. Since Excel is running invisibly from
a cron job, there is no user to give a response and Excel just sits there
waiting for a response that will never come.
Try starting cron in terminal session and see if anything comes up.
Post by Kertz, Denis (D)** CTR **
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
I also suspect this Upar2 "confusion" isn't limited to running an Excel
program. I can run a cron job with regular UNIX commands (cut, sort, etc)
and see they are running with the ps command. But when I try to kill them
(kill -9) I get permission denied. If I want to kill a process running via
the cron I have to start cygwin with 'Run as administrator' and then I can
kill processes running under the cron.
Of course.
Why "of course"? Shouldn't I be able to kill my own processes?
It's not "your own" process, it's "cron job" started with your credentials.
Post by Kertz, Denis (D)** CTR **
I can certainly do that under WinXP.
Again, only if you logged in as admin.
This is not the case in Vista+ by default.
Post by Kertz, Denis (D)** CTR **
But this isn't a major issue for me. I only
pointed it out in case it was related to the issue why my Excel cron jobs hang.
--
WBR,
Andrey Repin (***@yandex.ru) 12.11.2014, <23:08>

Sorry for my terrible english...


--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Kertz, Denis (D)** CTR **
2014-11-13 01:22:11 UTC
Permalink
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
run.excel 'c:\Shared\Bin\Create_Daily_Scorecard.xls'
it runs to completion and creates a new .xls as its output. When I run
this run.excel script from a cron job it hangs.
Hangs as in - do not create new file?
Hangs as in never finishes and I don't know what, if anything, it has done. But that suggests some tests for me to run that I should have thought of. First, create a test .xls that does nothing and see if that runs to completion. If it does, then create a test .xls that simply creates a file to test whether it actually creates the file.
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
I'm not trying to run Excel interactively from a cron job. One of the
limitations with using Excel from a cron job is Excel has to run error free.
If Excel does run into some error it will typically generate an error
message and wait for a user response. Since Excel is running invisibly from
a cron job, there is no user to give a response and Excel just sits there
waiting for a response that will never come.
Try starting cron in terminal session and see if anything comes up.
Can you tell me how to do this? When I run the ps command in a terminal session, I see this:
$ ps
PID PPID PGID WINPID TTY UID STIME COMMAND
5780 5568 5780 3408 pty0 1000 Nov 5 /usr/bin/bash
5568 1 5568 5568 ? 1000 Nov 5 /usr/bin/mintty
3716 5780 3716 1016 pty0 1000 18:58:16 /usr/bin/ps
1820 1 1820 1820 ? 1000 Nov 5 /usr/bin/cygrunsrv
1856 1820 1856 1892 ? 1000 Nov 5 /usr/sbin/cron

Do I have to kill the cygrunsrv and cron processes and then ??
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
Why "of course"? Shouldn't I be able to kill my own processes?
It's not "your own" process, it's "cron job" started with your credentials.
Post by Kertz, Denis (D)** CTR **
I can certainly do that under WinXP.
Again, only if you logged in as admin.
This is not the case in Vista+ by default.
Okay, I think what you are telling me is that the login I'm using on "my" WinXP PC (which I inherited) must be an administrator login and the login I'm using on the Win7 PC is not an administrator login (it isn't). That sounds plausible (I know a lot more about UNIX than I do about Windows). So the differences I'm seeing between WinXP and Win7 is due to using/not using an administrator login, not due to whether it is WinXP or Win7.

Denis

--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Andrey Repin
2014-11-13 22:25:21 UTC
Permalink
Greetings, Kertz, Denis (D)** CTR **!
Post by Kertz, Denis (D)** CTR **
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
run.excel 'c:\Shared\Bin\Create_Daily_Scorecard.xls'
it runs to completion and creates a new .xls as its output. When I run
this run.excel script from a cron job it hangs.
Hangs as in - do not create new file?
Hangs as in never finishes and I don't know what, if anything, it has done.
But that suggests some tests for me to run that I should have thought of.
First, create a test .xls that does nothing and see if that runs to
completion. If it does, then create a test .xls that simply creates a file
to test whether it actually creates the file.
:)
Post by Kertz, Denis (D)** CTR **
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
I'm not trying to run Excel interactively from a cron job. One of the
limitations with using Excel from a cron job is Excel has to run error free.
If Excel does run into some error it will typically generate an error
message and wait for a user response. Since Excel is running invisibly from
a cron job, there is no user to give a response and Excel just sits there
waiting for a response that will never come.
Try starting cron in terminal session and see if anything comes up.
$ ps
PID PPID PGID WINPID TTY UID STIME COMMAND
5780 5568 5780 3408 pty0 1000 Nov 5 /usr/bin/bash
5568 1 5568 5568 ? 1000 Nov 5 /usr/bin/mintty
3716 5780 3716 1016 pty0 1000 18:58:16 /usr/bin/ps
1820 1 1820 1820 ? 1000 Nov 5 /usr/bin/cygrunsrv
1856 1820 1856 1892 ? 1000 Nov 5 /usr/sbin/cron
Do I have to kill the cygrunsrv and cron processes and then ??
Stop (don't kill! Everyone, who use -KILL, must be -KILL'ed) the cron service,
then start cron in terminal, using `runas /user:... ...'. So it would run
under proper user, and see if anything come up, when it execute your excel
job.
Post by Kertz, Denis (D)** CTR **
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
Why "of course"? Shouldn't I be able to kill my own processes?
It's not "your own" process, it's "cron job" started with your credentials.
Post by Kertz, Denis (D)** CTR **
I can certainly do that under WinXP.
Again, only if you logged in as admin.
This is not the case in Vista+ by default.
Okay, I think what you are telling me is that the login I'm using on "my"
WinXP PC (which I inherited) must be an administrator login
By default, the first user account created after system installation
(rid:1000), have admin rights. In any system, starting from Win2000.
However, WinXP has no concept of privilege escalation, and if you've had admin
rights, you were always working with them enabled.
Post by Kertz, Denis (D)** CTR **
and the login
I'm using on the Win7 PC is not an administrator login (it isn't). That
sounds plausible (I know a lot more about UNIX than I do about Windows).
Then just think as if you've been running as root in WinXP, but now, you're
running as user with access to sudo facility under Win7. This is not entirely
correct, but close enough to give you an idea.
Post by Kertz, Denis (D)** CTR **
So
the differences I'm seeing between WinXP and Win7 is due to using/not using
an administrator login, not due to whether it is WinXP or Win7.
The difference is inherently architectural, and not directly related to using
or not using admin account.
I think we best keep discussion strictly relevant to your present issue.
If you want any more details on Win7 security "improvements", google "UAC
description".


--
WBR,
Andrey Repin (***@yandex.ru) 14.11.2014, <01:14>

Sorry for my terrible english...


--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Kertz, Denis (D)** CTR **
2014-11-18 01:36:19 UTC
Permalink
Post by Andrey Repin
Post by Andrey Repin
Try starting cron in terminal session and see if anything comes up.
Stop (don't kill! Everyone, who use -KILL, must be -KILL'ed) the cron service,
then start cron in terminal, using `runas /user:... ...'. So it would run
under proper user, and see if anything come up, when it execute your excel
job.
I was unable to find how to use runas from a terminal. I can simply type runas and it does nothing and I can't find --help or /help. I did find a suggestion to use cygstart so I tried this:

$ cygstart --action=runas '/bin/cygrunsrv --start cron'
Unable to start 'C:\cygwin64\bin\cygrunsrv --start cron': The specified file was not found.

So that didn't work. I did try starting the cron service (cygrunsrv) from a terminal session run as administrator and I tried starting the cron service from the Windows services.msc. Nothing has worked for running an Excel program with my run.excel script.

I created a "null" .xls file that does nothing when run by Excel. I can run my script (run.excel c:/Shared/Bin/null.xls) from a bash prompt and it does nothing (as expected) and terminates but when I run this same script from a cron job Excel starts but never terminates. Running a ps command I see this:

$ ps
PID PPID PGID WINPID TTY UID STIME COMMAND
5188 1184 5188 4928 ? 1000 19:00:01 /usr/bin/sh
6040 5820 5188 4428 ? 1000 19:00:02 /cygdrive/c/Windows/System32/wscript <-- runs vb script that starts Excel
1808 4464 1808 5704 ? 1000 18:24:25 /usr/sbin/cron
5184 5540 5184 6048 pty1 1000 21:13:03 /usr/bin/bash
3368 5184 3368 5560 pty1 1000 19:00:25 /usr/bin/ps
5820 5188 5188 5820 ? 1000 19:00:02 /usr/bin/sh
4464 1 4464 4464 ? 1000 18:24:25 /usr/bin/cygrunsrv
1184 1808 1808 1184 ? 1000 19:00:01 /usr/sbin/cron
5540 1 5540 5540 ? 1000 21:13:03 /usr/bin/mintty
$

And I see the Excel.Exe *32 in the process list of Task Manager so I know Excel was started.

Note the above ps command shows the wscript command running which is the command that executes the vb script that runs Excel. Also note that all of these processes including the wscript command show the 1000 UID which is the Upar2 login UID in the /etc/passwd file.

I also look in the services.msc window and the cron service properties shows Login As .\Upar2. I see the same on the WinXP PC where I can run Excel successfully from a cron job.

Denis

--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Andrey Repin
2014-11-19 13:45:23 UTC
Permalink
Greetings, Kertz, Denis (D)** CTR **!
Post by Kertz, Denis (D)** CTR **
Post by Andrey Repin
Post by Andrey Repin
Try starting cron in terminal session and see if anything comes up.
Stop (don't kill! Everyone, who use -KILL, must be -KILL'ed) the cron service,
then start cron in terminal, using `runas /user:... ...'. So it would run
under proper user, and see if anything come up, when it execute your excel
job.
I was unable to find how to use runas from a terminal.
runas supply a plentiful help page when started without any parameters.
Your problem is probably that you assume the mintty to be the way to go, or
sort of a requirement, which it isn't.
runas is a windows tool to start applications under different credentials. And
as any native tool, it has no concept of pty's, and unlikely to output
anything to the mintty.
You can overcome this with redirection to an extent, i.e.
runas | iconv -f <OEM_encoding>
Post by Kertz, Denis (D)** CTR **
I can simply type runas and it does nothing and I can't find --help or
/help. I did find a suggestion to use cygstart
cygstart is a cygwin analogue for START command. Not the tool for the job.


--
WBR,
Andrey Repin (***@yandex.ru) 19.11.2014, <16:19>

Sorry for my terrible english...


--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Keith Christian
2014-11-12 20:31:39 UTC
Permalink
Denis,

If Excel is starting a macro in the worksheet, it might be worth
adding some logging to the visual basic code. Perhaps try this in
your Excel macro code if that is where the processing is taking place:



'--- Set up variables near the top of your macro.
'--- (Check whether you want the macro to set the current directory
(ChDir strPath) to that of the workbook.)
strPath = ThisWorkbook.Path
ChDir strPath
strLogFilename = strPath & "\" & "loggingfile.txt"


'--- Insert this block at various areas in the macro code
'--- Helps ensure logfile isn't discarded during a hang by
'--- using "Append" mode and flushing/closing immediately after
messages is written.
Open strLogFilename For Append As #2
strLogMessage = Now & " ---- " & "Current directory is " & strPath
Print #2, strLogMessage
Close #2



Keith


On Wed, Nov 12, 2014 at 9:20 AM, Kertz, Denis (D)** CTR **
Post by Kertz, Denis (D)** CTR **
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
run.excel 'c:\Shared\Bin\Create_Daily_Scorecard.xls'
When I run an Excel program interactively with this run.excel script it
runs just fine but when I run it via a cron job Excel just hangs.
Define "runs fine" please?
What exactly that excel script is doing?
This run.excel script simply starts up Excel with the .xls file it is given. In this example Excel opens c:\Shared\Bin\Create_Daily_Scorecard.xls. This .xls has a Workbook_Open macro, which is automatically run whenever this .xls is opened, that reads some data files and creates another .xls as its output.
run.excel 'c:\Shared\Bin\Create_Daily_Scorecard.xls'
it runs to completion and creates a new .xls as its output. When I run this run.excel script from a cron job it hangs.
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
When Excel hangs I can look at the processes running on the PC using the
Windows Task Manager and I don't see the EXCEL.EXE process. But when I
check the option to show processes from all users I see the hung EXCEL.EXE
process, AND the user name displayed is my login. So I am running this under the
Upar2 login and Task Manager doesn't display EXCEL.EXE as a Upar2 process
but when I check 'Show processes from all users' it shows EXCEL.EXE running
under user name Upar2 - a contradiction.
Task manager display processes started in your current session.
Not processes started under your credentials. That's an important difference.
Then this is just a difference between WinXP and Win7? Under WinXP it shows EXCEL.EXE in my process list even when the "Show processes from all users" isn't checked.
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
What I suspect is happening is Excel is attempting to do something that
requires Upar2 permission but it isn't really running as Upar2 so Excel
displays some error message and is waiting for the user to respond. But
Excel is running invisibly so this can't be seen.
More like you expect to run Excel interactively from service.
Not possible. Period.
I'm not trying to run Excel interactively from a cron job. One of the limitations with using Excel from a cron job is Excel has to run error free. If Excel does run into some error it will typically generate an error message and wait for a user response. Since Excel is running invisibly from a cron job, there is no user to give a response and Excel just sits there waiting for a response that will never come.
Post by Andrey Repin
Post by Kertz, Denis (D)** CTR **
I also suspect this Upar2 "confusion" isn't limited to running an Excel
program. I can run a cron job with regular UNIX commands (cut, sort, etc)
and see they are running with the ps command. But when I try to kill them
(kill -9) I get permission denied. If I want to kill a process running via
the cron I have to start cygwin with 'Run as administrator' and then I can
kill processes running under the cron.
Of course.
Why "of course"? Shouldn't I be able to kill my own processes? I can certainly do that under WinXP. But this isn't a major issue for me. I only pointed it out in case it was related to the issue why my Excel cron jobs hang.
--
Post by Andrey Repin
WBR,
Sorry for my terrible english...
Nothing wrong with your English...
Denis
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Warren Young
2014-11-18 22:50:19 UTC
Permalink
Post by Kertz, Denis (D)** CTR **
Post by Andrey Repin
More like you expect to run Excel interactively from service.
Not possible. Period.
I'm not trying to run Excel interactively from a cron job. One of the limitations with using Excel from a cron job is Excel has to run error free.
That’s not the key issue here.

Windows does not allow a service to have a GUI, at all.[1] Unless Excel is smart enough to not even start its GUI loop when it sees that it is running as a service — as it will be when running under “cron as service” — it will fail.

You were offered a choice when running cron-config: to run as a service or not. If you installed it as a service, try removing the Cygwin cron service[2] and reinstalling it to run under your user account. I tested it here, and a Bash script was able to launch notepad.exe via cron when run this way.

(I did not test the run-as-service case since I haven’t changed my user permissions per[3] on my test VM, and I don’t want to. And per above, I do not think it would succeed anyway.)

This means you will have to leave that computer logged in all the time. You also need to ensure that /usr/sbin/cron.exe starts on each login. As soon as you log out — and possibly if the desktop gets locked — cron will go back to failing to run GUI programs.

If this also fails, try using the Windows Task Scheduler instead. It’s more suited to this sort of task.

For that matter, why bring Cygwin into this at all? You’re clearly already familiar with VBScript, so why not create a VB app to do all the CreateObject() stuff?

If your excuse is that you don’t have Visual Studio, then you have no excuse, since there is a free version that will suffice for such a simple task.[4][5]


[1] http://stackoverflow.com/questions/53232/
[2] cygrunsrv -R cron
[3] http://cygwin.com/cygwin-ug-net/ntsec.html#ntsec-nopasswd1
[4] http://www.visualstudio.com/products/visual-studio-express-vs
[5] Beware, VSE will go away eventually: http://goo.gl/Cjmq2q
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Andrey Repin
2014-12-22 00:03:02 UTC
Permalink
Greetings, Kertz, Denis (D)** CTR **!
Post by Kertz, Denis (D)** CTR **
I am trying to port a cygwin application that uses cron from a WinXP PC to
a Win7 Pro PC and I find some cron jobs won't run. Specifically, I need to
run an Excel program from a cron job and this doesn't work on my Win7 PC.
For posterity:
Turned out, this has nothing to do with cygwin (predictable), and actually has
to do with how Windows (Vista+) manage services (namely: lack of access to any
GUI, unless you create one for yourself).

The issue has been discussed, for example, at serverfault.com[1] and relevant
MSDN article is [2].
The solution could be to create a stub application, which will make all
necessary calls and then launch your GUI application in prepared environment.

[1] http://serverfault.com/questions/101671/scheduled-tasks-w-gui-issue
[2] http://msdn.microsoft.com/en-us/library/ms687105(VS.85).aspx
Post by Kertz, Denis (D)** CTR **
In order to run an Excel program from cygwin I have this run.excel bash
excel=$1
vbscript=/usr/tmp/$$.vbs
cat <<-! >$vbscript
Dim xlApp
Set xlApp = CreateObject("Excel.application")
Set xlWb = xlApp.workbooks.Open("$excel")
xlApp.Quit
Set xlWb = Nothing
Set xlApp = Nothing
!
chmod 777 $vbscript
c:/Windows/System32/wscript.exe 'c:\cygwin64\usr\tmp\$$.vbs'
run.excel 'c:\Shared\Bin\Create_Daily_Scorecard.xls'
When I run an Excel program interactively with this run.excel script it
runs just fine but when I run it via a cron job Excel just hangs. When
Excel hangs I can look at the processes running on the PC using the Windows
Task Manager and I don't see the EXCEL.EXE process. But when I check the
option to show processes from all users I see the hung EXCEL.EXE process,
AND the user name displayed is my login. So I am running this under the
Upar2 login and Task Manager doesn't display EXCEL.EXE as a Upar2 process
but when I check 'Show processes from all users' it shows EXCEL.EXE running
under user name Upar2 - a contradiction.
What I suspect is happening is Excel is attempting to do something that
requires Upar2 permission but it isn't really running as Upar2 so Excel
displays some error message and is waiting for the user to respond. But
Excel is running invisibly so this can't be seen.
I also suspect this Upar2 "confusion" isn't limited to running an Excel
program. I can run a cron job with regular UNIX commands (cut, sort, etc)
and see they are running with the ps command. But when I try to kill them
(kill -9) I get permission denied. If I want to kill a process running via
the cron I have to start cygwin with 'Run as administrator' and then I can
kill processes running under the cron.
So, does anyone know what's going on here and what I need to do get these
cron jobs running. As I noted at the beginning this is being ported from
WinXP, where all this works fine, to Win7.
$ cron-config
Do you want to install the cron daemon as a service? (yes/no) yes
Enter the value of CYGWIN for the daemon: [ ]
Do you want the cron daemon to run as yourself? (yes/no) yes
Running cron_diagnose ...
... no problem found.
Do you want to start the cron daemon as a service now? (yes/no) yes
OK. The cron daemon is now running.
Denis
--
WBR,
Andrey Repin (***@yandex.ru) 22.12.2014, <02:37>

Sorry for my terrible english...


--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Kertz, Denis (D)** CTR **
2015-01-12 16:39:08 UTC
Permalink
After more investigation, I agree that this isn't a cywin problem but this isn't a GUI issue either. Something very strange is going on.

Here is a test vb script to control Excel using the wscript engine (c:/Windows/System32/wscript.exe). This vb script simply starts Excel, opens a .csv file (c:\Shared\Prospect\Bin\test.csv), and terminates:

Dim xlApp
Dim xlWb

Set xlApp = CreateObject("Excel.application")
xlApp.Visible = True
Set xlWb = xlApp.workbooks.Open("c:\Shared\Prospect\Bin\test.csv")
xlApp.Quit
Set xlWb = Nothing
Set xlApp = Nothing

Here is the cron job to run this vb script:

c:/Windows/System32/wscript.exe "c:\cygwin64\home\Upar2\bin\testExcel.vbs"

When this cron job is run, it hangs with Excel running (and doing nothing).

However, if the line that opens the .csv file is removed from this script:
Set xlWb = xlApp.workbooks.Open("c:\Shared\Prospect\Bin\test.csv")
Then the script runs successfully. That shows the cron job is running successfully for this trivial Excel program that simply starts Excel and terminates Excel.

This suggests there is a permission issue with opening the test.csv file but that isn't the case. A cron job was run to simply cat the test.csv file and this works:

cat c:/Shared/Prospect/Bin/test.csv >$HOME/cat.out

Finally, as was previously suggested, this script was executed using the runas command and that works successfully:

runas /user:<PC name>\Upar2 "c:\Windows\System32\wscript.exe c:\cygwin64\home\Upar2\bin\testExcel.vbs"

A variation of this Excel script was created to create a new workbook (xlApp.Workbooks.Add) and save the workbook as a .xls file. This also results in Excel hanging when run as a cron job.

So it appears the Excel script runs successfully as a cron job as long as no file operation (read or write) is performed which, of course, means no useful Excel script can be run.

Any ideas?

Denis

-----Original Message-----
From: Andrey Repin [mailto:***@yandex.ru]
Sent: Sunday, December 21, 2014 6:03 PM
To: Kertz, Denis (D)** CTR **; ***@cygwin.com
Subject: [SPAM?] Re: Can't Run Excel From A Cron Job Under Windows 7

Greetings, Kertz, Denis (D)** CTR **!
Post by Kertz, Denis (D)** CTR **
I am trying to port a cygwin application that uses cron from a WinXP PC to
a Win7 Pro PC and I find some cron jobs won't run. Specifically, I need to
run an Excel program from a cron job and this doesn't work on my Win7 PC.
For posterity:
Turned out, this has nothing to do with cygwin (predictable), and actually has
to do with how Windows (Vista+) manage services (namely: lack of access to any
GUI, unless you create one for yourself).

The issue has been discussed, for example, at serverfault.com[1] and relevant
MSDN article is [2].
The solution could be to create a stub application, which will make all
necessary calls and then launch your GUI application in prepared environment.

[1] http://serverfault.com/questions/101671/scheduled-tasks-w-gui-issue
[2] http://msdn.microsoft.com/en-us/library/ms687105(VS.85).aspx
Post by Kertz, Denis (D)** CTR **
In order to run an Excel program from cygwin I have this run.excel bash
excel=$1
vbscript=/usr/tmp/$$.vbs
cat <<-! >$vbscript
Dim xlApp
Set xlApp = CreateObject("Excel.application")
Set xlWb = xlApp.workbooks.Open("$excel")
xlApp.Quit
Set xlWb = Nothing
Set xlApp = Nothing
!
chmod 777 $vbscript
c:/Windows/System32/wscript.exe 'c:\cygwin64\usr\tmp\$$.vbs'
run.excel 'c:\Shared\Bin\Create_Daily_Scorecard.xls'
When I run an Excel program interactively with this run.excel script it
runs just fine but when I run it via a cron job Excel just hangs. When
Excel hangs I can look at the processes running on the PC using the Windows
Task Manager and I don't see the EXCEL.EXE process. But when I check the
option to show processes from all users I see the hung EXCEL.EXE process,
AND the user name displayed is my login. So I am running this under the
Upar2 login and Task Manager doesn't display EXCEL.EXE as a Upar2 process
but when I check 'Show processes from all users' it shows EXCEL.EXE running
under user name Upar2 - a contradiction.
What I suspect is happening is Excel is attempting to do something that
requires Upar2 permission but it isn't really running as Upar2 so Excel
displays some error message and is waiting for the user to respond. But
Excel is running invisibly so this can't be seen.
I also suspect this Upar2 "confusion" isn't limited to running an Excel
program. I can run a cron job with regular UNIX commands (cut, sort, etc)
and see they are running with the ps command. But when I try to kill them
(kill -9) I get permission denied. If I want to kill a process running via
the cron I have to start cygwin with 'Run as administrator' and then I can
kill processes running under the cron.
So, does anyone know what's going on here and what I need to do get these
cron jobs running. As I noted at the beginning this is being ported from
WinXP, where all this works fine, to Win7.
$ cron-config
Do you want to install the cron daemon as a service? (yes/no) yes
Enter the value of CYGWIN for the daemon: [ ]
Do you want the cron daemon to run as yourself? (yes/no) yes
Running cron_diagnose ...
... no problem found.
Do you want to start the cron daemon as a service now? (yes/no) yes
OK. The cron daemon is now running.
Denis
--
WBR,
Andrey Repin (***@yandex.ru) 22.12.2014, <02:37>

Sorry for my terrible english...


--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple

Continue reading on narkive:
Loading...