VFP9 wscript.shell .run won't work with task scheduler

I have written the following code in vfp9.  The code is supposed to run the Google Account Manager (gam) to create a file of current gmail accounts.  This works fine when run from the desktop but, It won't work when using the task scheduler.  It never executes the .run instruction (according to the task manager).  Any help would be appreciated.
lcCmd = Getenv("ComSpec") + [ /C ] && There is a space before and after the ‘/C’
lcCmd=lcCmd+[c:\gam\gam.exe print users allfields > C:\gam\GamData\allusers.csv] 

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Olaf DoschkeSoftware DeveloperCommented:
%Comspec% is the environment variable specifying what is executed, if you use the VFP RUN or ! command.
You're overcomplicating things.

If you want to call c:\gam\gam.exe why don't you do so?

RUN c:\gam\gam.exe print users allfields > C:\gam\GamData\allusers.csv

Open in new window

As far as I read documentation about the gam.exe it requires an initialisation where you have to log in to an administrative google apps account and grant access to give the EXE authentication for any further functionality, that may be your problem.

Bye, Olaf.
zanthrasAuthor Commented:
As I said in my question, This code runs just fine, including GAM when run from the desktop.  Gam functions flawlessly.  I am trying to suppress any output to the screen.  The IWindowstyle  (loShell.Run(lcCmd,IwindowStyle,bWaitOnReturn) variable is set to zero.  That hides any window that  the shell.run might open.  That can't be done using the 'RUN' command.
Processes in the Task Scheduler are different from ones executed in interactive Desktop session and some commands do not work as expected.

OK, why do you need FoxPro to run the batch? You may simply execute some .BAT file in the Task Scheduler:
rem ... List all Gmail accounts
c:\gam\gam.exe print users allfields > C:\gam\GamData\allusers.csv
rem ... and now execute VFP to do the rest of work (if necessary):
VFP9.EXE <YourVFPCodeFileName> 

Open in new window

You may also use PowerShell.

If your code "never executes the .run instruction " what it does? Does it hang? Does it exit? Does it even start? Did you ensure the CREATEOBJECT() was successful?
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

Olaf DoschkeSoftware DeveloperCommented:
You have scheduled what? This code compiled as EXE? or this code in a PRG? Pavel suggests running a bat file with your command and I would second that, you don't need VFP at all, only if you do further things in VFP with the CSV output.

Also: If task scheduler is involved, how much does it matter if a window displays. You typically do such things at a server not being used by a user at the same time anyway.

Bye, Olaf.
Also the VFP RUN command supports parameter /N2 or /N7 which allows to run the application minimized which is acceptable even when the user is logged in the interactive session.
zanthrasAuthor Commented:
There are problems using the 'RUN'.  For one thing, VFP runs the batch and keeps on proccessing.  I need the output of the first GAM command to do what I need to do in the rest of the program.

Anyway, it turns out thatthe windows task scheduler just can't do what i want so, I bought a third party scheduler (system scheduler from Splinterware http://www.splinterware.com).  It works just fine now.

Thanks for your help

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Olaf DoschkeSoftware DeveloperCommented:
No objection, but the MS task scheduler is ok, you may have needed to configure some options correctly, eg running with a certain windows account.

Just your sentiment about the scheduler is wrong. I do run several tasks running VFP EXEs. Also waiting for external processes in VFP is possible. In case you RUN /N you don't wait, in case of RUN you do wait, also you may wait for the CSV file and in a loop try to get exclusive access, so you see gam.exe is finished with it. You can also use CreateProcess instead and WaitForSingleObject.

Anyway, it's fine you can solve your problem with a third party scheduler. You could respect the time we invested, but again I won't object.

Bye, Olaf.
zanthrasAuthor Commented:
My solution didn't require a VFP 'work-a-round' .  The program itself is okay but Microsofts' scheduler was lacking.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.