Solved

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

Posted on 2014-10-10
9
554 Views
Last Modified: 2014-10-16
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.
loShell=Createobject('Wscript.shell')
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] 
loShell.Run(lcCmd,IwindowStyle,bWaitOnReturn)

Open in new window

0
Comment
Question by:zanthras
  • 3
  • 3
  • 2
9 Comments
 
LVL 29

Expert Comment

by:Olaf Doschke
Comment Utility
%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.
0
 

Author Comment

by:zanthras
Comment Utility
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.
0
 
LVL 41

Expert Comment

by:pcelba
Comment Utility
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?
0
 
LVL 29

Expert Comment

by:Olaf Doschke
Comment Utility
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.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 41

Expert Comment

by:pcelba
Comment Utility
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.
0
 

Accepted Solution

by:
zanthras earned 0 total points
Comment Utility
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
0
 
LVL 29

Expert Comment

by:Olaf Doschke
Comment Utility
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.
0
 

Author Closing Comment

by:zanthras
Comment Utility
My solution didn't require a VFP 'work-a-round' .  The program itself is okay but Microsofts' scheduler was lacking.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now