Link to home
Start Free TrialLog in
Avatar of zanthras
zanthrasFlag for United States of America

asked on

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.
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

Avatar of Olaf Doschke
Olaf Doschke
Flag of Germany image

%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.
Avatar of zanthras

ASKER

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?
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.
ASKER CERTIFIED SOLUTION
Avatar of zanthras
zanthras
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
My solution didn't require a VFP 'work-a-round' .  The program itself is okay but Microsofts' scheduler was lacking.