Solved

aprinters() not working in EXE

Posted on 2014-01-09
8
652 Views
Last Modified: 2014-02-07
Function aPrinters() is working when under application.  Failled when ran from EXE on some PC and works well on others.  

=APRINTERS(xPrinterList,0)
IF ASCAN(xPrinterList,"pdf995",1,0,1,1) = 0
      mbkGestionSorties = .f.
      bPDF995Present = .f.
ENDIF       

On some PC system is crashing stating that xPrinterList does not exist.  If I run into APP mode onto same PC, no problems.  If I run EXE on another PC, it run fine.  

Thanks
0
Comment
Question by:meep_meep
  • 4
  • 3
8 Comments
 
LVL 41

Expert Comment

by:pcelba
Comment Utility
The PC system is not crashing your program just does not properly handle the APRINTERS() result... You have to test the result returned by the APRINTERS() function to avoid this "crash".

But it does not mean the APRINTERS() function works well when the array is not created but printers exist.

Unfortunately you have not so many options to fix this behavior.

1) Check the version of your run-time libraries used for EXE run on all PCs ( VERSION(4) function should return 09.00.0000.7423)
2) If the APRINTERS() returns 0 then you may attempt to issue GETPRINTER() to allow users to select printer from available printers.
3) If the GETPRINTER() does display empty printers list then you may try to obtain the list of printers by Win32 API call. See EnumPrinters API call here: http://www.news2news.com/vfp/?group=57&function=215
4) You may also check other printer related functions from the same resource (EnumPrinterDriver API call is available as the source for a free)

Another useful piece of code is e.g. here: http://www.berezniker.com/content/pages/visual-foxpro/enumerating-printer-forms

You may also obtain the list of printers by WMI:
oWMI = GetObject("winmgmts:\\.\root\cimv2")
oPlist = oWMI.ExecQuery("Select * From Win32_Printer")
FOR EACH oPrinter IN oPlist
  ? oPrinter.Name
NEXT

More info: http://blogs.technet.com/b/heyscriptingguy/archive/2006/08/14/how-can-i-list-all-the-printers-on-a-remote-computer.aspx

The only thing we are sure about is no VFP update from Microsoft...
0
 

Author Comment

by:meep_meep
Comment Utility
Agree with you about "crashing".  I was referring to code crashing since aPrinters() did not fill up the array.  One point is bugging me: my program is working when ran from APP but fail when from EXE on same PC, even when EXE is built on that PC.  Same program is well working on other PC.  I compared files from those two and they are the same.  Do you know if there are some dll I should check version or availability on the faulty machine to make aPrinters() working ?  Reason why I need to fix that function on that machine is that FoxyPreviewer have some fatal issues when asked.  Again, on another machine, all that is working :S
0
 
LVL 41

Expert Comment

by:pcelba
Comment Utility
How do you execute the APP? From VFP IDE by DO command?  VFP IDE uses different environment than running EXE.  Did you try to execute EXE by DO command from VFP IDE?

Did you check the VERSION(4) when the EXE/APP is running?

Printers enumeration calls functions from  WINSPOOL.DRV  so you may check this file version (in Windows\SYSTEM32 on 32 bit systems,  in Windows\SYSWoW64  on  64 bit systems).
0
 

Author Comment

by:meep_meep
Comment Utility
Not sure what happened.  The user was using Comodo anti-virus.  We disabled it for an hour, ran the EXE without any problems.  We then re-enabled anti-virus and EXE still ran without any problems.  100% confused now.  A test we missed to do is to make sure EXE was still failling before disabling anti-virus.  However, yesterday we did reboot PC and EXE was still not working.  Since I'm 100% confused, it might be possible that EXE was working before anti-virus turned off.  Does this make any sense to you ?!?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 41

Accepted Solution

by:
pcelba earned 500 total points
Comment Utility
LOL,  Comodo's AI is reading this forum maybe...

I don't know Comodo antivirus software just some Comodo security certificates. And this antivirus behavior really does not make sense... except for some "printing viruses" attack blocking where this behavior could be possible... The behavior change could happen after some Comodo automatic update but it has to be confirmed by Comodo.

Antivirus compatibility is becoming a nightmare under certain circumstances... File access denied, File does not exist, applications (very) slow start, FPT file is missing or invalid, ... Missing printers are new item on this list... I am using Avast and AVG without this side effect but it can appear tomorrow...

The good point it is working now!
0
 

Author Closing Comment

by:meep_meep
Comment Utility
Very efficient, thanks a lot for your precious collaboration
0
 
LVL 29

Expert Comment

by:Olaf Doschke
Comment Utility
Just a question: How many printes are installed, and are they available for the current user, when running the EXE?

Just check if APRINTERS() returns 0, then there s no printer for that user.

Unusual, but what else should be a problem? Too many printers perhaps, specifically network printers.

Also see the note of the help topic: The behavior of this function is OS (operating system) - specific. Visual FoxPro may or may not check to see if the printers are actually connected to your computer when it prepares this list, and the list may include all printers installed as printer setups, or only those available on the current network.

So reasons for the function no working are also possible in OS configuration or behaviour.

Bye, Olaf.
0
 

Author Comment

by:meep_meep
Comment Utility
Thanks Olaf.  The involved user is now running my exe in sandbox.  Since that time he did not face that error.  My understanding is that anti-virus was blocking aPrinters().
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Veeam Backup & Replication has added a new integration – Veeam Backup for Microsoft Office 365.  In this blog, we will discuss how you can benefit from Office 365 email backup with the Veeam’s new product and try to shed some light on the needs and …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 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

12 Experts available now in Live!

Get 1:1 Help Now